#!/bin/bash

voice=1
#pl_jacek = 1
#pl_ewa = 2
#pl_jan = 6
#pl_maja = 7


echo "Mowe wygenerowal syntezator mowy IVONA: http://www.ivona.com/"
ifona_info()
{
    echo ""
    echo  "podaj tekst jako jeden parametr ale w cudzyslowiu:"
    echo "./ifona.sh \"jakis tekst\""
    echo "lub jesli chcesz sam link do sciagniecia:"
    echo "./ifona.sh -l \"jakis tekst\""
    echo "odczytanie pliku:"
    echo "./ifona.sh -f nazwa_pliku"
    echo "wyswietlenie linku dla tekstu z pliku:"
    echo "./ifona -f -l nazwa_pliku"
    echo ""
}


if [ "$1" != ''  ] ; then 
    if [ "$1" == '-l' ] && [ "$2" != '' ] && [ "$2" != '-f' ] ; then
	tres=`echo $2 |tr ' ' '+'`
	link="`curl -s -d "lang=pl&synth=1&tokenUrl=http://www.ivona.com/?tk=&tresc=$tres&voice=$voice" http://www.ivona.com/index.php |grep "fileTest.php" | cut -d "'" -f6`"
	echo $link
	exit
    fi
    if [ "$1" == '-f' ] && [ "$2" != '' ] && [ "$2" != '-l' ] ; then
	tres=`cat $2 |tr ' ' '+'`
	link="`curl -s -d "lang=pl&synth=1&tokenUrl=http://www.ivona.com/?tk=&tresc=$tres&voice=$voice" http://www.ivona.com/index.php |grep "fileTest.php" | cut -d "'" -f6`"
	mplayer  "$link" > /dev/null 2> /dev/null
    fi
    if [ "$2" == '' ] && ([ "$1" != '-l' ] || [ "$1" != '-f' ]) ; then

	tres=`echo $1 |tr ' ' '+'`
	link="`curl -s -d "lang=pl&synth=1&tokenUrl=http://www.ivona.com/?tk=&tresc=$tres&voice=$voice" http://www.ivona.com/index.php |grep "fileTest.php" | cut -d "'" -f6`"
	mplayer  "$link" > /dev/null 2> /dev/null

    fi
    if ([ "$1" == '-f' ] && [ "$2" == '-l' ]) || ([ "$1" == '-l' ] && [ "$2" == '-f' ]) && [ "$3" != '' ] ; then
        tres=`cat $3 |tr ' ' '+'`
	link="`curl -s -d "lang=pl&synth=1&tokenUrl=http://www.ivona.com/?tk=&tresc=$tres&voice=$voice" http://www.ivona.com/index.php |grep "fileTest.php" | cut -d "'" -f6`"
	echo $link



   fi
else
    ifona_info
    
fi


