-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.py
More file actions
46 lines (36 loc) · 1.28 KB
/
Copy pathclient.py
File metadata and controls
46 lines (36 loc) · 1.28 KB
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
"""Minimal client that hits the deployed VibeVoice-ASR web endpoint.
Usage:
uv run python client.py <audio_file> [endpoint_url]
Find the endpoint URL in the `modal deploy` output (the `/web` URL of
the `VibeVoiceASR` class).
"""
from __future__ import annotations
import sys
import urllib.request
from pathlib import Path
def transcribe(audio_path: str, endpoint_url: str) -> None:
boundary = "----modalvibevoiceboundary"
audio_bytes = Path(audio_path).read_bytes()
filename = Path(audio_path).name
body = (
(
f"--{boundary}\r\n"
f'Content-Disposition: form-data; name="audio"; filename="{filename}"\r\n'
"Content-Type: application/octet-stream\r\n\r\n"
).encode()
+ audio_bytes
+ f"\r\n--{boundary}--\r\n".encode()
)
req = urllib.request.Request(
endpoint_url.rstrip("/") + "/transcribe",
data=body,
headers={"Content-Type": f"multipart/form-data; boundary={boundary}"},
method="POST",
)
with urllib.request.urlopen(req, timeout=3600) as resp:
print(resp.read().decode())
if __name__ == "__main__":
if len(sys.argv) < 3:
print("usage: python client.py <audio_file> <endpoint_url>")
sys.exit(1)
transcribe(sys.argv[1], sys.argv[2])