Transcribe recorded audio files to text via UniSound UniCloud ASR API, supporting multiple formats and optimized for finance and customer service domains.
python3 {baseDir}/scripts/transcribe.py audio.wav --out result.txt
python3 {baseDir}/scripts/transcribe.py audio.wav --json --out result.json
python3 {baseDir}/scripts/transcribe.py audio.mp3 --format mp3
python3 {baseDir}/scripts/transcribe.py audio.wav --domain finance
How it works
------------
The script uses the UniCloud ASR API with the following workflow:
1. **Initialize upload** — Get a task ID from the API / 初始化上传,获取任务ID
2. **Upload audio file** — Upload the audio file to the server / 上传音频文件到服务器
3. **Start transcription** — Submit the transcription task / 提交转写任务
4. **Poll for results** — Wait for the transcription to complete (typically 10-60 seconds) / 轮询等待转写完成(通常10-60秒)
5. **Return transcript** — Output the recognized text / 输出识别文本
> **Privacy**: Audio files are uploaded directly to UniCloud servers. No data is sent to third-party services.
>
> **隐私说明**:音频文件直接上传到云知声服务器。不会将数据发送到第三方服务。
Dependencies
------------
- Python 3.8+
- `requests`: `pip install requests`
Pre-installation Considerations / 安装前需要考虑的事项
--------------------------------------------------------
**Important Notes Before Using This Skill / 使用前重要说明**
**(1) Required Environment Variables / 必需的环境变量**
This skill requires the following environment variables to be configured:
此技能需要配置以下环境变量:
- `UNISOUND_APPKEY` (Required / 必填)
- `UNISOUND_SECRET` (Required / 必填)
- `UNISOUND_USERID` (Optional, defaults to `unisound-python-demo`)
**(2) Test Credentials Usage / 测试凭据使用**
This skill includes UAT test credentials for evaluation purposes:
此技能包含用于评估目的的 UAT 测试凭据:
- **For testing only** — Use only with non-sensitive audio files
- **仅供测试** — 仅用于非敏感音频文件
- **UAT environment** — Not for production use
- **UAT 环境** — 不适用于生产环境
- **Obtain production credentials** — Contact UniCloud for production API access
- **获取生产凭据** — 联系云知声获取生产环境 API 访问权限
**(3) Security Best Practices / 安全最佳实践**
- **Use environment variables** — Never embed production credentials in scripts or configuration files
- **使用环境变量** — 切勿在脚本或配置文件中嵌入生产凭据
- **Review the script** — Check `scripts/transcribe.py` to understand network endpoints
- **审查脚本** — 检查 `scripts/transcribe.py` 以了解网络端点
- **Privacy awareness** — Audio files are uploaded to UniSound servers; review their privacy policy
- **隐私意识** — 音频文件会上传到云知声服务器;请查看其隐私政策
**(4) Production Deployment / 生产部署**
For production use:
用于生产环境时:
- Obtain your own API credentials from UniCloud / 云知声
- Set environment variables in your deployment configuration / 在部署配置中设置环境变量
- Review and confirm privacy terms with UniCloud / 与云知声审查并确认隐私条款
- Test with non-sensitive data first / 首先使用非敏感数据进行测试
Credentials (Required)
-----------
**You MUST configure API credentials via environment variables before running the script.**
**必须通过环境变量配置 API 凭据才能运行脚本。**
### Obtaining Credentials / 获取凭据
To use this skill, you need to obtain API credentials from UniCloud (云知声):
使用此技能前,您需要从云知声获取 API 凭据:
1. Contact UniCloud to obtain your API credentials
联系云知声获取您的 API 凭据
2. You will receive:
您将收到:
- **AppKey**: Application key / 应用密钥
- **Secret**: Secret key for authentication / 认证密钥
- **UserId**: Your user identifier / 用户标识
- **Base URL**: API endpoint URL / API 端点地址
### Test Credentials (UAT Environment) / 测试凭据(UAT 环境)
For testing and evaluation, you can use the following UAT environment credentials:
用于测试和评估,您可以使用以下 UAT 环境凭据:
```yaml
AppKey: 681e01d78d8a40e8928bc8268020639b
Secret: d7b2980cb61843d69fdab5e99deafcdf
UserId: unisound-python-demo
Base URL: http://af-asr.uat.hivoice.cn
⚠️ Important Security Notice / 重要安全提示
- Test environment only — These credentials are for UAT testing only
- 仅测试环境 — 这些凭据仅用于 UAT 测试
- No sensitive data — Never use with production or sensitive audio files
- 勿用于敏感数据 — 切勿用于生产或敏感音频文件
- Get your own credentials — For production use, contact UniCloud
- 获取自己的凭据 — 生产环境请联系云知声
- Data privacy — Audio files are uploaded to UniSound servers
- 数据隐私 — 音频文件将上传至云知声服务器
Linux/macOS:
# Using test credentials / 使用测试凭据
export UNISOUND_APPKEY="681e01d78d8a40e8928bc8268020639b"
export UNISOUND_SECRET="d7b2980cb61843d69fdab5e99deafcdf"
export UNISOUND_USERID="unisound-python-demo"
Windows (CMD):
REM Using test credentials / 使用测试凭据
set UNISOUND_APPKEY=681e01d78d8a40e8928bc8268020639b
set UNISOUND_SECRET=d7b2980cb61843d69fdab5e99deafcdf
set UNISOUND_USERID=unisound-python-demo
Windows (PowerShell):
# Using test credentials / 使用测试凭据
$env:UNISOUND_APPKEY="681e01d78d8a40e8928bc8268020639b"
$env:UNISOUND_SECRET="d7b2980cb61843d69fdab5e99deafcdf"
$env:UNISOUND_USERID="unisound-python-demo"
Using .env file (Recommended):
Create a .env file in the project root:
创建 .env 文件:
# Test credentials (UAT) / 测试凭据
UNISOUND_APPKEY=681e01d78d8a40e8928bc8268020639b
UNISOUND_SECRET=d7b2980cb61843d69fdab5e99deafcdf
UNISOUND_USERID=unisound-python-demo
Security Note: Never commit
.envfiles or actual credentials to version control.安全提示:切勿将
.env文件或实际凭据提交到版本控制系统。
| Variable | Required | Description | 说明 |
|---|---|---|---|
UNISOUND_APPKEY | Yes | Application key / 应用密钥 | Required / 必填 |
UNISOUND_SECRET | Yes | Secret key / 认证密钥 | Required / 必填 |
UNISOUND_USERID | No | User identifier / 用户标识 | Default: unisound-python-demo |
UNISOUND_BASE_URL | No | API base URL / API 基础地址 | Default: http://af-asr.uat.hivoice.cn |
UNISOUND_DOMAIN | No | Recognition domain / 识别领域 | Default: other (config default: finance) |
UNISOUND_AUDIOTYPE | No | Default audio format / 默认音频格式 | Default: wav |
UNISOUND_USE_HOT_DATA | No | Enable hotword recognition / 启用热词识别 | Default: true |
WAV, MP3, M4A, FLAC, OGG — up to 2 hours, 100MB max.
支持格式:WAV、MP3、M4A、FLAC、OGG——最长 2 小时,最大 100MB。
Use the --format flag to specify the format if auto-detection fails:
如果自动检测失败,使用 --format 参数指定格式:
python3 {baseDir}/scripts/transcribe.py audio.mp3 --format mp3
Error: API returned error: [error_code] message
Cause: Invalid credentials, wrong parameters, or server-side error. 凭据无效、参数错误或服务器错误。
Solution: Verify your credentials are correct. Check that: 验证凭据是否正确。检查:
Error: 错误: 音频文件不存在
Cause: The specified audio file does not exist. 指定的音频文件不存在。
Solution: Check the file path: 检查文件路径:
# Use absolute path to be safe / 使用绝对路径更安全
python3 {baseDir}/scripts/transcribe.py /full/path/to/audio.wav
Error: 转写超时
Cause: Transcription is taking longer than expected (server may be busy). 转写时间过长(服务器可能繁忙)。
Solution:
Error: Unsupported audio format
Cause: The audio format is not supported by the API. API 不支持该音频格式。
Solution:
--format flag to explicitly specify the format / 使用 --format 参数显式指定格式# Convert using ffmpeg / 使用 ffmpeg 转换
ffmpeg -i input.mp3 -ar 16000 -ac 1 output.wav
Issue: Cannot connect to API server
无法连接到 API 服务器
Cause: Network connectivity issues or incorrect API endpoint URL. 网络连接问题或 API 端点 URL 不正确。
Solution:
Getting Help / 获取帮助
If you encounter issues not covered here: 如果遇到未涵盖的问题:
Check the UniCloud ASR documentation for the latest API changes 查看云知声 ASR 文档了解最新的 API 变更
Verify your network connection to the API server 验证到 API 服务器的网络连接
Check the error message details for specific error codes 检查错误消息详情以获取特定错误代码
Ensure you're using Python 3.8 or later 确保使用 Python 3.8 或更高版本
# Check Python version / 检查 Python 版本
python3 --version
ZIP package — ready to use