Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Google Text-To-Speech in Javascript

I need to play Google text-to-speech in JavaScript.
The idea is to use the web service:

http://translate.google.com/translate_tts?tl=en&q=This%20is%20just%20a%20test

And play it on a certian action, e.g. a button click.

But it seems that it is not like loading a normal wav/mp3 file:

<audio id="audiotag1" src="audio/example.wav" preload="auto"></audio>  <script type="text/javascript">     function play() {         document.getElementById('audiotag1').play();     } </script> 

How can I do this?

like image 416
Betamoo Avatar asked Mar 27 '13 06:03

Betamoo


People also ask

Is Google Text to Speech API free?

Text-to-Speech is priced based on the number of characters sent to the service to be synthesized into audio each month. You must enable billing to use Text-to-Speech, and will be automatically charged if your usage exceeds the number of free characters allowed per month.


1 Answers

Another option now may be HTML5 text to speech, which is in Chrome 33+ and many others.

Here is a sample:

var msg = new SpeechSynthesisUtterance('Hello World'); window.speechSynthesis.speak(msg); 

With this, perhaps you do not need to use a web service at all.

like image 130
Brian M. Hunt Avatar answered Sep 22 '22 15:09

Brian M. Hunt