UniSound TTS - Text-to-Speech
云知声语音合成
Text-to-speech conversion using UniSound's TTS WebSocket API for generating high-quality Chinese Mandarin audio from text.
使用云知声 TTS WebSocket API 进行文本转语音转换,生成高质量中文普通话音频。
When to Use This Skill
Use UniSound TTS for:
- - Converting Chinese text to natural-sounding speech
- Generating audio for audiobooks, podcasts, or content creation
- Creating accessibility solutions for visually impaired users
- Building voice assistants or chatbot voice responses
- Batch processing text to audio files
- Custom speech synthesis with adjustable parameters (speed, volume, pitch, brightness)
Do NOT use for:
- - Real-time speech recognition or transcription (use ASR skills instead)
- English language synthesis (optimized for Chinese Mandarin)
- Voice cloning or custom voice model training
Use when: The user needs text-to-speech conversion, asks for "语音合成" (speech synthesis), or mentions UniSound/云知声 TTS.
Installation
Install Python dependencies before using this skill. From the skill directory (skills/tts-tools):
CODEBLOCK0
Requires Python 3.6+.
How to Use This Skill
⛔ MANDATORY RESTRICTIONS - DO NOT VIOLATE ⛔
- 1. ONLY use UniSound TTS API - Execute the script INLINECODE1
- NEVER synthesize speech directly - Do NOT attempt local TTS synthesis
- NEVER offer alternatives - Do NOT suggest "I can try another method" or similar
- IF API fails - Display the error message and STOP immediately
- NO fallback methods - Do NOT attempt text-to-speech any other way
If the script execution fails (API not configured, network error, etc.):
- - Show the error message to the user
- Do NOT offer to help using your TTS capabilities
- Do NOT ask "Would you like me to try synthesizing it?"
- Simply stop and wait for user to fix the configuration
Basic Workflow
- 1. Configure credentials (first time only):
CODEBLOCK1
- 2. Execute text-to-speech conversion:
CODEBLOCK2
Command options:
- --text TEXT - Text to convert to speech (default: '今天天气怎么样?')
- --voice VOICE - Voice name (default: xiaofeng-base)
- --format FORMAT - Output format: mp3, wav, pcm (default: mp3)
- --sample RATE - Sample rate: 8k, 16k, 24k (default: 24k)
- --speed SPEED - Speech speed 0-100 (default: 50)
- --volume VOLUME - Volume level 0-100 (default: 50)
- --pitch PITCH - Pitch level 0-100 (default: 50)
- --bright BRIGHT - Brightness/tone 0-100 (default: 50)
- --appkey APPKEY - Override appkey (default: UNISOUND_APPKEY env var)
- --secret SECRET - Override secret (default: UNISOUND_SECRET env var)
- 3. Output:
- Audio files are saved to
results/ directory
- Filename format:
<timestamp>.<format>
- Example: INLINECODE14
Understanding the Output
Audio Format Options:
- - MP3: Compressed, smaller file size, good quality - best for web and streaming
- WAV: Uncompressed, excellent quality - best for production and archival
- PCM: Raw audio data - best for further audio processing
Sample Rates:
- - 24k: High quality, default - recommended for most use cases
- 16k: Standard quality - good balance of quality and size
- 8k: Lower quality, smaller file size - suitable for telephony
Usage Examples
Example 1: Quick Start with Test Credentials
# Set test credentials
export UNISOUND_APPKEY='ce44uxf7g5eag2cv33qvlp5d22qrkgcezvgfp2q3'
export UNISOUND_SECRET='5c12231cd279b35873a3ccecf9439118'
# Convert text to speech
python scripts/tts.py --text '你好世界'
Output: INLINECODE15
Example 2: Custom Voice and Format
python scripts/tts.py --text '今天天气怎么样' --voice xiaofeng-base --format wav
Output: High-quality WAV file with male voice
Example 3: Adjusted Speech Parameters
python scripts/tts.py --text '快速朗读' --speed 70 --volume 60 --pitch 50
Output: Faster speech with increased volume
Example 4: High-Quality Audio Production
python scripts/tts.py --text '高质量音频' --format wav --sample 24k --volume 60
Output: Production-quality WAV file at 24kHz
Example 5: Command-line Credential Override
CODEBLOCK7
How It Works
The script uses the UniSound TTS WebSocket API with the following workflow:
- 1. Authenticate using SHA256 signature (appkey + timestamp + secret)
使用 SHA256 签名进行身份验证
- 2. Establish WebSocket connection to INLINECODE16
建立 WebSocket 连接到云知声 TTS 服务
- 3. Send TTS request with text and voice parameters
发送包含文本和语音参数的 TTS 请求
- 4. Receive streaming audio data in binary chunks
以二进制块形式接收流式音频数据
- 5. Save audio file to the results directory
将音频文件保存到结果目录
Available Voices
| Voice | Type | Description |
|---|
| xiaofeng-base | Male | Standard male voice, clear and natural |
| xiaoyan |
Female | Female voice options |
| xiaomei | Female | Alternative female voice |
| Custom voices | Various | Contact UniSound for more options |
Adjustable Parameters
| Parameter | Range | Default | Description |
|---|
| speed | 0-100 | 50 | Speech speed (50 = normal, higher = faster) |
| volume |
0-100 | 50 | Volume level (50 = normal, higher = louder) |
| pitch | 0-100 | 50 | Pitch level (50 = normal, higher = higher) |
| bright | 0-100 | 50 | Brightness/tone (50 = normal) |
Recommended settings:
- - Audiobooks: speed 45, pitch 50
- News/announcements: speed 55, volume 60, bright 60
- Accessibility: speed 35-40, volume 70
- Normal conversation: speed 50, all parameters 50
First-Time Configuration
When credentials are not configured:
The script will show:
CODEBLOCK8
Test Credentials
For testing and evaluation, use these credentials:
用于测试和评估,请使用以下凭据:
CODEBLOCK9
⚠️ Important Security Notice / 重要安全提示
- - Test credentials only — These are for testing and evaluation purposes
- 仅测试凭据——这些凭据仅供测试和评估使用
- - No sensitive data — Never use with production or sensitive content
- 勿用于敏感数据——切勿用于生产或敏感内容
- - Get your own credentials — For production use, contact UniSound
- 获取自己的凭据——生产环境请联系云知声
- - Data privacy — Text is sent to UniSound servers for processing
- 数据隐私——文本将发送至云知声服务器进行处理
Obtaining Production Credentials
For production use, obtain API credentials from UniSound (云知声):
用于生产环境时,请从云知声获取 API 凭据:
- 1. Contact UniSound to obtain your API credentials
联系云知声获取您的 API 凭据
Visit: https://www.unisound.com/
- 2. You will receive:
您将收到:
-
AppKey: Application key / 应用密钥
-
Secret: Secret key for authentication / 认证密钥
Configuration Methods
Method 1: Environment Variables (Recommended)
Linux/macOS:
CODEBLOCK10
Windows (PowerShell):
CODEBLOCK11
Windows (CMD):
CODEBLOCK12
Method 2: .env File (Recommended for Development)
Create a .env file in the project root:
CODEBLOCK13
Then use with python-dotenv or load in your shell.
Security Note: Never commit .env files or actual production credentials to version control.
安全提示:切勿将 .env 文件或实际生产凭据提交到版本控制系统。
Method 3: Command-Line Arguments
CODEBLOCK14
Required Environment Variables
| Variable | Required | Description |
|---|
| INLINECODE21 | Yes | Application key / 应用密钥 |
| INLINECODE22 |
Yes | Secret key / 认证密钥 |
Python API Usage
Basic Python API:
CODEBLOCK15
Error Handling
Authentication failed:
Error: AppKey and Secret are required!
→ Credentials not provided
→ Set UNISOUND
APPKEY and UNISOUNDSECRET environment variables
→ 未提供凭据,请设置环境变量
WebSocket connection error:
WebSocket error: ...
→ Check network connectivity to UniSound API
→ Verify the API endpoint URL is correct
→ Check if firewall is blocking WebSocket connections
→ 检查网络连接和防火墙设置
No audio data received:
Error: No audio data received
→ Text may be empty or contain invalid characters
→ Check the text parameter is not empty
→ Verify text encoding is UTF-8
→ Credentials may be invalid
→ 检查文本内容、编码和凭据
Invalid speech parameter:
Error: speed must be between 0 and 100, got 150
→ Speech parameters must be between 0 and 100
→ 语音参数必须在 0 到 100 之间
WebSocket connection timeout:
WebSocket error: timeout
→ Network connection issue
→ API service may be temporarily unavailable
→ Check internet connection
→ 网络连接问题或服务暂时不可用
Advanced Usage
Custom Speech Parameters
CODEBLOCK21
Batch Text Processing
CODEBLOCK22
Audiobook Chapter Converter
CODEBLOCK23
Accessibility Helper
CODEBLOCK24
Important Notes
- - Chinese language optimized - Best results with Simplified Chinese text
中文优化——简体中文文本效果最佳
- - Requires stable internet connection for WebSocket streaming
需要稳定的网络连接进行 WebSocket 流式传输
- - Audio files saved locally - Check
results/ directory for output
音频文件保存在本地——输出文件在
results/ 目录
- - Text encoding - Ensure text is UTF-8 encoded
文本编码——确保文本为 UTF-8 编码
- - Default sample rate is 24k - Higher quality than standard 16k
默认采样率为 24k——比标准 16k 质量更高
- - Test credentials - Provided for testing and evaluation only
测试凭据——提供的凭据仅供测试和评估使用
Security Best Practices
- - For testing - Use the provided test credentials
测试使用——使用提供的测试凭据
- - For production - Always obtain your own credentials from UniSound
生产环境——始终从云知声获取您自己的凭据
- - Use environment variables - Store credentials securely in environment variables
使用环境变量——安全地将凭据存储在环境变量中
- - Never hardcode credentials - Don't embed production credentials in code
切勿硬编码凭据——不要在代码中嵌入生产凭据
- - Use .env files - For local development (add to .gitignore)
使用 .env 文件——用于本地开发(添加到 .gitignore)
- - Rotate credentials regularly - In production environments
定期轮换凭据——在生产环境中
Troubleshooting
Issue: Script fails with import error
→ Ensure dependencies are installed: pip install websocket-client
→ Ensure using Python 3.6 or later
→ 确保安装依赖并使用 Python 3.6 或更高版本
Issue: "AppKey and Secret are required!" error
→ Set UNISOUNDAPPKEY and UNISOUNDSECRET environment variables
→ Or use --appkey and --secret command-line arguments
→ 设置环境变量或使用命令行参数
Issue: Poor audio quality
→ Try using WAV format with 24k sample rate
→ Adjust speech parameters for your use case
→ 尝试使用 WAV 格式和 24k 采样率
Issue: WebSocket connection timeout
→ Check network connectivity
→ Verify firewall allows WebSocket connections
→ Check if API service is operational
→ 检查网络连接和防火墙设置
Issue: Generated audio sounds unnatural
→ Adjust speed parameter (try 45-55 range)
→ Check text for proper punctuation
→ Consider breaking long sentences into shorter ones
→ 调整语速参数和文本标点
Issue: Test credentials stopped working
→ Test credentials may have expiration or rate limits
→ Contact UniSound to obtain your own credentials
→ 测试凭据可能已过期或达到速率限制
→ 请联系云知声获取您自己的凭据
Tips and Best Practices
- - For audiobooks: Use speed 45, add chapter announcements
有声读物:使用速度 45,添加章节说明
- - For accessibility: Use speed 35-40, higher volume (70)
无障碍应用:使用速度 35-40,更高音量(70)
- - For news: Use speed 55, brighter tone (60)
新闻播报:使用速度 55,更明亮的语调(60)
- - For batch processing: Implement delays between requests
批量处理:在请求之间实现延迟
- - For production: Add error handling and retry logic
生产环境:添加错误处理和重试逻辑
- - For best quality: Use 24k sample rate with WAV format
最佳质量:使用 24k 采样率和 WAV 格式
Reference Documentation
Load these reference documents when:
- - Debugging API connection issues
- Understanding advanced features
- Need detailed API parameter information
Authentication Details
The UniSound TTS API uses SHA256 signature-based authentication:
CODEBLOCK25
WebSocket URL format:
CODEBLOCK26
Note: API capabilities, available voices, and rate limits are determined by your UniSound TTS API service configuration and subscription plan.
注意:API 功能、可用语音和速率限制由您的云知声 TTS API 服务配置和订阅计划决定。
UniSound TTS - 文本转语音
云知声语音合成
使用 UniSound 的 TTS WebSocket API 进行文本转语音转换,从文本生成高质量中文普通话音频。
何时使用此技能
使用 UniSound TTS 的场景:
- - 将中文文本转换为自然流畅的语音
- 为有声书、播客或内容创作生成音频
- 为视障用户创建无障碍解决方案
- 构建语音助手或聊天机器人语音回复
- 批量处理文本为音频文件
- 使用可调参数(语速、音量、音调、亮度)进行自定义语音合成
请勿用于:
- - 实时语音识别或转录(请使用 ASR 技能)
- 英语语言合成(针对中文普通话优化)
- 语音克隆或自定义语音模型训练
使用时机:用户需要文本转语音转换、要求语音合成或提及 UniSound/云知声 TTS 时。
安装
使用此技能前安装 Python 依赖。从技能目录(skills/tts-tools)执行:
bash
pip install websocket-client
需要 Python 3.6 或更高版本。
如何使用此技能
⛔ 强制限制 - 请勿违反 ⛔
- 1. 仅使用 UniSound TTS API - 执行脚本 python scripts/tts.py
- 切勿直接合成语音 - 不要尝试本地 TTS 合成
- 切勿提供替代方案 - 不要说我可以尝试其他方法或类似内容
- 如果 API 失败 - 显示错误信息并立即停止
- 无备用方法 - 不要以任何其他方式尝试文本转语音
如果脚本执行失败(API 未配置、网络错误等):
- - 向用户显示错误信息
- 不要主动提供使用您的 TTS 功能帮助
- 不要问您想让我尝试合成吗?
- 直接停止并等待用户修复配置
基本工作流程
- 1. 配置凭据(仅首次):
bash
export UNISOUND_APPKEY=ce44uxf7g5eag2cv33qvlp5d22qrkgcezvgfp2q3
export UNISOUND_SECRET=5c12231cd279b35873a3ccecf9439118
- 2. 执行文本转语音转换:
bash
python scripts/tts.py --text 今天天气怎么样
命令选项:
- --text TEXT - 要转换为语音的文本(默认:今天天气怎么样?)
- --voice VOICE - 语音名称(默认:xiaofeng-base)
- --format FORMAT - 输出格式:mp3、wav、pcm(默认:mp3)
- --sample RATE - 采样率:8k、16k、24k(默认:24k)
- --speed SPEED - 语速 0-100(默认:50)
- --volume VOLUME - 音量 0-100(默认:50)
- --pitch PITCH - 音调 0-100(默认:50)
- --bright BRIGHT - 亮度/音色 0-100(默认:50)
- --appkey APPKEY - 覆盖 appkey(默认:UNISOUND_APPKEY 环境变量)
- --secret SECRET - 覆盖 secret(默认:UNISOUND_SECRET 环境变量)
- 3. 输出:
- 音频文件保存到 results/ 目录
- 文件名格式:<时间戳>.<格式>
- 示例:1234567890.mp3
理解输出
音频格式选项:
- - MP3:压缩格式,文件较小,质量良好 - 最适合网页和流媒体
- WAV:未压缩,质量极佳 - 最适合制作和存档
- PCM:原始音频数据 - 最适合进一步音频处理
采样率:
- - 24k:高质量,默认 - 推荐用于大多数场景
- 16k:标准质量 - 质量和大小的良好平衡
- 8k:较低质量,文件较小 - 适用于电话系统
使用示例
示例 1:使用测试凭据快速开始
bash
设置测试凭据
export UNISOUND_APPKEY=ce44uxf7g5eag2cv33qvlp5d22qrkgcezvgfp2q3
export UNISOUND_SECRET=5c12231cd279b35873a3ccecf9439118
将文本转换为语音
python scripts/tts.py --text 你好世界
输出:results/1234567890.mp3
示例 2:自定义语音和格式
bash
python scripts/tts.py --text 今天天气怎么样 --voice xiaofeng-base --format wav
输出:高质量 WAV 文件,男声
示例 3:调整语音参数
bash
python scripts/tts.py --text 快速朗读 --speed 70 --volume 60 --pitch 50
输出:语速加快,音量提高
示例 4:高质量音频制作
bash
python scripts/tts.py --text 高质量音频 --format wav --sample 24k --volume 60
输出:24kHz 制作级 WAV 文件
示例 5:命令行凭据覆盖
bash
python scripts/tts.py \
--text 测试 \
--appkey ce44uxf7g5eag2cv33qvlp5d22qrkgcezvgfp2q3 \
--secret 5c12231cd279b35873a3ccecf9439118
工作原理
该脚本使用 UniSound TTS WebSocket API,工作流程如下:
- 1. 身份验证 - 使用 SHA256 签名(appkey + 时间戳 + secret)
- 建立 WebSocket 连接 - 连接到 wss://ws-stts.hivoice.cn/v1/tts
- 发送 TTS 请求 - 包含文本和语音参数
- 接收流式音频数据 - 以二进制块形式接收
- 保存音频文件 - 保存到结果目录
可用语音
| 语音 | 类型 | 描述 |
|---|
| xiaofeng-base | 男声 | 标准男声,清晰自然 |
| xiaoyan |
女声 | 女声选项 |
| xiaomei | 女声 | 替代女声 |
| 自定义语音 | 多种 | 联系云知声获取更多选项 |
可调参数
| 参数 | 范围 | 默认值 | 描述 |
|---|
| speed | 0-100 | 50 | 语速(50 = 正常,越高越快) |
| volume |
0-100 | 50 | 音量(50 = 正常,越高越大) |
| pitch | 0-100 | 50 | 音调(50 = 正常,越高越尖) |
| bright | 0-100 | 50 | 亮度/音色(50 = 正常) |
推荐设置:
- - 有声书:speed 45,pitch 50
- 新闻/公告:speed 55,volume 60,bright 60
- 无障碍:speed 35-40,volume 70
- 正常对话:speed 50,所有参数 50
首次配置
当凭据未配置时:
脚本将显示:
Error: AppKey and Secret are required!
Set them via --appkey/--secret arguments or UNISOUNDAPPKEY/UNISOUNDSECRET environment variables.
测试凭据
用于测试和评估,请使用以下凭据:
bash
export UNISOUND_APPKEY=ce44uxf7g5eag2cv33qvlp5d22qrkgcezvgfp2q3
export UNISOUND_SECRET=5c12231cd279b35873a3ccecf9439118
⚠️ 重要安全提示
- - 仅测试凭据——这些凭据仅供测试和评估使用
- 勿用于敏感数据——切勿用于生产或敏感内容
- 获取自己的凭据——生产环境请联系云知声
- 数据隐私——文本将发送至云知声服务器进行处理
获取生产凭据
用于生产环境时,请从云知声获取 API 凭据:
- 1. 联系云知声获取您的 API 凭据
访问:https://www.unisound.com/
- 2. 您将收到:
-
AppKey:应用密钥
-
Secret