mcpField
Q
qwen3-tts-mlx

qwen3-tts-mlx

github.com/agiseek创意与媒体464 次安装35 周前更新
代码仓库

关于 qwen3-tts-mlx

qwen3-tts-mlx 是面向 Apple Silicon Mac 的本地语音合成技能,基于 MLX 运行 Qwen3-TTS。它支持多语言语音生成、风格控制、文本设计音色和参考音频克隆。

主要功能

  1. 01支持 11 种语言合成
  2. 02提供 9 种内置音色
  3. 03通过提示词控制语气与风格
  4. 04根据文字描述设计音色
  5. 05根据参考音频克隆声音
  6. 06支持批量配音处理

适用场景

  1. 01离线制作旁白、有声书或播客
  2. 02为视频生成多语言配音
  3. 03按描述创建自定义声音
  4. 04用短音频样本生成克隆音色

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/agiseek/agent-skills --skill qwen3-tts-mlx

安装后在 Claude Code 中输入/qwen3-tts-mlx确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
dubbing_format.md
scripts/
batch_dubbing.py
run_tts.py

详细介绍

Qwen3-TTS MLX

使用 MLX 在 Apple Silicon(M1/M2/M3/M4)上本地运行 Qwen3-TTS。支持 11 种语言、9 种内置音色、声音克隆,以及根据文本描述设计音色。

适用场景

  • 在 Mac 上完全离线生成语音
  • 制作旁白、有声读物、播客或视频配音
  • 创建风格和情感可控的多语言 TTS
  • 根据简短音频样本克隆任意声音
  • 根据文本描述设计自定义音色

快速开始

安装
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

模型变体

变体模型大小内存用途
CustomVoicemlx-community/Qwen3-TTS-12Hz-0.6B-CustomVoice-4bit~1GB~4GB内置音色 + 风格控制(推荐)
VoiceDesignmlx-community/Qwen3-TTS-12Hz-1.7B-VoiceDesign-5bit~2GB~5GB根据文本描述创建音色
Basemlx-community/Qwen3-TTS-12Hz-0.6B-Base-4bit~1GB~4GB根据参考音频克隆声音

支持的语言

语言代码备注
自动检测auto默认值,根据文本检测
中文Chinese普通话
英语English
日语Japanese
韩语Korean
法语French
德语German
西班牙语Spanish
葡萄牙语Portuguese
意大利语Italian
俄语Russian

内置音色

音色语言特点
Vivian中文女性,明亮、年轻
Serena中文女性,温柔、轻柔
Uncle_Fu中文男性,威严,新闻主播风格
Dylan中文男性,北京话
Eric中文男性,四川话
Ryan英语男性,充满活力
Aiden英语男性,清晰、中性
Ono_Anna日语女性
Sohee韩语女性

音色选择指南:

场景推荐音色
中文新闻/旁白Uncle_Fu
中文日常/活泼内容Eric
中文女性、专业风格Vivian
中文女性、讲故事风格Serena
英语活力型内容Ryan
英语中性/教育内容Aiden
日语内容Ono_Anna
韩语内容Sohee

模式

1) CustomVoice

使用内置音色,并可通过 --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" - 轻声细语、近距离麦克风效果
2) VoiceDesign

通过自然语言描述,创建全新的音色。

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"
3) VoiceClone

根据参考音频样本克隆任意声音(建议时长为 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

声音克隆提示:

  • 使用没有背景噪音的干净音频
  • 5-10 秒的语音效果最佳
  • 提供准确的参考音频转录文本
  • 参考音频与输出的语言应一致

CLI 参数

参数必填默认值描述
--text是-要合成的文本
--voice否Vivian内置语音(仅限 CustomVoice)
--lang_code否auto语言代码
--instruct否-风格控制或语音描述
--speed否1.0语速倍率
--temperature否0.7采样温度(越高变化越大)
--model否(per mode)覆盖默认模型
--output否-输出文件路径
--out-dir否./outputs未设置 --output 时的输出目录
--ref_audioVoiceClone-参考音频文件
--ref_textVoiceClone-参考音频转录文本

Python API

使用 generate_audio(推荐)
from mlx_audio.tts.generate import generate_audio

# CustomVoice with style control
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,
)
直接使用 Model
from mlx_audio.tts.utils import load
import soundfile as sf
import numpy as np

# Load model
model = load("mlx-community/Qwen3-TTS-12Hz-0.6B-CustomVoice-4bit")

# Generate audio (returns a generator)
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)

# Combine and save
audio = np.concatenate(audio_chunks)
sf.write("output.wav", audio, 24000)
VoiceDesign
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,
)
VoiceClone
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
语音克隆质量不佳使用更清晰的参考音频和准确的转录文本
分词器警告无害,可忽略
内存不足关闭其他应用,使用 4-bit 模型

评论

支持 Markdown