diff --git a/dsLightRag/Config/__pycache__/Config.cpython-310.pyc b/dsLightRag/Config/__pycache__/Config.cpython-310.pyc index b834a481..12da3d79 100644 Binary files a/dsLightRag/Config/__pycache__/Config.cpython-310.pyc and b/dsLightRag/Config/__pycache__/Config.cpython-310.pyc differ diff --git a/dsLightRag/Test/tts_http_demo.py b/dsLightRag/Test/tts_http_demo.py index 6eaba7a2..990fb60b 100644 --- a/dsLightRag/Test/tts_http_demo.py +++ b/dsLightRag/Test/tts_http_demo.py @@ -50,11 +50,37 @@ request_json = { if __name__ == '__main__': try: - resp = requests.post(api_url, json.dumps(request_json), headers=header) - print(f"resp body: \n{resp.json()}") - if "data" in resp.json(): - data = resp.json()["data"] - file_to_save = open("test_submit.mp3", "wb") - file_to_save.write(base64.b64decode(data)) + resp = requests.post(api_url, json=request_json, headers=header) + print(f"resp body: {resp.json()}") + + # 检查响应状态 + if resp.status_code == 200: + resp_data = resp.json() + if resp_data.get("code") == 3000 and "data" in resp_data: + data = resp_data["data"] + + # 检查data是否为空 + if data: + try: + # 解码Base64数据 + audio_data = base64.b64decode(data) + + # 保存为MP3文件 + output_file = "test_tts_output.mp3" + with open(output_file, "wb") as f: + f.write(audio_data) + print(f"音频文件已成功保存为: {output_file}") + except Exception as decode_error: + print(f"Base64解码或文件保存失败: {str(decode_error)}") + # 打印数据前100个字符,以便调试 + print(f"数据前100个字符: {data[:100]}") + else: + print("错误: 返回的data字段为空") + else: + print(f"API返回错误: code={resp_data.get('code')}, message={resp_data.get('message')}") + else: + print(f"HTTP请求失败: 状态码={resp.status_code}") except Exception as e: - e.with_traceback() + print(f"发生异常: {str(e)}") + import traceback + traceback.print_exc()