File size: 943 Bytes
ca02ffa |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
import requests
def transcribe_audio(
server_url: str,
wav_path: str,
model_type: str = "tiny",
model_path: str = "../models/models-ax650",
language: str = "zh",
task: str = "transcribe"
):
url = f"{server_url.rstrip('/')}/asr"
files = {
"wav": open(wav_path, "rb"),
}
data = {
"model_type": model_type,
"model_path": model_path,
"language": language,
"task": task,
}
print(f"Sending request to: {url}")
response = requests.post(url, files=files, data=data)
if response.status_code != 200:
print("❌ Error:", response.text)
return None
result = response.json()
print("服务器返回结果:")
print(result)
return result
if __name__ == "__main__":
# 你的服务器地址
SERVER = "http://127.0.0.1:8000"
# 本地 wav 文件路径
WAV = "../demo.wav"
transcribe_audio(SERVER, WAV)
|