Update app.py
Browse files
app.py
CHANGED
@@ -25,6 +25,7 @@ from replaceWords import replace_words
|
|
25 |
from applyVad import apply_vad
|
26 |
from wienerFilter import wiener_filter
|
27 |
from highPassFilter import high_pass_filter
|
|
|
28 |
|
29 |
|
30 |
|
@@ -74,45 +75,40 @@ def transcribe_hindi_old(audio):
|
|
74 |
converted_text=text_to_int(replaced_words)
|
75 |
return converted_text
|
76 |
|
77 |
-
## implementation of noise reduction techniques.
|
78 |
###############################################
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
99 |
return converted_text
|
100 |
|
101 |
-
# Combined function to process and transcribe audio
|
102 |
-
def process_audio_and_transcribe(audio):
|
103 |
-
# Step 1: Preprocess (Noise Reduction)
|
104 |
-
try:
|
105 |
-
processed_filepath = noise_reduction_pipeline(audio)
|
106 |
-
except webrtcvad.Error as e:
|
107 |
-
return f"Error in processing audio for VAD: {str(e)}"
|
108 |
-
|
109 |
-
# Step 2: Transcription
|
110 |
-
try:
|
111 |
-
transcription = transcribe_with_huggingface(processed_filepath)
|
112 |
-
except Exception as e:
|
113 |
-
return f"Transcription failed: {str(e)}"
|
114 |
-
|
115 |
-
return transcription
|
116 |
#################################################
|
117 |
|
118 |
def sel_lng(lng, mic=None, file=None):
|
@@ -130,7 +126,7 @@ def sel_lng(lng, mic=None, file=None):
|
|
130 |
elif lng== "model_3":
|
131 |
return transcribe_hindi_lm(audio)
|
132 |
elif lng== "model_4":
|
133 |
-
return
|
134 |
|
135 |
|
136 |
# demo=gr.Interface(
|
|
|
25 |
from applyVad import apply_vad
|
26 |
from wienerFilter import wiener_filter
|
27 |
from highPassFilter import high_pass_filter
|
28 |
+
from wavletDenoise import wavelet_denoise
|
29 |
|
30 |
|
31 |
|
|
|
75 |
converted_text=text_to_int(replaced_words)
|
76 |
return converted_text
|
77 |
|
|
|
78 |
###############################################
|
79 |
+
# implementation of noise reduction techniques.
|
80 |
+
|
81 |
+
# Function to apply a Wiener filter for noise reduction
|
82 |
+
def apply_wiener_filter(audio):
|
83 |
+
return wiener(audio)
|
84 |
+
|
85 |
+
# Function to handle speech recognition
|
86 |
+
def Noise_cancellation_function(audio_file):
|
87 |
+
# Load the audio file using librosa
|
88 |
+
audio, sr = librosa.load(audio_file, sr=16000)
|
89 |
+
|
90 |
+
# Step 1: Apply a high-pass filter
|
91 |
+
audio = high_pass_filter(audio, sr)
|
92 |
+
|
93 |
+
# Step 2: Apply Wiener filter for noise reduction
|
94 |
+
audio = apply_wiener_filter(audio)
|
95 |
+
|
96 |
+
# Step 3: Apply wavelet denoising
|
97 |
+
denoised_audio = wavelet_denoise(audio)
|
98 |
+
|
99 |
+
# Save the denoised audio to a temporary file
|
100 |
+
temp_wav = "temp_denoised.wav"
|
101 |
+
write(temp_wav, sr, denoised_audio)
|
102 |
+
|
103 |
+
# Perform speech recognition on the denoised audio
|
104 |
+
transcript = transcriber_hindi_lm(temp_wav)
|
105 |
+
text_value = transcript['text']
|
106 |
+
cleaned_text=text_value.replace("<s>","")
|
107 |
+
processd_doubles=process_doubles(cleaned_text)
|
108 |
+
replaced_words = replace_words(processd_doubles)
|
109 |
+
converted_text=text_to_int(replaced_words)
|
110 |
return converted_text
|
111 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
#################################################
|
113 |
|
114 |
def sel_lng(lng, mic=None, file=None):
|
|
|
126 |
elif lng== "model_3":
|
127 |
return transcribe_hindi_lm(audio)
|
128 |
elif lng== "model_4":
|
129 |
+
return Noise_cancellation_function(audio)
|
130 |
|
131 |
|
132 |
# demo=gr.Interface(
|