Update app.py
Browse files
app.py
CHANGED
|
@@ -3,17 +3,25 @@ import speech_recognition as sr
|
|
| 3 |
from pydub import AudioSegment
|
| 4 |
import os
|
| 5 |
|
| 6 |
-
def
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
# Auto-detect format from file extension
|
| 8 |
file_ext = os.path.splitext(audio_file_path)[1][1:] # e.g. "mp3", "wav"
|
| 9 |
-
|
| 10 |
# Add silence padding
|
| 11 |
audio = AudioSegment.from_file(audio_file_path, format=file_ext)
|
| 12 |
two_sec_silence = AudioSegment.silent(duration=2500)
|
| 13 |
audio = two_sec_silence + audio + two_sec_silence
|
| 14 |
-
audio.export("
|
| 15 |
-
file_path2 = "
|
| 16 |
|
|
|
|
|
|
|
|
|
|
| 17 |
recognizer = sr.Recognizer()
|
| 18 |
try:
|
| 19 |
with sr.AudioFile(file_path2) as source:
|
|
@@ -35,7 +43,9 @@ iface = gr.Interface(
|
|
| 35 |
inputs=[
|
| 36 |
gr.Audio(sources=["microphone", "upload"], type="filepath", label="Audio Input"),
|
| 37 |
#gr.Textbox(label="Language code (e.g., en-US, fa-IR)")
|
| 38 |
-
gr.Dropdown(choices=["fa-IR", "en-US", "ar-SA"], label="Choose the right language:")
|
|
|
|
|
|
|
| 39 |
],
|
| 40 |
#outputs="text",
|
| 41 |
outputs=gr.Textbox(label="Transcription results", lines=10),
|
|
|
|
| 3 |
from pydub import AudioSegment
|
| 4 |
import os
|
| 5 |
|
| 6 |
+
def audio_preproccessing():
|
| 7 |
+
os.system("deepFilter 'Audio.wav'")
|
| 8 |
+
os.rename("Audio_DeepFilterNet3.wav", "Audio.wav")
|
| 9 |
+
print("Audio Preprocessing Done!")
|
| 10 |
+
|
| 11 |
+
def transcribe_audio(audio_file_path, input_language,denoising):
|
| 12 |
# Auto-detect format from file extension
|
| 13 |
file_ext = os.path.splitext(audio_file_path)[1][1:] # e.g. "mp3", "wav"
|
| 14 |
+
|
| 15 |
# Add silence padding
|
| 16 |
audio = AudioSegment.from_file(audio_file_path, format=file_ext)
|
| 17 |
two_sec_silence = AudioSegment.silent(duration=2500)
|
| 18 |
audio = two_sec_silence + audio + two_sec_silence
|
| 19 |
+
audio.export("Audio.wav", format="wav")
|
| 20 |
+
file_path2 = "Audio.wav"
|
| 21 |
|
| 22 |
+
if denoising=='Yes':
|
| 23 |
+
audio_preproccessing()
|
| 24 |
+
|
| 25 |
recognizer = sr.Recognizer()
|
| 26 |
try:
|
| 27 |
with sr.AudioFile(file_path2) as source:
|
|
|
|
| 43 |
inputs=[
|
| 44 |
gr.Audio(sources=["microphone", "upload"], type="filepath", label="Audio Input"),
|
| 45 |
#gr.Textbox(label="Language code (e.g., en-US, fa-IR)")
|
| 46 |
+
gr.Dropdown(choices=["fa-IR", "en-US", "ar-SA"], label="Choose the right language:"),
|
| 47 |
+
#gr.Checkbox(label="Apply Denoising?")
|
| 48 |
+
gr.Dropdown(choices=["Yes", "No"], label="Need Denoising?")
|
| 49 |
],
|
| 50 |
#outputs="text",
|
| 51 |
outputs=gr.Textbox(label="Transcription results", lines=10),
|