Chatterbox-TTS-Server API接口文档:构建你的语音应用
Chatterbox-TTS-Server API接口文档构建你的语音应用【免费下载链接】Chatterbox-TTS-ServerSelf-host the powerful Chatterbox TTS model. This server offers a user-friendly Web UI, flexible API endpoints (incl. OpenAI compatible), predefined voices, voice cloning, and large audiobook-scale text processing. Runs accelerated on NVIDIA (CUDA), AMD (ROCm), and CPU.项目地址: https://gitcode.com/gh_mirrors/ch/Chatterbox-TTS-ServerChatterbox-TTS-Server是一个强大的开源文本转语音服务提供完整的API接口和现代化的Web界面。无论你是开发者需要集成语音功能还是普通用户想要轻松生成高质量语音这个项目都能满足你的需求。 核心功能概览Chatterbox-TTS-Server基于Resemble AI的Chatterbox模型系列提供三种不同的TTS引擎原始Chatterbox模型- 高质量的英语语音合成支持情感控制Chatterbox Turbo模型- 优化的350M参数模型支持拟声标签如[laugh]、[cough]Chatterbox多语言模型- 支持23种语言的多语言语音合成 API端点总览Chatterbox-TTS-Server提供了完整的RESTful API接口主要包括以下几个核心端点1. 自定义TTS端点/tts这是最灵活的TTS生成接口支持所有参数控制POST /tts Content-Type: application/json请求参数参数类型必需描述默认值textstring是要合成的文本内容-voice_modestring否语音模式predefined预定义或clone克隆predefinedpredefined_voice_idstring条件预定义语音文件名当voice_modepredefined时必需-reference_audio_filenamestring条件参考音频文件名当voice_modeclone时必需-output_formatstring否输出格式wav、mp3、opuswavsplit_textboolean否是否自动分割长文本truechunk_sizeinteger否文本分块大小50-500字符120streamboolean否是否启用流式输出falsetemperaturefloat否控制随机性0.0-1.50.8exaggerationfloat否控制表达力0.25-2.00.5cfg_weightfloat否分类器自由引导权重0.2-1.00.5seedinteger否生成种子0speed_factorfloat否语速因子0.25-4.01.0languagestring否语言代码en示例请求curl -X POST http://localhost:8004/tts \ -H Content-Type: application/json \ -d { text: 欢迎使用Chatterbox TTS服务器这是一个强大的文本转语音服务。, voice_mode: predefined, predefined_voice_id: Alice.wav, output_format: mp3, temperature: 0.7, speed_factor: 1.2 } \ --output output.mp32. OpenAI兼容端点/v1/audio/speech为了便于集成Chatterbox-TTS-Server提供了与OpenAI TTS API兼容的接口POST /v1/audio/speech Content-Type: application/json请求参数参数类型必需描述默认值modelstring否模型标识符chatterboxinputstring是要合成的文本-voicestring否语音文件名default_sample.wavresponse_formatstring否输出格式wav、opuswavspeedfloat否语速因子1.0seedinteger否生成种子0languagestring否语言代码en示例请求curl -X POST http://localhost:8004/v1/audio/speech \ -H Content-Type: application/json \ -d { input: 这是一个与OpenAI API兼容的文本转语音接口。, voice: Robert.wav, response_format: opus, speed: 1.0 } \ --output speech.opus 辅助API端点1. 获取语音列表/v1/audio/voices获取所有可用的预定义语音列表GET /v1/audio/voices响应示例{ voices: [ { display_name: Alice, filename: Alice.wav }, { display_name: Robert, filename: Robert.wav } ] }2. 获取模型信息/api/model-info获取当前加载的模型信息和状态GET /api/model-info响应示例{ model_loaded: true, model_type: turbo, device: cuda, supported_languages: { en: English, zh: Chinese, ja: Japanese } }3. 卸载模型/api/unload释放GPU/CPU内存中的模型POST /api/unload响应{ status: unloaded } 文件管理API1. 获取参考音频文件列表/get_reference_filesGET /get_reference_files2. 获取预定义语音列表/get_predefined_voicesGET /get_predefined_voices3. 上传参考音频/upload_referencePOST /upload_reference Content-Type: multipart/form-data4. 上传预定义语音/upload_predefined_voicePOST /upload_predefined_voice Content-Type: multipart/form-data⚙️ 配置管理API1. 保存设置/save_settingsPOST /save_settings Content-Type: application/json2. 重置设置/reset_settingsPOST /reset_settings3. 重启服务器/restart_serverPOST /restart_server 快速开始使用API步骤1启动服务器首先确保你已经安装了Chatterbox-TTS-Server。可以通过以下方式启动# 使用启动脚本 ./start.sh # Linux/macOS start.bat # Windows # 或直接运行 python server.py步骤2测试API连接使用curl测试服务器是否正常运行curl http://localhost:8004/api/model-info步骤3生成第一个语音使用预定义语音生成语音curl -X POST http://localhost:8004/tts \ -H Content-Type: application/json \ -d { text: 你好世界这是Chatterbox TTS服务器的测试。, voice_mode: predefined, predefined_voice_id: Alice.wav, output_format: mp3 } \ --output hello.mp3步骤4使用语音克隆上传参考音频并克隆语音# 1. 上传参考音频 curl -X POST http://localhost:8004/upload_reference \ -F filesmy_voice.wav # 2. 使用克隆的语音生成 curl -X POST http://localhost:8004/tts \ -H Content-Type: application/json \ -d { text: 使用我的声音克隆生成的语音, voice_mode: clone, reference_audio_filename: my_voice.wav } \ --output cloned.mp3 编程语言集成示例Python集成import requests import json class ChatterboxTTSClient: def __init__(self, base_urlhttp://localhost:8004): self.base_url base_url def generate_speech(self, text, voice_idAlice.wav, output_formatmp3): 生成语音 url f{self.base_url}/tts payload { text: text, voice_mode: predefined, predefined_voice_id: voice_id, output_format: output_format, temperature: 0.8, speed_factor: 1.0 } response requests.post(url, jsonpayload) if response.status_code 200: return response.content else: raise Exception(fAPI错误: {response.status_code}) def list_voices(self): 获取可用语音列表 url f{self.base_url}/v1/audio/voices response requests.get(url) return response.json() # 使用示例 client ChatterboxTTSClient() audio_data client.generate_speech(这是一个Python集成的示例) with open(output.mp3, wb) as f: f.write(audio_data)JavaScript集成async function generateSpeech(text, voice Alice.wav) { const response await fetch(http://localhost:8004/tts, { method: POST, headers: { Content-Type: application/json, }, body: JSON.stringify({ text: text, voice_mode: predefined, predefined_voice_id: voice, output_format: mp3 }) }); if (response.ok) { const audioBlob await response.blob(); const audioUrl URL.createObjectURL(audioBlob); return audioUrl; } else { throw new Error(语音生成失败); } } // 使用示例 generateSpeech(这是一个JavaScript示例) .then(audioUrl { const audio new Audio(audioUrl); audio.play(); }) .catch(error console.error(error)); 高级功能配置1. 流式输出对于长文本如电子书可以使用流式输出curl -X POST http://localhost:8004/tts \ -H Content-Type: application/json \ -d { text: 这是一个很长的文本内容..., stream: true } \ --output stream.wav2. 多语言支持使用多语言模型生成不同语言的语音curl -X POST http://localhost:8004/tts \ -H Content-Type: application/json \ -d { text: Bonjour, comment allez-vous?, language: fr, voice_mode: predefined, predefined_voice_id: Alice.wav } \ --output french.mp33. 使用拟声标签仅Turbo模型curl -X POST http://localhost:8004/tts \ -H Content-Type: application/json \ -d { text: 这个笑话真好笑[laugh]让我先喝口水[cough]。, voice_mode: predefined, predefined_voice_id: Alice.wav } \ --output with_tags.mp3 安全注意事项路径遍历防护API端点对predefined_voice_id和reference_audio_filename参数进行了安全处理防止路径遍历攻击文件上传验证上传的文件会进行格式和大小验证输入验证所有输入参数都经过Pydantic模型验证️ 故障排除常见API错误错误代码含义解决方法400请求参数错误检查请求体格式和参数值404语音文件未找到确认语音文件存在于相应目录500服务器内部错误查看服务器日志获取详细信息503模型未加载等待模型加载完成或检查模型配置检查服务器状态# 检查服务器是否运行 curl http://localhost:8004/api/model-info # 查看可用语音 curl http://localhost:8004/v1/audio/voices # 查看配置 curl http://localhost:8004/api/ui/initial-data 最佳实践使用合适的文本分块对于长文本启用split_text并设置合适的chunk_size选择合适的语音模式预定义语音适合一致性要求高的场景语音克隆适合个性化需求调整生成参数根据需求调整temperature、exaggeration等参数使用种子保证一致性需要相同输出时使用固定的seed值监控资源使用长时间运行建议监控GPU内存使用情况 性能优化建议启用BF16推理在支持BF16的GPU上设置环境变量TTS_BF16on可提升40%吞吐量合理设置分块大小根据文本长度和硬件性能调整chunk_size使用语音条件缓存重复使用相同参考语音的请求会跳过重新编码选择合适的输出格式opus格式文件更小适合网络传输 实际应用场景1. 内容创作播客和有声书生成视频配音教育内容制作2. 应用程序集成语音助手无障碍功能游戏语音生成3. 企业应用客服语音系统培训材料制作多语言内容本地化 更新和维护更新服务器版本# 拉取最新代码 git pull origin main # 更新依赖 python start.py --upgrade # 重启服务器 python server.py备份配置# 备份配置文件 cp config.yaml config.yaml.backup 总结Chatterbox-TTS-Server提供了一个功能完整、易于集成的TTS API接口支持多种语音模式、多语言输出和高级生成参数控制。无论是简单的文本转语音需求还是复杂的语音应用开发都能通过其丰富的API接口实现。通过本文档你应该已经掌握了如何使用Chatterbox-TTS-Server的API接口来构建自己的语音应用。记得查阅官方文档获取更多详细信息并根据实际需求调整配置参数。现在就开始使用Chatterbox-TTS-Server为你的应用添加高质量的语音功能吧【免费下载链接】Chatterbox-TTS-ServerSelf-host the powerful Chatterbox TTS model. This server offers a user-friendly Web UI, flexible API endpoints (incl. OpenAI compatible), predefined voices, voice cloning, and large audiobook-scale text processing. Runs accelerated on NVIDIA (CUDA), AMD (ROCm), and CPU.项目地址: https://gitcode.com/gh_mirrors/ch/Chatterbox-TTS-Server创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考