The Speech class is your primary touch-point.

Instantiate a Speech object with your

from lmnt.api import Speech

const speech = new Speech('LMNT_API_KEY')

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.

const voices = await speech.fetchVoices()

Parameters

options
object

An optional object containing fields to update.

Return value

A list of voice metadata objects. Here’s a sample object:

[
  {
    "name": "Curtis",
    "id": "curtis",
    "state": "ready",
    "owner": "system",
    "starred": false,
    "gender": "male",
    "description": "Curtis' voice carries the seasoned timbre of middle age, filled with warmth, curiosity, and a hint of wisdom gained over the years."
  }
]

fetchVoice

async fetchVoice(voice)

Returns the voice metadata for a single voice.

const voice = await speech.fetchVoice('curtis')

Parameters

voice
string
required

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:

  {
    "name": "Curtis",
    "id": "curtis",
    "state": "ready",
    "owner": "system",
    "starred": false,
    "gender": "male",
    "description": "Curtis' voice carries the seasoned timbre of middle age, filled with warmth, curiosity, and a hint of wisdom gained over the years."
  }

createVoice

async createVoice(name, enhance, filenames, options={})

Creates a new voice from a set of audio files. Returns the voice metadata object.

const filenames = ['file1.wav', 'file2.wav']
const result = await speech.createVoice('new-voice', false, filenames)

Parameters

name
string
required

The name of the voice.

enhance
boolean
required

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.

filenames
string[]
required

A list of filenames to use for the voice.

options
object

Return value

The voice metadata object. Here’s a sample object:

{
    "id": "123444566422",
    "name": "new-voice",
    "owner": "me",
    "state": "ready",
    "starred": false,
    "description": "Totam necessitatibus saepe repudiandae perferendis. Tempora iure provident. Consequatur debitis assumenda. Earum debitis cum.",
    "type": "instant",
    "gender": "male"
}

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.

const options = {'name': 'new-voice-name', 'starred': true}
await speech.updateVoice('123444566422', options)

Parameters

voice_id
string
required

The id of the voice to update. If you don’t know the id, you can get it from list_voices().

options
object

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.

await speech.deleteVoice('123444566422')

Parameters

voice_id
string
required

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:

{
    "success": "true"
}

synthesize

async synthesize(text, voice, options={})

Synthesizes speech for a supplied text string.

const synthesis = await speech.synthesize('Hello world!', 'curtis')
const audio = synthesis.audio

Parameters

text
string
required

The text to synthesize.

voice
string
required

Which voice to render; id is found using the list_voices call.

options
object

Addiitonal options for the synthesis request.

Return value

audio
Buffer

The synthesized audio encoded in the requested format as a Buffer object.

durations
array of duration objects

An array of text duration objects. Only returned if return_durations is True.

seed
number

The seed used for synthesis. Only returned if return_seed is True.

Here is the schema for the return value:

{
  "audio": binary-audio-file,
  "durations": [
    {
      "text": "string",
      "start": 0,
      "duration": 0
    },
    ...
  ],
  "seed": "number"
}

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

voice
string
required

Which voice to render; id can be found using the fetchVoices call.

options
object

Additional options for the streaming connection.

Return value

A StreamingSynthesisConnection instance, which you can use to stream data.