ronit1710 commited on
Commit
5949c14
·
verified ·
1 Parent(s): aa1cd0c

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +38 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import librosa
2
+ import gradio as gr
3
+ from faster_whisper import WhisperModel
4
+
5
+ class AudioToText:
6
+ """Converts an MP3 file to text using Faster Whisper."""
7
+
8
+ def __init__(self, model_size="medium.en", device="cpu", compute_type="int8", language="en"):
9
+ """Initialize the Whisper model for transcription."""
10
+ self.model = WhisperModel(model_size, device=device, compute_type=compute_type)
11
+ self.language = language
12
+
13
+ def transcribe_audio(self, file_path):
14
+ """Transcribe an MP3 audio file to text."""
15
+ audio, sr = librosa.load(file_path, sr=16000)
16
+ segments, _ = self.model.transcribe(audio, beam_size=5, language=self.language, vad_filter=True)
17
+ transcription = "\n".join([segment.text.strip() for segment in segments])
18
+ return transcription
19
+
20
+ # Create an instance of the transcription model
21
+ transcriber = AudioToText()
22
+
23
+ # Define the Gradio function
24
+ def transcribe_gradio(file_path):
25
+ return transcriber.transcribe_audio(file_path)
26
+
27
+ # Create Gradio interface
28
+ demo = gr.Interface(
29
+ fn=transcribe_gradio,
30
+ inputs=gr.Audio(type="filepath"), # ✅ Fixed: Changed "file" to "filepath"
31
+ outputs="text",
32
+ title="Speech-to-Text Whisper Demo",
33
+ description="Upload an MP3 file to transcribe it to text using Faster Whisper.",
34
+ )
35
+
36
+ # Launch the demo
37
+ demo.launch()
38
+
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio
2
+ librosa
3
+ faster-whisper