Ntabukiraniro commited on
Commit
3ef5d7a
1 Parent(s): 9f7e57b

Upload 2 files

Browse files
Files changed (1) hide show
  1. openai_whisper.py +22 -0
openai_whisper.py ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import openai
2
+ import os
3
+ openai.api_key = os.getenv("OPENAI_API_KEY")
4
+ import wave
5
+
6
+ class Config:
7
+ channels = 2
8
+ sample_width = 2
9
+ sample_rate = 44100
10
+
11
+ def save_wav_file(file_path, wav_bytes):
12
+ with wave.open(file_path, 'wb') as wav_file:
13
+ wav_file.setnchannels(Config.channels)
14
+ wav_file.setsampwidth(Config.sample_width)
15
+ wav_file.setframerate(Config.sample_rate)
16
+ wav_file.writeframes(wav_bytes)
17
+
18
+ def transcribe(file_path):
19
+ audio_file = open(file_path, 'rb')
20
+ transcription = openai.Audio.transcribe("whisper-1", audio_file)
21
+ return transcription['text']
22
+