-
Notifications
You must be signed in to change notification settings - Fork 27
Add text-to-speech feature #63
base: master
Are you sure you want to change the base?
Conversation
Add a menuitem to the popup to speak out the selection. Press the 'Listen' to play the speech. If the from language is set to auto, translate() sets a variable to the detected language. TODO - Can play speeches on top of each other, allow only one instance to play at once. - Leaks memory probably now. Every time a speech is played, a new background Page is created and it's never destroyed. Create only one global page at the beginning and send messages to play?
I fixed the problem described in a previous commit about creating page-worker.Page objects every time user played the audio. Now Firefox throws unsafe CPOW usage errors, the audio plays but this can't be good. TODO - Use Web Audio API, just steal someone else's work.
Use Web Audio API instead of contentscript, which I tried previously, to play the speech. TODO - Volume - Speech speed - Both above need settings
Thanks for your contribution! |
I was able to install it to the normal version of Firefox now. The first time you listen the speech it works, but after that it doesn't. Strange that in the developer version I didn't notice this behavior. It looks like a new AudioContext must be created every time playing the speech. I wonder if the audio thing might leak resources if you don't clean up after it every time. Is there any good way to test for memory leaks in FF? |
Create a new AudioContext in the click handler every time the speech is played and free resources after the playing has ended. Is it necessary to free resources at all? If so, can you do it in the AudioBufferSourceNode.ended callback?
Now, a new AudioContext is created every time when you want to listen to the speech. I'll try to research about freeing up resources afterwards, is it needed at all. And about the Web Audio API in general. I have been running this code all day on my browser and it seems to work fine, but I'd like to know for sure it's correct. |
Sad to see AudioContext behavior is not the same accros the Firefox versions.. |
Thanks @fluks, looks great! The AudioContext should be freed automatically by the garbage collector if there is no references to it? You can use this tool to debug memory in Firefox: https://developer.mozilla.org/en-US/docs/Tools/Memory |
It should work now on the current version of Firefox and on the developer version also. You can test the feature by just pulling my branch? I haven't signed anything yet, do I really need to? I was able to install an unsigned extension by:
Installing an unsigned extension via url bar by pointing it to the location of the extension on the file system failed.
I'll remove the |
Here's a signed xpi for you to test, @PerfectSlayer, if you still need it. https://github.com/fluks/gtranslate/raw/xpi/gtranslate-0.13.0-fx%2Ban.xpi |
Thanks. I thought they already remove the By the way, it seems to work fine! 👏 |
So, is-it stable enough? Does anyone test-it? |
I haven’t tested it yet, but I definitely consider to approve it. Some things I see:
|
It has been in my tests. I have been using a version with a feature you suggested, such that the voices won't overlap. I haven't committed this version. |
The translator page can speak and the official API also has this feature.
Makes sense, I'll do that. I don't know is this feature wanted by many users, but the change in the ui is quite minor currently. Here's a pic. |
This code doesn't address the overlapping problem. To stop the audio being played, you need to call I also removed some unnecessary code. |
Hi, I added an option to listen to Google Translate's TTS voice. Works on the Firefox developer edition(46.0a2), I can't test it on the main release because of the extension signature enforcement, even I have 'xpinstall.signatures.required' in about:config, still won't install if I toggle it to false.
To listen to the voice you need to press the Listen label.