本地Qwen3-TTS语音合成,通过MLX在Apple Silicon上运行。适用于离线旁白、有声书、视频配音及多语言TTS。
使用 MLX. 支持 11 种语言, 9 种内置语音, 语音克隆, 以及文本描述中的声音设计.是一项面向实际任务的技能。它将相关步骤、工具调用和结果整理方式集中到统一流程中,帮助使用者更快完成目标并减少重复操作。
实际使用前应先确认任务范围、数据来源、运行环境、必要权限和关键参数,再依据技能说明逐步执行;若输入条件不完整,应先补齐信息或采用保守配置,避免因错误假设导致结果偏离需求。
执行过程中需要关注工具调用是否成功、接口或依赖是否可用、输出格式是否符合预期,并对异常提示、缺失字段和边界情况进行处理;涉及批量任务时,还应保存进度,避免中断后重复操作。
使用 MLX 在 Apple Silicon(M1/M2/M3/M4)设备上本地运行 Qwen3-TTS。支持 11 种语言、9 种内置语音、语音克隆,以及基于文本描述的语音设计。
pip install mlx-audio brew install ffmpeg
python scripts/run_tts.py custom-voice --text "Hello, welcome to local text to speech." --voice Ryan --output output.wav
python scripts/run_tts.py custom-voice --text "Breaking news: local AI model achieves human-level speech." --voice Uncle_Fu --instruct "news anchor tone, calm and authoritative" --output news.wav
| 变体 | 模型 | 大小 | 内存占用 | 适用场景 |
|---|---|---|---|---|
| CustomVoice | mlx-community/Qwen3-TTS-12Hz-0.6B-CustomVoice-4bit |
~1GB | ~4GB | 内置语音 + 风格控制(推荐) |
| VoiceDesign | mlx-community/Qwen3-TTS-12Hz-1.7B-VoiceDesign-5bit |
~2GB | ~5GB | 基于文本描述创建语音 |
| Base | mlx-community/Qwen3-TTS-12Hz-0.6B-Base-4bit |
~1GB | ~4GB | 基于参考音频进行语音克隆 |
| 语言 | 代码 | 备注 |
|---|---|---|
| 自动检测 | auto |
默认值,根据输入文本自动识别 |
| 中文 | Chinese |
普通话 |
| 英语 | English |
|
| 日语 | Japanese |
|
| 韩语 | Korean |
|
| 法语 | French |
|
| 德语 | German |
|
| 西班牙语 | Spanish |
|
| 葡萄牙语 | Portuguese |
|
| 意大利语 | Italian |
|
| 俄语 | Russian |
| 语音 | 语言 | 角色特征 |
|---|---|---|
| Vivian | Chinese | 女性,明亮、年轻 |
| Serena | Chinese | 女性,温和、柔和 |
| Uncle_Fu | Chinese | 男性,权威感强,新闻主播风格 |
| Dylan | Chinese | 男性,北京方言 |
| Eric | Chinese | 男性,四川方言 |
| Ryan | English | 男性,富有活力 |
| Aiden | English | 男性,清晰、中性 |
| Ono_Anna | Japanese | 女性 |
| Sohee | Korean | 女性 |
语音选择指南:
| 使用场景 | 推荐语音 |
|---|---|
| 中文新闻/解说 | Uncle_Fu |
| 中文日常/活泼内容 | Eric |
| 中文女性,专业场景 | Vivian |
| 中文女性,讲故事场景 | Serena |
| 英文活力型内容 | Ryan |
| 英文中性/教育类内容 | Aiden |
| 日语内容 | Ono_Anna |
| 韩语内容 | Sohee |
使用内置语音,并可通过 --instruct 参数可选地控制情绪/风格。
python scripts/run_tts.py custom-voice --text "This is amazing news!" --voice Vivian --instruct "excited and happy" --output excited.wav
风格指令示例:
"calm and warm" —— 柔和、亲切的表达方式"news anchor, authoritative" —— 专业的广播播报风格"excited and energetic" —— 高能量、热情洋溢"sad and melancholic" —— 情绪化、忧郁的语调"whispering, intimate" —— 轻声细语、贴近麦克风的感觉通过自然语言描述,创建一个全新的语音。
python scripts/run_tts.py voice-design --text "Welcome to our podcast." --instruct "warm, mature male narrator with low pitch and gentle tone" --output podcast_intro.wav
语音描述示例:
"young cheerful female with high pitch""elderly wise male with deep resonant voice""professional female news anchor, clear articulation""friendly young male, casual and relaxed"从一段参考音频样本中克隆任意语音(建议时长为 5–10 秒)。
python scripts/run_tts.py voice-clone --text "This is my cloned voice speaking new content." --ref_audio reference.wav --ref_text "The exact transcript of the reference audio" --output cloned.wav
语音克隆小贴士:
| 参数 | 是否必需 | 默认值 | 说明 |
|---|---|---|---|
--text |
是 | - | 待合成的文本 |
--voice |
否 | Vivian | 内置语音(仅 CustomVoice 模式支持) |
--lang_code |
否 | auto | 语言代码 |
--instruct |
否 | - | 风格控制指令或语音描述 |
--speed |
否 | 1.0 | 语速倍率 |
--temperature |
否 | 0.7 | 采样温度(数值越高,输出越具变化性) |
--model |
否 | (按模式而定) | 覆盖默认模型路径 |
--output |
否 | - | 输出文件路径 |
--out-dir |
否 | ./outputs | 当未指定 --output 时的默认输出目录 |
--ref_audio |
VoiceClone | - | 参考音频文件路径 |
--ref_text |
VoiceClone | - | 参考音频对应的文字稿 |
from mlx_audio.tts.generate import generate_audio
# CustomVoice 模式 + 风格控制
generate_audio(
text="Hello from Qwen3-TTS!",
model="mlx-community/Qwen3-TTS-12Hz-0.6B-CustomVoice-4bit",
voice="Ryan",
lang_code="english",
instruct="friendly and warm",
output_path=".",
file_prefix="hello",
audio_format="wav",
join_audio=True,
verbose=True,
)
from mlx_audio.tts.utils import load
import soundfile as sf
import numpy as np
# 加载模型
model = load("mlx-community/Qwen3-TTS-12Hz-0.6B-CustomVoice-4bit")
# 生成音频(返回生成器)
audio_chunks = []
for chunk in model.generate_custom_voice(
text="Hello from Qwen3-TTS.",
speaker="Ryan",
language="english",
instruct="clear, steady delivery"
):
if hasattr(chunk, 'audio') and chunk.audio is not None:
audio_chunks.append(chunk.audio)
# 合并并保存
audio = np.concatenate(audio_chunks)
sf.write("output.wav", audio, 24000)
from mlx_audio.tts.generate import generate_audio
generate_audio(
text="Welcome to the show.",
model="mlx-community/Qwen3-TTS-12Hz-1.7B-VoiceDesign-5bit",
instruct="warm, friendly female narrator with medium pitch",
lang_code="english",
output_path=".",
file_prefix="voice_design",
join_audio=True,
)
from mlx_audio.tts.generate import generate_audio
generate_audio(
text="New content in the cloned voice.",
model="mlx-community/Qwen3-TTS-12Hz-0.6B-Base-4bit",
ref_audio="reference.wav",
ref_text="Transcript of the reference audio",
output_path=".",
file_prefix="cloned",
join_audio=True,
)
使用 scripts/batch_dubbing.py 批量处理多行文本:
python scripts/batch_dubbing.py --input dubbing.json --out-dir outputs
JSON 格式定义详见 references/dubbing_format.md。
| 指标 | 数值 |
|---|---|
| 采样率 | 24,000 Hz |
| 实时因子 | ~0.7x(快于实时) |
| 峰值内存占用 | ~4–6 GB |
| 首次运行 | 自动下载模型(约 1–2GB) |
| 问题 | 解决方案 |
|---|---|
| 生成速度慢 | 使用 4-bit 的 CustomVoice 模型 |
| 语音中出现不自然停顿 | 添加标点符号,保持句子简短 |
| 语言识别错误 | 显式指定 --lang_code |
| 语音克隆质量不佳 | 使用更干净的参考音频,并确保文字稿准确 |
| Tokenizer 警告 | 无害,可忽略 |
| 内存不足(OOM) | 关闭其他应用,改用 4-bit 模型 |
相关专题
热门下载
相关下载
精品课程
共6课时 | 54.7万人学习
共89课时 | 133.9万人学习
共49课时 | 82.5万人学习