cdactvm commited on
Commit
e63314d
1 Parent(s): 9cb187d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -37
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
- def noise_reduction_pipeline(filepath):
80
- # Your existing noise reduction code
81
- audio, sr = librosa.load(filepath, sr=None)
82
- audio_hp = high_pass_filter(audio, sr, cutoff=100, order=5)
83
- audio_wiener = wiener_filter(audio_hp)
84
- audio_vad = apply_vad(audio_wiener, sr)
85
- output_filepath = "processed_output.wav"
86
- sf.write(output_filepath, audio_vad, sr)
87
- return output_filepath
88
-
89
- # Hugging Face ASR function uses the pre-loaded model
90
- def transcribe_with_huggingface(filepath):
91
- result = transcriber_hindi_lm(filepath)
92
- text_value = result['text']
93
- cleaned_text = text_value.replace("<s>", "")
94
- converted_to_list = convert_to_list(cleaned_text, text_to_list())
95
- processed_doubles = process_doubles(converted_to_list)
96
- replaced_words = replace_words(processed_doubles)
97
- converted_text = text_to_int(replaced_words)
98
- print("Transcription: ", converted_text)
 
 
 
 
 
 
 
 
 
 
 
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 process_audio_and_transcribe(audio)
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(