Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -25,22 +25,35 @@ asr_model = nemo_asr.models.EncDecHybridRNNTCTCBPEModel.from_pretrained(
|
|
25 |
)
|
26 |
|
27 |
|
28 |
-
def transcribe_audio(audio_file):
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
|
38 |
-
|
39 |
-
|
40 |
|
41 |
-
|
42 |
-
|
43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
# Return the transcription result
|
45 |
return res[0][0]
|
46 |
|
|
|
25 |
)
|
26 |
|
27 |
|
28 |
+
# def transcribe_audio(audio_file):
|
29 |
+
# if audio_file:
|
30 |
+
# # Convert the uploaded audio to mono
|
31 |
+
# mono_audio = convert_to_mono(audio_file)
|
32 |
|
33 |
+
# # Write the mono audio to a temporary file and close it before transcribing
|
34 |
+
# with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_file:
|
35 |
+
# temp_file.write(mono_audio.read())
|
36 |
+
# temp_file_path = temp_file.name
|
37 |
|
38 |
+
# # Transcribe the audio using the temporary file path
|
39 |
+
# res = asr_model.transcribe([temp_file_path])
|
40 |
|
41 |
+
# # Clean up the temporary file
|
42 |
+
# os.remove(temp_file_path)
|
43 |
|
44 |
+
# # Return the transcription result
|
45 |
+
# return res[0][0]
|
46 |
+
def transcribe_audio(audio_file):
|
47 |
+
if audio_file:
|
48 |
+
# Convert the uploaded audio to mono
|
49 |
+
mono_audio = convert_to_mono(audio_file)
|
50 |
+
|
51 |
+
# Transcribe the audio using the BytesIO object directly
|
52 |
+
audio_data = mono_audio.read()
|
53 |
+
|
54 |
+
# Use the audio_data in the format expected by the ASR model
|
55 |
+
res = asr_model.transcribe([BytesIO(audio_data)])
|
56 |
+
|
57 |
# Return the transcription result
|
58 |
return res[0][0]
|
59 |
|