跳到主要内容
非官方简体中文翻译,内容版权归 Mastra 所有,遵循 Apache-2.0 许可。

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.

Installation
Installation的直接链接

npm install @mastra/voice-modelslab@latest

API key
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 example
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 parameters
Constructor parameters的直接链接

speechModel?:

ModelsLabVoiceConfig
Configuration for text-to-speech.
ModelsLabVoiceConfig

name?:

'default'
ModelsLab speech model name.

apiKey?:

string
ModelsLab API key. Falls back to the MODELSLAB_API_KEY environment variable.

speaker?:

ModelsLabVoiceId | string
= '1'
Default voice ID or OpenAI-style speaker alias.

Voices
Voices的直接链接

ModelsLab exposes six built-in English voices:

IDNameGenderLanguage
1Neutralneutralen
2Malemaleen
3Warmmaleen
4Deep Malemaleen
5Femalefemaleen
6Clear Femalefemaleen

OpenAI-style aliases map to these voices:

AliasVoice ID
alloy1
echo2
fable3
onyx4
nova5
shimmer6

Methods
Methods的直接链接

speak()
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:

string | NodeJS.ReadableStream
Text to convert to speech. A readable stream is fully buffered and converted to text first.

options?:

object
Options for the synthesis request.
object

speaker?:

ModelsLabVoiceId | string
Voice ID or OpenAI-style alias. Non-numeric values that are not aliases fall back to voice ID 1.

language?:

string
Language sent to the ModelsLab API.

speed?:

number
Speech speed sent to the ModelsLab API.

Returns: Promise<NodeJS.ReadableStream>

getSpeakers()
getspeakers的直接链接

Returns the built-in ModelsLab voice metadata.

voiceId:

string
Voice identifier from 1 through 6.

name:

string
Display name of the voice.

language:

string
Language code for the voice.

gender:

string
Gender metadata for the voice.

Returns: Promise<Array<{ voiceId: string; name: string; language: string; gender: string }>>

listen()
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 notes
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.
  • speed doesn'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.