Git Product home page Git Product logo

google-tts's Introduction

Google TTS

Build Status

A Javascript API for the Google's text-to-Speech engine and is based on code at http://weston.ruter.net/projects/google-tts/.

NOTE: Playbackwill only work when running the script locally as Google's server only returns audio if you can prevent the browser from sending the Referrer HTTP Header to their server. So this library is at the moment only really good for use in browser plugins and Phonegap apps.

Features

  • Converts upto 42 languages
  • Supports playback through HTML5 Audio tag if available in browser.
  • Asynchronous playback API
  • Splits up large inputs (>100 chars) into multiple consecutive requests (just like Google Translates does).
  • Small and compact: ~1.5 KB minified and gzipped

Installation

Add the following inside your HTML <body> tag, near the bottom:

<script type="text/javascript" src="https://rawgithub.com/hiddentao/google-tts/master/google-tts.min.js"></script>

You can also install using bower:

$ bower install google-tts

API

new GoogleTTS(language)

Initialize a new instance of the library, e.g:

var tts = new GoogleTTS('zh-CN');

Params:

  • language - the default language to speak in when not otherwise specified. If omitted then English is assumed.

.languages()

Get the full list of supported languages.

Returns: An object such as:

{
    ...
    'en' : 'English',
    'zh-CN' : 'Mandarin (simplified)',
    ...
}

.url(text, language)

Construct the URL to fetch the speech audio for given text and language.

Params:

  • text - the text to convert to speech.
  • language - the language to speak it in. If omitted then the default language (see above) is assumed.

Returns: a URL to the audio file.

.play(text, language, cb)

Fetch and play the speech audio for given text and language, if possible (see top).

Params:

  • text - the text to convert to speech.
  • language - the language to speak it in. If omitted then the default language (see above) is assumed.
  • cb - Completion callback function with signature (err), where err holds information on any errors which may occur.

.getPlayer(cb)

Get the active playback mechanism (see below).

Params:

  • cb - Completion callback function with signature (err, player), where err holds information on any errors which may occur. player is an instance of GoogleTTS.Player.

.addPlayer(player)

Add a playback mechanism (see below).

Params:

  • player - An instance of GoogleTTS.Player.

Playback mechanisms

At the moment there are two supported playback mechanisms:

  • HTML5 audio tag
    • As of June 10th 2013 only Safari and Chrome support MP3 playback
  • SoundManager2
    • On Firefox we need this to do MP3 playback, using Flash.

When you first call play() the library calls getPlayer(), which then cycles through the available playback mechanisms until a supported one is found. If no playback mechanism is supported in the current browser then an error get thrown - No playback mechanism is available.

Each playback mechanism is implemented as a sub-class of GoogleTTS.Player. You can implement your own playback mechanism by extending this class and then adding an instance of your custom mechanism via addPlayer().

Demo

For browsers which support HTML5 Audio MP3 playback (e.g. Firefox) you can launch index.html directly in the browser.

For browsers which need to use the SoundManager2 Flash player (e.g. Chrome) there is at the moment no way of getting it work without running a local dev server which serves up the files. This is necessary so that the flash player works, yet it means that the request to Google's servers will be rejected because of the HTTP referrer header. If you would still like to try then run the following:

  1. Run grunt dev to start the simple HTTP server
  2. Open 127.0.0.1:8888 in your browser

Build and Test

If you make changes, before you raise a pull request build the project:

$ npm install
$ grunt

License

MIT - see LICENSE.md

google-tts's People

Contributors

atroche avatar hiddentao avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

google-tts's Issues

Can it support FireFox?

I have Download the firefox and use the firefox to open the example, but there is a popup window to say not supoort HTML5 MP3 AUDIO, But i can do it in chrome, what can i do if i want this can do in firefox?

Jquery file is playing multiple Text

when i am using it it is playing multiple text at a same time while clicking on play button and i am using it on div but it is not playing only one div text at a time.

multiple selector

hi i was wondering how i use multiple block of text, i wanted to add a classes to html content i.e a block of texts and i wanted the plugin to convert to audio

How can I use this with require.js ?

I've already figured out how to use it with require.js, but I get a 404 when trying to use.
Trying to do this in chrome. IE works ok, FF not so much

cannot open it on XAMPP server

I upload the sample website to apache but it cannot run it on the xampp apache
But i can run it on local by click the file in the file browser
what can i do if i want it run on apache?
(i find that the url of google translate also 404 if i run it on apache)

No response from tts.play()

Hi

I'm not getting any response from tts.play(). I passed it a callback function to see if there are any errors, but that function isn't getting called. Even the demo webpage[0] doesn't play anything, when I enter text and hit play. There are no errors when I go to my browser's console, and try the same thing. Here's my code:

var tts = new GoogleTTS("en");
tts.play("Hello world", "en", function(err) {
    alert(err); // no alerts pop up
}

I'm on trying this on Chrome 32, on OS X Mountain Lion.

[0] - http://hiddentao.github.io/google-tts/

Dips

Hi , I am running the code with my text "this is not acceptable. What is going on?" . Now it only speaks up to "this is not acceptable". It can not speak after the "?". What is the problem in that???
Similarly, If I write the text "I am very angry..... this is not acceptable" this is not correctly pronounce. How can I fix them??

Determine usefulness of this library

The main downside to this library is that it can't be used to add text-to-speech capability to any arbitrary site because Google's server checks the referrer header when requests are made and presumably only returns an audio file when requests are made from browsers visiting its own sites (e.g. translate.google.com).

This library is useful for browser extensions and possible Cordova/Phonegap projects but I'm not sure there's an elegant way get it working on a remotely-hosted site.

Perhaps this needs to be made clear in the documentation and the library need to be tested in the above mentioned scenarios to make sure that it actually does work there.

Long url lenght fails

Hello,

When a long text is sent, google seems to abort the connection.
It should be great to detect a long string, split it, send these to google and play mp3 returned one after one.
Will try to work on a patch but can't promise anything as JS isn't a well known language for me.

Example (in french, sorry, this is the tv grid of the day) :
Sur FRANCE 2 a 20 heure 45 il y a : Drôle de famille !. Sur FRANCE 3 a 20 heure 45 il y a : Des racines et des ailes. Sur M6 a 20 heure 50 il y a : Pékin express, le coffre maudit. Sur NRJ 12 a 20 heure 50 il y a : Les grandes histoires. Sur NT1 a 20 heure 45 il y a : Soeur Thérèse.com. Sur TF1 a 20 heure 50 il y a : Grey's Anatomy. Sur TF1 a 21 heure 35 il y a : Grey's Anatomy. Sur W9 a 20 heure 45 il y a : Météo. Sur W9 a 20 heure 50 il y a : Enquêtes criminelles : le magazine des faits divers.

Regards.

Error getting sound

I am trying to add text to speech to my website but keep getting this error

GET http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q=Ask%20Again&textlen=9&idx=0&total=1 404 (Not Found)

If it matters, I am using Ruby and Sinatra and this is the javascript code

<script type="text/javascript" src="https://rawgithub.com/hiddentao/google-tts/master/google-tts.min.js"></script>
<script>
var tts = new GoogleTTS();
tts.play("<%=@message%>", "en")
</script>

Why does it not work with anything but 'Hello World'?

I've just been wrestling with this for ages. And it would seem that it will only play the words 'hello' - lower case - and 'Hello World'. I can only assume this is for people building Hello World applications with the TTS service.

Is this expected?

I am getting this in Safari: "Failed to load resource"

I am using Safari 5.1.7 on Windows 8.1 and I am getting:
Failed to load resource: The requested URL was not found on this server. pointing to file:///soundmanager2_debug.swf

How do I resolve this?

EDIT: This error occurred while trying out the demo in this project's repo.

Not working

Hello,

As you provide demo with index.html is not working.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.