Google synthesis
Builds network request for Google Speech API V1 or Google's translation's speech synthesis API. Based of Zlargon's 'google-tts'.
Installation
npm install --save googlesynthesis
Usage
Constructor
// Import module.const GoogleSynthesis = ;// Create an instance.const googleSynthesis = console // Logger used for developing purposes, optional.;
Methods
// Gets the url requests for getting the synthesized audio.let urls = googleSynthesis;
Returns an array of urls since it only allows for a maximum of 500 characters per request.
// Gets the url requests for getting the synthesized audio, using the translate API.let urls = googleSynthesis;
Returns an array of urls since it only allows for a maximum of 200 characters per request. To see which languages are supported see the Google Cloud documentation.
Various extra methods you most likely won't have to deal with
// Slices transcript into sections.let slices = googleSynthesis;console; // Gets a key from translate.google.com.googleSynthesis;
Result of slices will be: ['Hello','world!']
Events
// Emitted when an error occured.googleSynthesis;// If you have set getKey to true in the constructor,// then this event will emit when it has retrieved one.googleSynthesis;
Example
The following example is made for electron so the Web Audio API is available.
// Initialize module, see constructor section for more information.const GoogleSynthesis = ;const googleSynthesis = ; // Audio player.const audio = ; // After this event is called the service can be used.googleSynthesis;
For another example see the Electron-VoiceInterfaceBoilerplate's output.js.
Troubleshooting
If the module suddenly stops working it might be because of several reasons
- If you are using 'request()', you might have exceeded the maximum number of request to the speech API. You currently can't increase this limit.
- If you are using 'requestTranslate()', Google changed the method of creating the required token for each request had changed.