Home > Uncategorized > Text to Speech in Javascript

Text to Speech in Javascript

Just a short post about an undocumented Google API, Text-To-Speech.

function sayWord(word,lang)
var url = “http://translate.google.com/translate_tts?ie=UTF-8&q=” + word.toLowerCase() + “&tl=” + lang;
var snd = new Audio(url);

Where “Word” is the phrase to say, and lang is the accent of the speaker. For example “Chat” in french is pronounced “Shaa’.

An important “Gotya” is that in iOS, this function must only be called in response to a click event. You cannot autoplay audio.

Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: