Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,27 +2,25 @@
|
|
2 |
import warnings
|
3 |
warnings.filterwarnings("ignore")
|
4 |
|
5 |
-
import librosa
|
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
|
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
|
13 |
-
from isNumber import is_number
|
14 |
from Text2List import text_to_list # Converts a text string into a list of words.
|
15 |
-
from convert2list import convert_to_list
|
16 |
from processDoubles import process_doubles # Handles repeated words or numbers in speech recognition output.
|
17 |
-
from replaceWords import replace_words
|
18 |
-
from highPassFilter import high_pass_filter
|
19 |
-
from waveletDenoise import wavelet_denoise
|
20 |
-
from 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)
|
@@ -50,7 +48,6 @@ def sel_lng(lng, mic=None, file=None):
|
|
50 |
if lng == "model_1":
|
51 |
return recognize_speech(audio)
|
52 |
|
53 |
-
|
54 |
# Create a Gradio interface
|
55 |
demo = gr.Interface(
|
56 |
fn=sel_lng,
|
@@ -59,8 +56,6 @@ demo = gr.Interface(
|
|
59 |
gr.Audio(sources=["microphone", "upload"], type="filepath"),
|
60 |
],
|
61 |
outputs=["textbox"],
|
62 |
-
title="Automatic Speech Recognition"
|
63 |
-
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"
|
64 |
)
|
65 |
-
|
66 |
demo.launch()
|
|
|
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 |
|
10 |
# Importing custom utility functions for text processing.
|
11 |
+
from text2int import text_to_int # Converts text numbers (e.g., "one") into integers (e.g., 1).
|
12 |
+
from isNumber import is_number # Checks if a string is a number.
|
13 |
from Text2List import text_to_list # Converts a text string into a list of words.
|
14 |
+
from convert2list import convert_to_list # Converts processed text into a structured list.
|
15 |
from processDoubles import process_doubles # Handles repeated words or numbers in speech recognition output.
|
16 |
+
from replaceWords import replace_words # Replaces specific words in the recognized text with alternatives.
|
17 |
+
from highPassFilter import high_pass_filter # filter noise by bypassing high frequency signals.
|
18 |
+
from waveletDenoise import wavelet_denoise # used for signal Denoising.
|
19 |
+
from applyWienerFilter import apply_wiener_filter # for Signal Denoising.
|
20 |
|
21 |
# Initialize ASR model pipeline
|
22 |
asr_model = pipeline("automatic-speech-recognition", model="cdactvm/w2v-bert-punjabi")
|
23 |
|
|
|
24 |
# Function to handle speech recognition
|
25 |
def recognize_speech(audio_file):
|
26 |
audio, sr = librosa.load(audio_file, sr=16000)
|
|
|
48 |
if lng == "model_1":
|
49 |
return recognize_speech(audio)
|
50 |
|
|
|
51 |
# Create a Gradio interface
|
52 |
demo = gr.Interface(
|
53 |
fn=sel_lng,
|
|
|
56 |
gr.Audio(sources=["microphone", "upload"], type="filepath"),
|
57 |
],
|
58 |
outputs=["textbox"],
|
59 |
+
title="Automatic Speech Recognition"
|
|
|
60 |
)
|
|
|
61 |
demo.launch()
|