forked from samx81/modelz-whisper
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient.py
More file actions
39 lines (32 loc) · 1.06 KB
/
Copy pathclient.py
File metadata and controls
39 lines (32 loc) · 1.06 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
from http import HTTPStatus
import requests
import msgpack # type: ignore
import json
def main():
url = "http://localhost:8000/inference"
sample = "./example/Something_good_just_happened.wav"
print(sample)
with open(sample, "rb") as f:
binary = f.read()
req = {
"binary": binary,
"id": "1",
"prompt_words": "Something good just happened",
"prompt_phones": "Something good just happened",
"do_g2p": True
}
resp = requests.post(url, data=msgpack.packb(req))
if resp.status_code == HTTPStatus.OK:
# Decode the response content and parse it as JSON
response_json = json.loads(resp.content.decode("utf-8"))
# Extract the "transcript" field
print(response_json)
transcript = response_json.get("Transcript", None)
if transcript:
print("Transcript:", transcript)
else:
print("Transcript field not found in the response.")
else:
print(resp.status_code, resp.text)
if __name__ == "__main__":
main()