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?
Here is the code snippet I found:
Another option now may be HTML5 text to speech, which is in Chrome 33+ and many others.
Here is a sample:
With this, perhaps you do not need to use a web service at all.
Very easy with responsive voice. Just include the js and voila!
You can use the
SpeechSynthesisUtterance
with a function like say:Then you only need to call
say(msg)
when using it.Update: Look at Google's Developer Blog that is about Voice Driven Web Apps Introduction to the Web Speech API.
run this code it will take input as audio(microphone) and convert into the text than audio play.