import requests import json import os url = "http://127.0.0.1:8969/inference" # 音频文件路径,根据 readme.txt #L23,这里以 60s.wav 为例 # 使用相对路径 script_dir = os.path.dirname(os.path.abspath(__file__)) audio_file = os.path.join(script_dir, "KotobaASRLLM_Cuda130", "60s.wav") if not os.path.exists(audio_file): print(f"找不到音频文件: {audio_file}") exit(1) # 构建 multipart/form-data 数据 # 使用 language = ja,对应 -l ja # response_format 设为 json,对应 --output-json data = { "temperature": "0.0", "language": "ja", "response_format": "json" } print(f"正在发送请求到 {url}...") print(f"音频文件: {audio_file}") with open(audio_file, "rb") as f: files = {"file": (os.path.basename(audio_file), f, "audio/wav")} try: response = requests.post(url, data=data, files=files) response.raise_for_status() # 尝试解析返回的 JSON 数据 result = response.json() print("\n识别结果 (JSON格式):") print(json.dumps(result, indent=2, ensure_ascii=False)) except requests.exceptions.RequestException as e: print(f"\n请求失败: {e}") if e.response is not None: print(f"服务器返回内容: {e.response.text}")