zaf / asterisk-googletts

Asterisk AGI script that uses Google's translate text to speech service.
GNU General Public License v2.0
214 stars 125 forks source link

Add feature #32

Closed 3eBoP closed 6 years ago

3eBoP commented 7 years ago

Adding a parameter $status so you can chose to play the file generated, or save it in a var to use it later

zaf commented 7 years ago

Hello and thank you for the PR. There are a few issues here so I'm not merging it at the moment:

First it changes some some default settings like the debug flag and the cache dir. Also the new cache dir is not handled correctly, there is no check if the directory exists or an attempt to create it before trying to move the files there.

Most importantly it is not working for large input. There is the limit of 150 characters in the API, for that reason we split the input in lines no longer than 150 chars and we run in loop the code that fetches , saves and plays back the generated speech for each of them. That means there are cases where we have more than one sound files returned. With your changes in place only the first of these files is returned to the dialplan as the variable 'file_to_play'. You would probably have to first get all the files, merge them in one and return that in 'file_to_play', or return a list of files/variables but I'm afraid we are creating too much complexity for too little gain.

What is the use case that made you add this feature? How you wanted to play the generated speech sound that it wasn't covered by the existing functionality of the tts script?

3eBoP commented 7 years ago

Thanks for your answer.

I don't understand when you say "Also the new cache dir is not handled correctly, there is no check if the directory exists or an attempt to create it before trying to move the files there.". Isn't it made line 143 with : mkpath("$cachedir") unless (-d "$cachedir");

I didn't see that there was a limit of 150 characters, surely because I use the script only with small texts. I think I could just do something like that : $count_texts = 0 ... print "SET VARIABLE file_to_play_$i $cachedir/$filename\n"; $count_texts++; ... print "SET VARIABLE count_texts $count_texts\n";

And then back in my dialplan I could make a loop to read all my file_to_play_x vars.

What do you think ?

My use case for adding this feature was I needed to TTS a text not for playing to the user which is in my Dialplan, but for another person which is dialed : exten => s,1,agi(googletts.agi,"My text",fr,,,"returning") exten => s,2,Dial(SIP,,rA(${file_to_play}))

For my use, my modification of code will not help ...

3eBoP commented 7 years ago

Hi,

What do you think about my previous post ?

Do you have an idea on how to merge files generated by googletts ?

Thanks.

zaf commented 7 years ago

If you see the cli scripts they already merge the sound files to one. This is fine for a cli app, but maybe not practical for the AGI script when you want to have some sound playing back as soon as possible. Maybe you can integrate the cli scripts somehow in your diaplan logic.

3eBoP commented 7 years ago

What are these cli scripts you talk about ?

zaf commented 7 years ago

The scripts under the cli folder. They are CLI utils to generate and save sound files using GoogleTTS