Download examples/quickstart.py from changh95/Qwen3-ASR: direct link, hf CLI and curl.
- Browser
- Download file 964 Bytes
-
https://huggingface.co/changh95/Qwen3-ASR/resolve/main/examples/quickstart.py
- Command line
-
hf download hf://changh95/Qwen3-ASR/examples/quickstart.py
-
curl -L -o quickstart.py https://huggingface.co/changh95/Qwen3-ASR/resolve/main/examples/quickstart.py
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']}") | |