闪电般的速度,母语般的质感——用Supertonic在设备端实现零延迟多语言语音合成,让AI Agent开口说话这件事变得既快又稳。
世界上有一种等待叫"等AI把文字变成声音的那三秒钟"。三秒,足够让用户放弃等待、关掉页面、再也不回来。设备端TTS(Text-to-Speech)的意义就在于把这三秒变成30毫秒——快到你根本感觉不到延迟。
| 维度 | 云端TTS | 设备端TTS(Supertonic) |
|---|---|---|
| 延迟 | 200-3000ms | 30-100ms |
| 隐私 | 数据上传到服务器 | 数据不离开设备 |
| 离线能力 | 无 | 完全支持 |
| 成本 | 按调用付费 | 零边际成本 |
| 多语言 | 广泛支持 | 30+语言 |
| 音质 | 优秀 | 优秀(接近云端) |
Supertonic 技术栈:
┌─────────────────────────────────────────┐
│ 应用层 │
│ [iOS App] [macOS App] [CLI] [API] │
└─────────────────┬───────────────────────┘
│
┌─────────────────┴───────────────────────┐
│ Swift SDK │
│ SupertonicKit │
│ - 流式TTS接口 │
│ - 语音管理 │
│ - 音频缓冲 │
└─────────────────┬───────────────────────┘
│
┌─────────────────┴───────────────────────┐
│ ONNX Runtime │
│ onnxruntime-swift │
│ - CoreML加速 │
│ - Metal GPU推理 │
│ - 内存优化 │
└─────────────────┬───────────────────────┘
│
┌─────────────────┴───────────────────────┐
│ 模型层 │
│ VITS / MeloTTS / Kokoro │
│ 多语言模型文件 (~50-200MB) │
└─────────────────────────────────────────┘
// Package.swift
// swift-tools-version: 5.9
import PackageDescription
let package = Package(
name: "MyApp",
platforms: [.iOS(.v16), .macOS(.v13)],
dependencies: [
.package(url: "https://github.com/supertone-inc/supertonic.git",
from: "1.0.0"),
.package(url: "https://github.com/microsoft/onnxruntime-swift.git",
from: "1.16.0")
]
)
# 下载多语言TTS模型 # 模型大小约50-200MB curl -L -o models/melo-tts-zh.onnx \ https://huggingface.co/supertonic/melo-tts-zh/resolve/main/model.onnx # 英文模型 curl -L -o models/melo-tts-en.onnx \ https://huggingface.co/supertonic/melo-tts-en/resolve/main/model.onnx # 多语言联合模型(推荐) curl -L -o models/supertonic-multilingual.onnx \ https://huggingface.co/supertonic/multilingual/resolve/main/model.onnx
import SupertonicKit
class SpeechManager {
private let engine: SupertonicEngine
init() async throws {
// 初始化引擎
engine = try await SupertonicEngine(
modelPath: Bundle.main.path(
forResource: "supertonic-multilingual",
ofType: "onnx"
)!,
config: .default
)
}
// 基础合成
func speak(_ text: String) async throws {
let audio = try await engine.synthesize(
text: text,
voice: .default,
language: .chinese
)
// 播放音频
try await AudioPlayer.shared.play(audio)
}
// 流式合成(低延迟)
func speakStreaming(_ text: String) async throws {
let stream = engine.synthesizeStream(
text: text,
voice: .default,
language: .chinese
)
for try await audioChunk in stream {
try await AudioPlayer.shared.playChunk(audioChunk)
}
}
}
// 自定义语音参数
struct TTSConfig {
// 语速控制(0.5 - 2.0)
var speed: Float = 1.0
// 音调控制(-12 - 12 半音)
var pitch: Float = 0
// 情感强度(0 - 1)
var emotionIntensity: Float = 0.5
// 采样率
var sampleRate: Int = 24000
}
// 使用自定义配置
let config = TTSConfig(
speed: 1.2,
pitch: 2,
emotionIntensity: 0.8
)
let audio = try await engine.synthesize(
text: "世界上有一种AI叫做妙趣",
voice: .custom(name: "cheerful"),
language: .chinese,
config: config
)
将Supertonic封装为OpenClaw的TTS Skill,让Agent获得语音输出能力:
// skills/tts-supertonic/SKILL.md ## Supertonic 设备端TTS技能 当需要将文字转为语音时: 1. 使用 supertonic_speak 工具 2. 支持多语言、语速调节、情感控制 3. 自动检测输入文本语言 4. 优先使用设备端TTS,降级到云端API **适用场景:** - 为视障用户提供语音反馈 - 语音助手对话 - 有声内容生成 - 实时翻译语音输出
// skills/tts-supertonic/index.ts
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
const server = new McpServer({
name: 'supertonic-tts',
version: '1.0.0',
});
server.tool(
'supertonic_speak',
'使用Supertonic设备端TTS将文字转为语音',
{
text: { type: 'string', description: '要转为语音的文本' },
language: { type: 'string', description: '语言代码', default: 'zh' },
speed: { type: 'number', description: '语速(0.5-2.0)', default: 1.0 },
emotion: { type: 'string', description: '情感', enum: ['neutral', 'happy', 'sad', 'angry'] },
outputFormat: { type: 'string', description: '输出格式', enum: ['wav', 'mp3', 'pcm'] },
},
async ({ text, language, speed, emotion, outputFormat }) => {
const response = await fetch('http://localhost:8080/synthesize', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text, language, speed, emotion, outputFormat }),
});
const audioBuffer = await response.arrayBuffer();
const base64Audio = Buffer.from(audioBuffer).toString('base64');
return {
content: [{
type: 'text',
text: JSON.stringify({
audio: `data:audio/${outputFormat};base64,${base64Audio}`,
duration: response.headers.get('x-duration'),
sampleRate: response.headers.get('x-sample-rate'),
})
}]
};
}
);
| 语言 | 代码 | 质量 | 模型大小 |
|---|---|---|---|
| 中文普通话 | zh-CN | 优秀 | 85MB |
| 英语(美) | en-US | 优秀 | 60MB |
| 日语 | ja | 良好 | 75MB |
| 韩语 | ko | 良好 | 70MB |
| 西班牙语 | es | 优秀 | 65MB |
| 法语 | fr | 优秀 | 65MB |
| 德语 | de | 良好 | 68MB |
| 泰语 | th | 良好 | 72MB |
// 自动检测并处理混合语言
let mixedText = "这是一个多语言示例, Hello World! "
let segments = try await engine.detectLanguageSegments(mixedText)
// 结果:
// [
// { text: "这是一个多语言示例", language: "zh", confidence: 0.98 },
// { text: ", Hello World! ", language: "en", confidence: 0.99 },
// { text: "", language: "zh", confidence: 0.95 }
// ]
for segment in segments {
let audio = try await engine.synthesize(
text: segment.text,
language: Language(segment.language)
)
// 拼接各语言段音频
combinedAudio.append(audio)
}
engine.warmup() 方法。
// 性能优化配置
let optimizedConfig = SupertonicConfig(
// 使用Metal GPU推理
computeUnits: .all,
// 内存优化
memoryMode: .optimized,
// 线程配置
intraOpNumThreads: ProcessInfo.processInfo.activeProcessorCount,
// 音频缓冲
audioBufferSize: 4096,
// 预热模型
warmupOnLoad: true
)
Supertonic支持基于少量样本的语音克隆:
// 从音频样本克隆语音
let voiceSamples = [
URL(fileURLWithPath: "./samples/voice_01.wav"),
URL(fileURLWithPath: "./samples/voice_02.wav"),
URL(fileURLWithPath: "./samples/voice_03.wav"),
]
let clonedVoice = try await engine.cloneVoice(
from: voiceSamples,
name: "my_voice",
quality: .high // 需要更多样本和时间
)
// 使用克隆语音合成
let audio = try await engine.synthesize(
text: "用我自己的声音说话",
voice: clonedVoice,
language: .chinese
)
Supertonic证明了设备端TTS已经可以媲美云端服务的音质,同时拥有零延迟、零成本、完全离线的独特优势。通过Swift原生实现和ONNX加速,它为iOS/macOS开发者提供了最佳的TTS集成体验。当它与OpenClaw的Agent能力结合时,AI真正有了"嘴巴"——快速、清晰、随时在线。
最后更新:2026-05-16 | 妙趣AI - AI工具导航与教程平台