python调用阿里cosyvoice api实现音色自定义tts长文配音并删除音色代码
代码语言:python
所属分类:其他
代码描述:python调用阿里cosyvoice api实现音色自定义tts长文配音并删除音色代码
代码标签: python 调用 阿里 cosyvoice api 音色 自定义 tts 长文 配音 删除 音色
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
import os
import asyncio
import httpx
import base64
import logging
# 配置日志格式
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(levelname)s - %(message)s'
)
# ==========================================
# 1. 生成定制音色
# ==========================================
async def dashscope_create_voice(
voice_prompt: str,
preview_text: str,
api_key: str,
http_client: httpx.AsyncClient,
target_model: str = "cosyvoice-v3.5-plus", # 增加 target_model 参数
prefix: str = "announcer",
sample_rate: int = 24000,
response_format: str = "wav"
) -> tuple:
"""
调用 voice-enrollment 定制音色,返回元组 (voice_id, audio_bytes, response_format)
"""
url = "https://dashscope.aliyuncs.com/api/v1/services/audio/tts/customization"
headers = {
"Authorization": f"Bearer {api_key}",
"Content-Type": &quo.........完整代码请登录后点击上方下载按钮下载查看














网友评论0