Qwen3-ASR / examples /quickstart.py
changh95's picture
tt-model push qwen3-asr (container)
d9f9acd verified
Raw History Blame Contribute Delete
964 Bytes
# SPDX-License-Identifier: Apache-2.0
"""Transcribe a file with a running Qwen3-ASR server (tt serve changh95/Qwen3-ASR), standard library only:
python examples/quickstart.py sample.wav [http://localhost:20000]"""
import json
import sys
import urllib.request
import uuid
path = sys.argv[1]
url = (sys.argv[2] if len(sys.argv) > 2 else "http://localhost:20000").rstrip("/") + "/v1/audio/transcriptions"
b = uuid.uuid4().hex
body = (f"--{b}\r\nContent-Disposition: form-data; name=\"response_format\"\r\n\r\nverbose_json\r\n"
f"--{b}\r\nContent-Disposition: form-data; name=\"file\"; filename=\"audio\"\r\n\r\n").encode() \
+ open(path, "rb").read() + f"\r\n--{b}--\r\n".encode()
req = urllib.request.Request(url, data=body, headers={"Content-Type": f"multipart/form-data; boundary={b}"})
r = json.load(urllib.request.urlopen(req))
print(r["language"], r["text"])
for s in r["segments"]:
print(f"{s['start']:8.2f} {s['end']:8.2f} {s['text']}")