ModelsLab
ModelsLab provides text-to-speech (TTS) only. The Mastra integration submits an asynchronous synthesis job, waits for the audio URL, downloads the completed audio, and returns it as a Node.js readable stream.
InstallationDirect link to Installation
- npm
- pnpm
- Yarn
- Bun
npm install @mastra/voice-modelslab@latest
pnpm add @mastra/voice-modelslab@latest
yarn add @mastra/voice-modelslab@latest
bun add @mastra/voice-modelslab@latest
API keyDirect link to API key
Set MODELSLAB_API_KEY or pass the key through speechModel.apiKey. The constructor throws MODELSLAB_API_KEY is not set when neither value is available.
Usage exampleDirect link to Usage example
import { ModelsLabVoice } from '@mastra/voice-modelslab'
const voice = new ModelsLabVoice({
speechModel: {
apiKey: process.env.MODELSLAB_API_KEY,
},
speaker: '5',
})
const audioStream = await voice.speak('Hello, world!', {
speaker: 'nova',
language: 'english',
speed: 1,
})
const speakers = await voice.getSpeakers()
Constructor parametersDirect link to Constructor parameters
speechModel?:
name?:
apiKey?:
speaker?:
VoicesDirect link to Voices
ModelsLab exposes six built-in English voices:
| ID | Name | Gender | Language |
|---|---|---|---|
1 | Neutral | neutral | en |
2 | Male | male | en |
3 | Warm | male | en |
4 | Deep Male | male | en |
5 | Female | female | en |
6 | Clear Female | female | en |
OpenAI-style aliases map to these voices:
| Alias | Voice ID |
|---|---|
alloy | 1 |
echo | 2 |
fable | 3 |
onyx | 4 |
nova | 5 |
shimmer | 6 |
MethodsDirect link to Methods
speak()Direct link to speak
Converts text to speech. If ModelsLab returns a processing ID, the integration polls every five seconds for up to five minutes. It downloads the completed audio before returning the readable stream, so this method doesn't provide progressive audio streaming.
input:
options?:
speaker?:
language?:
speed?:
Returns: Promise<NodeJS.ReadableStream>
getSpeakers()Direct link to getspeakers
Returns the built-in ModelsLab voice metadata.
voiceId:
name:
language:
gender:
Returns: Promise<Array<{ voiceId: string; name: string; language: string; gender: string }>>
listen()Direct link to listen
ModelsLab doesn't support speech-to-text. Calling this method throws an error that points to @mastra/voice-deepgram as a listening provider.
Important notesDirect link to Important notes
- ModelsLab text-to-speech requests send the API key in the request body.
- Processing jobs are polled every five seconds and time out after 300 seconds.
- The completed audio is fully downloaded before the stream is returned. The stream isn't progressive.
- The integration doesn't force an output format. It downloads the audio from the URL returned by ModelsLab.
speeddoesn't have runtime range validation in this package.- Non-numeric speaker values that don't match an alias fall back to voice ID
1. - Speech-to-text isn't supported.