Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -9,28 +9,32 @@ prompt = "Type and press Enter"
|
|
9 |
|
10 |
|
11 |
def record_text(audio_file):
|
12 |
-
|
|
|
|
|
|
|
|
|
13 |
|
14 |
-
sound = audio_file
|
15 |
-
sound_type = sound.split(".")
|
16 |
-
if sound_type[-1] == 'mp3':
|
17 |
-
|
18 |
-
|
19 |
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
|
25 |
-
MyText = ""
|
26 |
-
with sr.AudioFile(sound) as source:
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
|
31 |
-
|
32 |
-
|
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):
|