A CommonJS wrapper over Norbert Landsteiner mespeak text-to-speech library. Works in browserify. More
Here is a simple example showing how to use mespeak:
var meSpeak = require("mespeak")
//Select english/american voice
meSpeak.loadVoice(require("mespeak/voices/en/en-us.json"))
//Play a sound
meSpeak.speak("hello world")
It also works in node.js too (though audio playback is unsupported):
var meSpeak = require("mespeak")
meSpeak.loadVoice(require("mespeak/voices/en/en-us.json"))
process.stdout.write(meSpeak.speak("hello world", {rawdata: "buffer"}))
npm install mespeak
The API is identical to that on Landsteiner's web page
var meSpeak = require("mespeak")
meSpeak.speak(str[, options])Says a string.
str is a string to sayoptions is a list of options to pass to the speech synthesizer. For more info, see here.The options argument takes the following parameters:
buffer: A node.js buffer containing a wav fileNote: The value of 'rawdata' must evaluate to boolean 'true' in order to be recognized.
meSpeak.loadConfig(json | url[, callback])Loads a configuration for mespeak. By default uses mespeak/mespeak_config.json There are two forms.
json Synchronously loads a configuration JSON object. This can be done using require("filename.json")The other option is to load the config asynchronously via http:
url is the url of the config filecallback is called once the config is loadedmeSpeak.isConfigLoaded()Checks if mespeak is configured
meSpeak.loadVoice(json | url[, callback] )Loads a voice for mespeak. You can either specify a url and a callback, or a JSON object. A list of voices are included in the voices/ directory. For example, to load an english voice you can do:
meSpeak.loadVoice(require("mespeak/voices/en/en-us.json"))`
The other form is the same as in meSpeak.loadConfig and takes two arguments:
url which is the url of the voice to loadcallback which is an optional callback-handler. The callback will receive two arguments:
meSpeak.setDefaultVoice(str)Sets the default voice to use. The default voice is always the the last voice loaded.
meSpeak.isVoiceLoaded()Checks if a voice is loaded
meSpeak.getDefaultVoice()Returns the default voice.
meSpeak.setVolume(volume)Sets the volume of playback globally.
volume is the volume represented as a floatThis update happens immediately and is applied relatively
meSpeak.getVolume()Returns playback volume.
meSpeak.play(stream[, relativeVolume])Plays a sound. You can use this to cache previously generated voices and play them back at run time by setting the
stream is a sound to playrelativeVolume is the relative loudness of the soundmeSpeak.resetQueue()Clears playback queue, stops all currently playing sounds.
meSpeak.canPlay()Checks if mespeak can play a sound.
(c) 2011-2013 Norbert Landsteiner. GPL License
NPM entry currently maintained by Mikola Lysenko