Speech
Reference for the Speech class in the Node.js SDK
The Speech
class is your primary touch-point.
Instantiate a Speech
object with your
Alternatively, you can set the LMNT_API_KEY
environment variable and omit the constructor argument.
fetchVoices
async fetchVoices(options={})
Returns the voices available for use in speech synthesis calls.
Parameters
An optional object containing fields to update.
Return value
A list of voice metadata objects. Here’s a sample object:
fetchVoice
async fetchVoice(voice)
Returns the voice metadata for a single voice.
Parameters
The id of the voice to update. Voice ids can be retrieved from fetchVoices()
.
Return value
The voice metadata object. Here’s a sample object:
createVoice
async createVoice(name, enhance, filenames, options={})
Creates a new voice from a set of audio files. Returns the voice metadata object.
Parameters
The name of the voice.
For unclean audio with background noise, applies processing to attempt to improve quality. Not on by default as it can also degrade quality in some circumstances.
A list of filenames to use for the voice.
Return value
The voice metadata object. Here’s a sample object:
updateVoice
async updateVoice(voice, options={})
Updates metadata for a specific voice. A voice that is not owned by you can only have its starred
field updated.
Only provided fields will be changed.
Parameters
The id of the voice to update. If you don’t know the id, you can get it from list_voices()
.
The properties to update. Only provided fields will be changed.
Return value
The updated voice metadata object.
deleteVoice
async deleteVoice(voice)
Deletes a voice and cancels any pending operations on it. The voice must be owned by you. Cannot be undone.
Parameters
The id of the voice to delete. If you don’t know the id, you can get it from list_voices()
.
Return value
A success or error message. Here’s a sample object:
synthesize
async synthesize(text, voice, options={})
Synthesizes speech for a supplied text string.
Parameters
The text to synthesize.
Which voice to render; id is found using the list_voices
call.
Additional options for the synthesis request.
Return value
The synthesized audio encoded in the requested format as a Buffer object.
An array of text duration objects. Only returned if return_durations
is True
.
The seed used for synthesis. Only returned if return_seed
is True
.
Here is the schema for the return value:
Notes
- The
mp3
bitrate is 96kbps.
synthesizeStreaming
synthesizeStreaming(voice, options={})
Creates a new, full-duplex streaming session. You can use the returned connection object to concurrently stream text content to the server and receive speech data from the server.
Parameters
Which voice to render; id can be found using the fetchVoices
call.
Additional options for the streaming connection.
Return value
A StreamingSynthesisConnection
instance, which you can use to stream data.
Was this page helpful?