Murf
Mastra 中的 Murf 语音实现提供了使用 Murf AI 语音服务的文本转语音(TTS)功能。它支持多种语言的多种语音。
🌐 The Murf voice implementation in Mastra provides text-to-speech (TTS) capabilities using Murf's AI voice service. It supports multiple voices across different languages.
使用示例Direct link to 使用示例
🌐 Usage Example
import { MurfVoice } from "@mastra/voice-murf";
// Initialize with default configuration (uses MURF_API_KEY environment variable)
const voice = new MurfVoice();
// Initialize with custom configuration
const voice = new MurfVoice({
speechModel: {
name: "GEN2",
apiKey: "your-api-key",
properties: {
format: "MP3",
rate: 1.0,
pitch: 1.0,
sampleRate: 48000,
channelType: "STEREO",
},
},
speaker: "en-US-cooper",
});
// Text-to-Speech with default settings
const audioStream = await voice.speak("Hello, world!");
// Text-to-Speech with custom properties
const audioStream = await voice.speak("Hello, world!", {
speaker: "en-UK-hazel",
properties: {
format: "WAV",
rate: 1.2,
style: "casual",
},
});
// Get available voices
const voices = await voice.getSpeakers();
构造函数参数Direct link to 构造函数参数
🌐 Constructor Parameters
speechModel?:
MurfConfig
= { name: 'GEN2' }
Configuration for text-to-speech functionality
speaker?:
string
= 'en-UK-hazel'
Default voice ID to use for text-to-speech
MurfConfigDirect link to MurfConfig
name:
'GEN1' | 'GEN2'
= 'GEN2'
The Murf model generation to use
apiKey?:
string
Murf API key. Falls back to MURF_API_KEY environment variable
properties?:
object
Default properties for all speech synthesis requests
语音属性Direct link to 语音属性
🌐 Speech Properties
style?:
string
Speaking style for the voice
rate?:
number
Speech rate multiplier
pitch?:
number
Voice pitch adjustment
sampleRate?:
8000 | 24000 | 44100 | 48000
Audio sample rate in Hz
format?:
'MP3' | 'WAV' | 'FLAC' | 'ALAW' | 'ULAW'
Output audio format
channelType?:
'STEREO' | 'MONO'
Audio channel configuration
pronunciationDictionary?:
Record<string, string>
Custom pronunciation mappings
encodeAsBase64?:
boolean
Whether to encode the audio as base64
variation?:
number
Voice variation parameter
audioDuration?:
number
Target audio duration in seconds
multiNativeLocale?:
string
Locale for multilingual support
方法Direct link to 方法
🌐 Methods
speak()Direct link to speak()
使用 Murf 的 API 将文本转换为语音。
🌐 Converts text to speech using Murf's API.
input:
string | NodeJS.ReadableStream
Text to convert to speech. If a stream is provided, it will be converted to text first.
options?:
object
Speech synthesis options
options.speaker?:
string
Override the default speaker for this request
options.properties?:
object
Override default speech properties for this request
返回:Promise<NodeJS.ReadableStream>
🌐 Returns: Promise<NodeJS.ReadableStream>
getSpeakers()Direct link to getSpeakers()
返回一个可用语音选项的数组,每个节点包含:
🌐 Returns an array of available voice options, where each node contains:
voiceId:
string
Unique identifier for the voice
name:
string
Display name of the voice
language:
string
Language code for the voice
gender:
string
Gender of the voice
listen()Direct link to listen()
Murf 不支持此方法,并且会抛出错误。Murf 不提供语音转文本功能。
🌐 This method is not supported by Murf and will throw an error. Murf does not provide speech-to-text functionality.
重要提示Direct link to 重要提示
🌐 Important Notes
- 需要 Murf API 密钥。可以通过
MURF_API_KEY环境变量设置,或在构造函数中传入。 - 该服务使用 GEN2 作为默认模型版本。
- 语音属性可以在构造函数级别设置,并可以针对每个请求进行覆盖。
- 该服务通过格式、采样率和声道类型等属性支持广泛的音频自定义。
- 不支持语音转文本功能。