-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathoutput_transcription.py
executable file
·41 lines (31 loc) · 1.07 KB
/
output_transcription.py
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
import requests
import sys
def curl_transcribe_audio(file_path):
# Define the endpoint and your API key
url = "https://api.openai.com/v1/audio/transcriptions"
api_key = "YOUR_KEY_HERE"
# Setup headers
headers = {
"Authorization": f"Bearer {api_key}",
}
# Open the file and setup files and data to be sent
with open(file_path, "rb") as file:
files = {
"file": file,
}
data = {
"model": "whisper-1",
"prompt": "Transcribe the radio dispatch audio. The speaker is usually a dispatcher, police officer, or EMS responder. There are often callsigns, ten-codes, and addresses said.",
"response_format": "json",
"temperature": "0",
"language": "en",
}
# Make the POST request
response = requests.post(url, headers=headers, files=files, data=data)
# Print the response or handle as needed
return str(response.json())
def main():
file = sys.argv[1]
print(curl_transcribe_audio(file))
if __name__ == "__main__":
main()