本技能包提供基于腾讯云语音合成服务的文本转语音功能,专注于基础单次合成需求。
在使用本技能前,请确保:
将腾讯云API密钥配置为环境变量:
export TENCENTCLOUD_SECRET_ID="your-secret-id"
export TENCENTCLOUD_SECRET_KEY="your-secret-key"
| 参数名 | 类型 | 必填 | 默认值 | 说明 |
|---|---|---|---|---|
| ------- | ------ | ------ | -------- | ------ |
| text | string | 是 | - | 要转换为语音的文本内容 |
| voice_type | int | 否 | 101001 | 语音类型(101001-101015) |
| codec | string | 否 | mp3 | 音频编码格式(mp3/wav) |
| output_file | string | 否 | output.mp3 | 输出音频文件名 |
# 使用默认参数合成语音
from tencent_tts import TextToSpeech
tts = TextToSpeech()
result = tts.synthesize("欢迎使用腾讯云语音合成服务")
print(f"音频文件已生成: {result['output_file']}")
# 使用自定义参数
from tencent_tts import TextToSpeech
tts = TextToSpeech()
result = tts.synthesize(
text="这是一个自定义语音合成的示例",
voice_type=101002,
codec="wav",
output_file="custom_voice.wav"
)
print(f"音频文件已生成: {result['output_file']}")
tencent-tts/
├── SKILL.md (本文件)
├── scripts/
│ └── tencent_tts.py (主功能脚本)
└── examples/
└── basic_usage.py (基础使用示例)
如遇问题,请参考:
共 1 个版本