Cloudflare
Mastra 中的 CloudflareVoice 类使用 Cloudflare Workers AI 提供文本转语音功能。该服务提供商专注于高效、低延迟的语音合成,适用于边缘计算环境。
🌐 The CloudflareVoice class in Mastra provides text-to-speech capabilities using Cloudflare Workers AI. This provider specializes in efficient, low-latency speech synthesis suitable for edge computing environments.
使用示例Direct link to 使用示例
🌐 Usage Example
import { CloudflareVoice } from "@mastra/voice-cloudflare";
// Initialize with configuration
const voice = new CloudflareVoice({
speechModel: {
name: "@cf/meta/m2m100-1.2b",
apiKey: "your-cloudflare-api-token",
accountId: "your-cloudflare-account-id",
},
speaker: "en-US-1", // Default voice
});
// Convert text to speech
const audioStream = await voice.speak("Hello, how can I help you?", {
speaker: "en-US-2", // Override default voice
});
// Get available voices
const speakers = await voice.getSpeakers();
console.log(speakers);
配置Direct link to 配置
🌐 Configuration
构造函数选项Direct link to 构造函数选项
🌐 Constructor Options
speechModel?:
speaker?:
CloudflareSpeechConfigDirect link to CloudflareSpeechConfig
name?:
apiKey?:
accountId?:
方法Direct link to 方法
🌐 Methods
speak()Direct link to speak()
使用 Cloudflare 的文本转语音服务将文本转换为语音。
🌐 Converts text to speech using Cloudflare's text-to-speech service.
input:
options.speaker?:
options.format?:
返回:Promise<NodeJS.ReadableStream>
🌐 Returns: Promise<NodeJS.ReadableStream>
getSpeakers()Direct link to getSpeakers()
返回一个可用语音选项的数组,每个节点包含:
🌐 Returns an array of available voice options, where each node contains:
voiceId:
language:
注意Direct link to 注意
🌐 Notes
- API 令牌可以通过构造函数选项或环境变量(CLOUDFLARE_API_TOKEN 和 CLOUDFLARE_ACCOUNT_ID)提供
- Cloudflare Workers AI 针对低延迟的边缘计算进行了优化
- 该提供商仅支持文本转语音(TTS)功能,不支持语音转文本(STT)
- 该服务能够很好地与其他 Cloudflare Workers 产品集成
- 用于生产环境,请确保你的 Cloudflare 账户拥有相应的 Workers AI 订阅
- 与其他一些提供商相比,语音选项更有限,但边缘的性能非常出色
相关提供商Direct link to 相关提供商
🌐 Related Providers
如果你除了需要文字转语音功能外,还需要语音转文字功能,可以考虑使用以下提供商之一:
🌐 If you need speech-to-text capabilities in addition to text-to-speech, consider using one of these providers: