Free Accounts & Free Advice

Twilio Client Text to Speech

Twilio Client makes it easy to bring any TwiML functionality into the browser, including text to speech using the Say verb. Twilio Client can be used to offer a spoken version of your website content, rss feeds, read important updates, provide live commenting and more.

Usage

A user enters the text to be spoken into a text field and selects a male or female voice. The user clicks a button labelled 'Speak to Me', which will read the text out loud.

When the user clicks the 'Speak to me' button, the javascript speak function is invoked. This function disables the submit button and tells Twilio.Device to connect. The value of the form fields are passed as parameters. When the Twilio device disconnects the submit button is re-enabled.

Our TwiML performs text to speech using the <Say> verb, and includes a 'gender' attribute with the appropriate value that as specified in the form. For a complete overview of TwiML (Twilio's XML) see the TwiML documentation.

Twilio processes the TwiML that was returned and speaks the text through the browser, then disconnects the call. Twilio.Device.disconnect callback will be invoked at this time and the submit button is re-enabled.