VedantDhavan commited on
Commit
2a6a085
Β·
verified Β·
1 Parent(s): 5d183b1

Code in Python

Browse files
Files changed (2) hide show
  1. Speech_To_Text/main.py +38 -0
  2. Speech_To_Text/readme.md +24 -0
Speech_To_Text/main.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import whisper
2
+
3
+ model = whisper.load_model('base')
4
+
5
+ import gradio as gr # Import gradio as gr
6
+ import time
7
+
8
+ def transcribe(audio):
9
+ #time.sleep(3)
10
+ #step 1: load audio
11
+ audio = whisper.load_audio(audio)
12
+ audio = whisper.pad_or_trim(audio)
13
+
14
+ #step 2: make a log-Mel Spectrogram and move to the same device as the model
15
+ mel = whisper.log_mel_spectrogram(audio).to(model.device)
16
+
17
+ #step 3: detect the spoken laguage
18
+ _, probs = model.detect_language(mel)
19
+ print(f"Detected language: {max(probs, key=probs.get)}")
20
+
21
+ #step 4: decode the audio
22
+ options = whisper.DecodingOptions()
23
+ result = whisper.decode(model, mel, options)
24
+
25
+ #step 5: print the recognized text
26
+ return result.text
27
+
28
+ gr.Interface( # Use gr.Interface
29
+ title = 'Speech to Text using API',
30
+ fn=transcribe,
31
+ inputs=[
32
+ # Removed the 'source' argument and changed 'type' to 'microphone'.
33
+ gr.Audio(type="filepath")
34
+ ],
35
+ outputs=[
36
+ "textbox"
37
+ ],
38
+ live=True).launch()
Speech_To_Text/readme.md ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ A Speech-to-Text (STT) model is an AI-powered system that converts spoken language into written text. These models are widely used in applications like virtual assistants, transcription services, accessibility tools, and voice-controlled devices.
2
+
3
+ How It Works
4
+ Audio Input: The model takes an audio signal as input, which can be a live speech or a recorded file.
5
+ Preprocessing: The audio is processed to remove noise, normalize volume, and convert it into a suitable format (e.g., spectrogram or Mel-frequency cepstral coefficients - MFCCs).
6
+ Feature Extraction: The model extracts relevant features from the audio, such as phonemes (basic sound units of speech).
7
+ Acoustic Model: It maps the extracted features to corresponding phonetic units.
8
+ Language Model: It refines the raw phonetic transcription by applying linguistic rules, grammar, and context.
9
+ Text Output: The final output is a structured, readable text representation of the spoken words.
10
+ Types of Speech-to-Text Models
11
+ Traditional ASR (Automatic Speech Recognition) – Uses Hidden Markov Models (HMM) and Gaussian Mixture Models (GMM).
12
+ Deep Learning-Based Models – Uses Recurrent Neural Networks (RNNs), Long Short-Term Memory (LSTMs), and Transformer-based architectures like Whisper by OpenAI or DeepSpeech by Mozilla.
13
+ End-to-End Models – Uses a single deep learning model (e.g., Transformer, Conformer) to directly map audio to text without separate acoustic and language models.
14
+ Popular Speech-to-Text Models
15
+ Whisper (OpenAI) – Multilingual, robust to noise, works well with various accents.
16
+ DeepSpeech (Mozilla) – Uses deep learning to achieve high accuracy.
17
+ Kaldi – Open-source toolkit for speech recognition.
18
+ Google Speech-to-Text API – Cloud-based solution with high accuracy.
19
+ Vosk – Lightweight and offline-capable STT system.
20
+ Challenges in STT Models
21
+ Background Noise – Can affect transcription accuracy.
22
+ Accents and Dialects – Hard to generalize for all users.
23
+ Code-Switching – Handling multiple languages in one sentence.
24
+ Low-Resource Languages – Less training data available.