#!/bin/bash
#clear
#------------------------------------#
#  Umwandeln von Text in Sprache     #
#------------------------------------#
#------------------------------------#
if [ -f "$1" ]
then
  TEXT="$( cat $* )"
else
  TEXT="$*"
fi
if [ "$( pidof espeak )" != "" ]
then
  echo "Zu viele Instanzen"
else
  ENTXT=$(echo "$TEXT" | grep -c " the ")
  DETXT=$(echo "$TEXT" | grep -c " der ")
  if [ $ENTXT -le $DETXT ]; then
    TEXT=$( echo $TEXT | sed 's/-/ minus /g'  | sed 's/\// släsch /g' | sed 's/:/ Doppelpunkt /g' | sed 's/[<>]/ /g' )
    espeak -p 38 -s 150 -v mb-de6 "$TEXT" 2> /dev/null
  else
    TEXT=$( echo $TEXT | sed 's/-/ minus /g' | sed 's/\// slash /g' | sed 's/:/ double dot /g' | sed 's/[<>]/ /g' )
    espeak -p 38 -s 130 -v mb-en1 "$TEXT" 2> /dev/null
  fi
fi
