cdactvm commited on
Commit
fb9d859
·
verified ·
1 Parent(s): a9a4e1f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -106
app.py CHANGED
@@ -1,113 +1,20 @@
1
- # import warnings
2
- # warnings.filterwarnings("ignore")
3
-
4
- # import os # for handling of directories.
5
- # import re # regular expression.
6
- # import pywt # pywavelet for wavelet transformation. used in denoising.
7
- # import librosa # used for audio processing.
8
- # import webrtcvad
9
- # import torchaudio # python library for audio processing.
10
- # import numpy as np # for mathematical calculations
11
- # import gradio as gr # for inferencing.
12
- # import scipy.signal # used for signal filtering. used in denoising audio signals.
13
- # import soundfile as sf # used for reading and processing audio files.
14
- # from scipy.io.wavfile import write # used for saving audio files in wav format.
15
- # from transformers import pipeline # used for inferencing.
16
- # from transformers import AutoProcessor #used for processing of input data.
17
- # from pyctcdecode import build_ctcdecoder
18
- # from transformers import Wav2Vec2ProcessorWithLM
19
- # from scipy.signal import butter, lfilter, wiener
20
- # from text2int import text_to_int
21
- # from isNumber import is_number
22
- # from Text2List import text_to_list
23
- # from convert2list import convert_to_list
24
- # from processDoubles import process_doubles
25
- # from replaceWords import replace_words
26
- # # from applyVad import apply_vad
27
- # # from wienerFilter import wiener_filter
28
- # # from highPassFilter import high_pass_filter
29
- # # from waveletDenoise import wavelet_denoise
30
-
31
- # asr_model = pipeline("automatic-speech-recognition", model="cdactvm/w2v-bert-punjabi")
32
-
33
-
34
- # # Function to apply a high-pass filter
35
- # def high_pass_filter(audio, sr, cutoff=300):
36
- # nyquist = 0.5 * sr
37
- # normal_cutoff = cutoff / nyquist
38
- # b, a = butter(1, normal_cutoff, btype='high', analog=False)
39
- # filtered_audio = lfilter(b, a, audio)
40
- # return filtered_audio
41
-
42
- # # Function to apply wavelet denoising
43
- # def wavelet_denoise(audio, wavelet='db1', level=1):
44
- # coeffs = pywt.wavedec(audio, wavelet, mode='per')
45
- # sigma = np.median(np.abs(coeffs[-level])) / 0.5
46
- # uthresh = sigma * np.sqrt(2 * np.log(len(audio)))
47
- # coeffs[1:] = [pywt.threshold(i, value=uthresh, mode='soft') for i in coeffs[1:]]
48
- # return pywt.waverec(coeffs, wavelet, mode='per')
49
-
50
- # # Function to apply a Wiener filter for noise reduction
51
- # def apply_wiener_filter(audio):
52
- # return wiener(audio)
53
-
54
-
55
- # # # Function to handle speech recognition
56
- # def recognize_speech(audio_file):
57
- # audio, sr = librosa.load(audio_file, sr=16000)
58
- # audio = high_pass_filter(audio, sr)
59
- # audio = apply_wiener_filter(audio)
60
- # denoised_audio = wavelet_denoise(audio)
61
- # result = asr_model(denoised_audio)
62
- # text_value = result['text']
63
- # cleaned_text = text_value.replace("[PAD]", "")
64
- # converted_to_list = convert_to_list(cleaned_text, text_to_list())
65
- # processed_doubles = process_doubles(converted_to_list)
66
- # replaced_words = replace_words(processed_doubles)
67
- # converted_text = text_to_int(replaced_words)
68
- # return converted_text
69
-
70
- # def sel_lng(lng, mic=None, file=None):
71
- # if mic is not None:
72
- # audio = mic
73
- # elif file is not None:
74
- # audio = file
75
- # else:
76
- # return "You must either provide a mic recording or a file"
77
-
78
- # if lng == "model_1":
79
- # return recognize_speech(audio)
80
-
81
- # demo=gr.Interface(
82
- # fn=sel_lng,
83
-
84
- # inputs=[
85
- # gr.Dropdown([
86
- # "model_1"],label="Select Model"),
87
- # gr.Audio(sources=["microphone","upload"], type="filepath"),
88
- # ],
89
- # outputs=[
90
- # "textbox"
91
- # ],
92
- # title="Automatic Speech Recognition",
93
- # description = "Demo for Automatic Speech Recognition. Use microphone to record speech. Please press Record button. Initially it will take some time to load the model. The recognized text will appear in the output textbox",
94
- # ).launch()
95
-
96
 
97
  import warnings
98
  warnings.filterwarnings("ignore")
99
 
100
- import librosa # used for audio processing.
101
- import numpy as np # for mathematical calculations
102
- import gradio as gr # for inferencing.
103
- from transformers import pipeline # used for inferencing.
104
- from scipy.signal import butter, lfilter, wiener
105
- from text2int import text_to_int
106
- from isNumber import is_number
107
- from Text2List import text_to_list
108
- from convert2list import convert_to_list
109
- from processDoubles import process_doubles
110
- from replaceWords import replace_words
 
 
111
 
112
  # Initialize ASR model pipeline
113
  asr_model = pipeline("automatic-speech-recognition", model="cdactvm/w2v-bert-punjabi")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
  import warnings
3
  warnings.filterwarnings("ignore")
4
 
5
+ import librosa # Library for loading and processing audio files.
6
+ import numpy as np # Library for numerical computations, used for signal processing.
7
+ import gradio as gr # Library for creating a web-based user interface for inference.
8
+ from transformers import pipeline # Import pipeline for automatic speech recognition (ASR).
9
+ from scipy.signal import butter, lfilter, wiener # Signal processing functions for noise reduction.
10
+
11
+ # Importing custom utility functions for text processing.
12
+ from text2int import text_to_int # Converts text numbers (e.g., "one") into integers (e.g., 1).
13
+ from isNumber import is_number # Checks if a string is a number.
14
+ from Text2List import text_to_list # Converts a text string into a list of words.
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")