cdactvm commited on
Commit
b8ea966
·
verified ·
1 Parent(s): 412403d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -22
app.py CHANGED
@@ -15,33 +15,14 @@ from Text2List import text_to_list # Converts a text string into a list of wor
15
  from convert2list import convert_to_list # Converts processed text into a structured list.
16
  from processDoubles import process_doubles # Handles repeated words or numbers in speech recognition output.
17
  from replaceWords import replace_words # Replaces specific words in the recognized text with alternatives.
 
 
 
18
 
19
  # Initialize ASR model pipeline
20
  asr_model = pipeline("automatic-speech-recognition", model="cdactvm/w2v-bert-punjabi")
21
 
22
 
23
- # Function to apply a high-pass filter
24
- def high_pass_filter(audio, sr, cutoff=300):
25
- nyquist = 0.5 * sr
26
- normal_cutoff = cutoff / nyquist
27
- b, a = butter(1, normal_cutoff, btype='high', analog=False)
28
- filtered_audio = lfilter(b, a, audio)
29
- return filtered_audio
30
-
31
- # Function to apply wavelet denoising
32
- def wavelet_denoise(audio, wavelet='db1', level=1):
33
- import pywt
34
- coeffs = pywt.wavedec(audio, wavelet, mode='per')
35
- sigma = np.median(np.abs(coeffs[-level])) / 0.5
36
- uthresh = sigma * np.sqrt(2 * np.log(len(audio)))
37
- coeffs[1:] = [pywt.threshold(i, value=uthresh, mode='soft') for i in coeffs[1:]]
38
- return pywt.waverec(coeffs, wavelet, mode='per')
39
-
40
- # Function to apply a Wiener filter for noise reduction
41
- def apply_wiener_filter(audio):
42
- return wiener(audio)
43
-
44
-
45
  # Function to handle speech recognition
46
  def recognize_speech(audio_file):
47
  audio, sr = librosa.load(audio_file, sr=16000)
 
15
  from convert2list import convert_to_list # Converts processed text into a structured list.
16
  from processDoubles import process_doubles # Handles repeated words or numbers in speech recognition output.
17
  from replaceWords import replace_words # Replaces specific words in the recognized text with alternatives.
18
+ from highPassFiler import high_pass_filter
19
+ form WaveletDenoise import wavelet_denoise
20
+ fomr applyWienerFilter import apply_wiener_filter
21
 
22
  # Initialize ASR model pipeline
23
  asr_model = pipeline("automatic-speech-recognition", model="cdactvm/w2v-bert-punjabi")
24
 
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  # Function to handle speech recognition
27
  def recognize_speech(audio_file):
28
  audio, sr = librosa.load(audio_file, sr=16000)