debug1
This commit is contained in:
parent
cfacbe10bb
commit
d227e3d15c
@ -139,56 +139,52 @@ class CosyVoiceService:
|
||||
logger.info(f"开始语音克隆: 文本='{text[:20]}...', 参考音频={reference_audio_path}")
|
||||
|
||||
# 构建请求数据
|
||||
request_data = {
|
||||
"text": text,
|
||||
"reference_audio": reference_audio_path,
|
||||
"reference_text": reference_text,
|
||||
"seed": seed
|
||||
}
|
||||
|
||||
logger.info(f"=== 发送给CosyVoice API的数据 ===")
|
||||
logger.info(f"API URL: {self.api_url}/generate/clone")
|
||||
logger.info(f"Request Data: {request_data}")
|
||||
|
||||
# 发送克隆请求
|
||||
response = requests.post(
|
||||
f"{self.api_url}/generate/clone",
|
||||
json=request_data,
|
||||
timeout=60 # 克隆需要更长时间
|
||||
)
|
||||
|
||||
logger.info(f"=== CosyVoice API响应 ===")
|
||||
logger.info(f"Status Code: {response.status_code}")
|
||||
logger.info(f"Response Headers: {dict(response.headers)}")
|
||||
if response.status_code != 200:
|
||||
logger.error(f"Response Text: {response.text}")
|
||||
request_data = {
|
||||
"text": text,
|
||||
"reference_audio": reference_audio_path,
|
||||
"reference_text": reference_text,
|
||||
"seed": seed
|
||||
}
|
||||
|
||||
if response.status_code == 200:
|
||||
result = response.json()
|
||||
if result.get('success'):
|
||||
# 直接从响应中获取音频数据
|
||||
audio_data = result.get('audio_data')
|
||||
if audio_data:
|
||||
local_path = self._save_audio_data(audio_data, 'clone')
|
||||
if local_path:
|
||||
logger.info(f"语音克隆成功: {local_path}")
|
||||
return local_path, local_path
|
||||
else:
|
||||
return None, None
|
||||
logger.info(f"=== 发送给CosyVoice API的数据 ===")
|
||||
logger.info(f"API URL: {self.api_url}/generate/clone")
|
||||
logger.info(f"Request Data: {request_data}")
|
||||
|
||||
# 发送克隆请求
|
||||
response = requests.post(
|
||||
f"{self.api_url}/generate/clone",
|
||||
json=request_data,
|
||||
timeout=60 # 克隆需要更长时间
|
||||
)
|
||||
|
||||
logger.info(f"=== CosyVoice API响应 ===")
|
||||
logger.info(f"Status Code: {response.status_code}")
|
||||
logger.info(f"Response Headers: {dict(response.headers)}")
|
||||
if response.status_code != 200:
|
||||
logger.error(f"Response Text: {response.text}")
|
||||
return None, None
|
||||
|
||||
result = response.json()
|
||||
if result.get('success'):
|
||||
# 直接从响应中获取音频数据
|
||||
audio_data = result.get('audio_data')
|
||||
if audio_data:
|
||||
local_path = self._save_audio_data(audio_data, 'clone')
|
||||
if local_path:
|
||||
logger.info(f"语音克隆成功: {local_path}")
|
||||
return local_path, local_path
|
||||
else:
|
||||
logger.error("响应中没有音频数据")
|
||||
return None, None
|
||||
else:
|
||||
logger.error(f"语音克隆失败: {result.get('message')}")
|
||||
logger.error("响应中没有音频数据")
|
||||
return None, None
|
||||
else:
|
||||
logger.error(f"API请求失败: HTTP {response.status_code}")
|
||||
logger.error(f"语音克隆失败: {result.get('message')}")
|
||||
return None, None
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"语音克隆失败: {str(e)}")
|
||||
return None, None
|
||||
|
||||
def generate_speech_with_natural_control(
|
||||
self,
|
||||
text: str,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user