-
Notifications
You must be signed in to change notification settings - Fork 544
Expand file tree
/
Copy pathclient_openai.py
More file actions
38 lines (32 loc) · 1.23 KB
/
client_openai.py
File metadata and controls
38 lines (32 loc) · 1.23 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
import sys
import requests
if len(sys.argv) < 2:
print("Usage: python transcribe_file.py <path_to_audio_file>")
sys.exit(1)
audio_file = sys.argv[1]
# Configuration
host = "localhost"
port = 8000 # Default REST port; change if you used --rest_port
url = f"http://{host}:{port}/v1/audio/transcriptions"
model = "small" # Or "whisper-1" (mapped to small internally)
language = "en" # Or "hi" for Hindi
response_format = "json" # Options: "json", "text", "verbose_json", "srt", "vtt"
# Prepare the request
files = {"file": open(audio_file, "rb")}
data = {
"model": model,
"language": language,
"response_format": response_format,
# Optional: Add "prompt" for style guidance, "temperature" (0-1), etc.
}
# Send the request
response = requests.post(url, files=files, data=data)
if response.status_code == 200:
if response_format == "json" or response_format == "verbose_json":
result = response.json()
print("Transcript:", result.get("text", "No text found"))
# If you need translation, post-process here (e.g., using another API like Google Translate)
else:
print("Transcript:", response.text)
else:
print("Error:", response.status_code, response.json().get("error", "Unknown error"))