Update app.py
Browse files
app.py
CHANGED
@@ -28,10 +28,12 @@ def trim_audio(input_audio, input_text):
|
|
28 |
with open(temp_audio_path, "wb") as audio_file:
|
29 |
audio_file.write(input_audio.read())
|
30 |
|
|
|
|
|
|
|
31 |
# Load the audio file and recognize text
|
32 |
-
recognizer = sr.Recognizer()
|
33 |
with sr.AudioFile(temp_audio_path) as source:
|
34 |
-
audio = recognizer.record(source
|
35 |
audio_text = recognizer.recognize_google(audio, language="ar-AE")
|
36 |
|
37 |
# Process the audio and create a trimmed audio
|
@@ -41,9 +43,9 @@ def trim_audio(input_audio, input_text):
|
|
41 |
|
42 |
for word in audio_text.split():
|
43 |
if word in text_to_match:
|
44 |
-
trimmed_audio += AudioSegment.from_file(temp_audio_path, format="wav")
|
45 |
|
46 |
-
st.audio(trimmed_audio.export(format="wav"), format="audio/wav")
|
47 |
|
48 |
finally:
|
49 |
temp_dir.cleanup()
|
|
|
28 |
with open(temp_audio_path, "wb") as audio_file:
|
29 |
audio_file.write(input_audio.read())
|
30 |
|
31 |
+
# Initialize the recognizer with the Arabic language
|
32 |
+
recognizer = sr.Recognizer(language="ar-AE")
|
33 |
+
|
34 |
# Load the audio file and recognize text
|
|
|
35 |
with sr.AudioFile(temp_audio_path) as source:
|
36 |
+
audio = recognizer.record(source)
|
37 |
audio_text = recognizer.recognize_google(audio, language="ar-AE")
|
38 |
|
39 |
# Process the audio and create a trimmed audio
|
|
|
43 |
|
44 |
for word in audio_text.split():
|
45 |
if word in text_to_match:
|
46 |
+
trimmed_audio += AudioSegment.from_file(temp_audio_path, format="wav")
|
47 |
|
48 |
+
st.audio(trimmed_audio.export(format="wav"), format="audio/wav")
|
49 |
|
50 |
finally:
|
51 |
temp_dir.cleanup()
|