Vihang28 commited on
Commit
fcabb84
1 Parent(s): 6145d6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -18
app.py CHANGED
@@ -9,28 +9,32 @@ prompt = "Type and press Enter"
9
 
10
 
11
  def record_text(audio_file):
12
- r = sr.Recognizer()
 
 
 
 
13
 
14
- sound = audio_file
15
- sound_type = sound.split(".")
16
- if sound_type[-1] == 'mp3':
17
- input_file = sound
18
- output_file = "con_sound.wav"
19
 
20
- # convert mp3 file to wav file
21
- sound = AudioSegment.from_mp3(input_file)
22
- sound.export(output_file, format="wav")
23
- sound = "con_sound.wav"
24
 
25
- MyText = ""
26
- with sr.AudioFile(sound) as source:
27
- r.adjust_for_ambient_noise(source)
28
- print("Converting audio file to text..")
29
- audio2 = r.record(source, duration=None) # Use record instead of listen
30
 
31
- MyText = r.recognize_google(audio2, language="en-US", key=None, show_all=False)
32
- MyText = MyText.lower()
33
- return (MyText)
34
 
35
 
36
  def api_calling(audio_file, prompt, api_key):
 
9
 
10
 
11
  def record_text(audio_file):
12
+ audio_file = open(audio_file, "rb")
13
+ transcript = openai.Audio.transcribe("whisper-1", audio_file)
14
+ text = transcript['text']
15
+ return text
16
+ # r = sr.Recognizer()
17
 
18
+ # sound = audio_file
19
+ # sound_type = sound.split(".")
20
+ # if sound_type[-1] == 'mp3':
21
+ # input_file = sound
22
+ # output_file = "con_sound.wav"
23
 
24
+ # # convert mp3 file to wav file
25
+ # sound = AudioSegment.from_mp3(input_file)
26
+ # sound.export(output_file, format="wav")
27
+ # sound = "con_sound.wav"
28
 
29
+ # MyText = ""
30
+ # with sr.AudioFile(sound) as source:
31
+ # r.adjust_for_ambient_noise(source)
32
+ # print("Converting audio file to text..")
33
+ # audio2 = r.record(source, duration=None) # Use record instead of listen
34
 
35
+ # MyText = r.recognize_google(audio2, language="en-US", key=None, show_all=False)
36
+ # MyText = MyText.lower()
37
+ # return (MyText)
38
 
39
 
40
  def api_calling(audio_file, prompt, api_key):