Vihang28 commited on
Commit
bb456ac
1 Parent(s): 6f281cd

Update app.py

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