cbrews / libTTS

A portable and simple text-to-speech library powered by Google Translate's Text-To-Speech service.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

libTTS

WARNING: This library is old and probably doesn't work anymore. It was created for fun.

libTTS is portable and simple text-to-speech library powered by Google Translate's Text-To-Speech service.

Google Translate already provides a full-fledged text-to-speech service for dynamically creating short text-to-speech files. However, due to restrictions of the service, it is not possible to play these files on external websites; a request to the text-to-speech API will give you a 404. More information on these restrictions can be found here.

This library encapsulates an <iframe> that loads the Google Translate Text-To-Speech url directly.

It looks like there are definitely some bugs with this (due to the way referers work) but it does appear to work on Chrome. In case you weren't aware, this project is a hack around Google's referer exclusion.

Examples

Check out http://christhebrews.github.io/libTTS/ for use!

Docs

libTTS creates a global variable TTS. Please check you namespaces!

TTS.say()

TTS.say(text) - pass a string to the text-to-speech engine.

TTS.say("Hello, World!");
// [TTS] Said: "Hello, World!"

Successfully spoken phrases will be printed to the console. Calling TTS.say() while another phrase is being spoken will abort the previous audio playback. There is a currently a 100-character limit on the text string (imposed by Google). Text strings that exceed this limit will print a warning in the console.

TTS.maxLength

integer - the allowed max length of a string passed to TTS.say()

TTS.maxLength;
// 100

Please use TTS.maxLength for validation checks against string lengths before passing them to TTS.say()

TTS.el

jQuery element - the iframe element that plays the audio.

TTS.el;
// jQuery <iframe> element

Dependencies

libTTS currently requires jQuery.

About

A portable and simple text-to-speech library powered by Google Translate's Text-To-Speech service.

License:MIT License


Languages

Language:HTML 52.9%Language:JavaScript 47.1%