Ahmadkhan12 commited on
Commit
cc78ef3
·
verified ·
1 Parent(s): b8176bc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -5
app.py CHANGED
@@ -1,7 +1,7 @@
1
  import gradio as gr
2
  import subprocess
3
  import traceback
4
- from whisper_cpp import Whisper # whisper.cpp Python wrapper
5
  import argostranslate.package
6
  import argostranslate.translate
7
 
@@ -15,13 +15,14 @@ def extract_audio(video_path):
15
  return audio_path
16
 
17
  # -------------------------------
18
- # 2. Transcribe using whisper_cpp
19
  # -------------------------------
20
  def transcribe_audio(audio_path):
21
  try:
22
- model = Whisper(model_size="small") # CPU-friendly small model
23
- result = model.transcribe(audio_path)
24
- text = result.get("text", "")
 
25
  return text.strip()
26
  except Exception:
27
  return f"STT Error:\n{traceback.format_exc()}"
 
1
  import gradio as gr
2
  import subprocess
3
  import traceback
4
+ import speech_recognition as sr
5
  import argostranslate.package
6
  import argostranslate.translate
7
 
 
15
  return audio_path
16
 
17
  # -------------------------------
18
+ # 2. Transcribe using CMU Sphinx (offline)
19
  # -------------------------------
20
  def transcribe_audio(audio_path):
21
  try:
22
+ recognizer = sr.Recognizer()
23
+ with sr.AudioFile(audio_path) as source:
24
+ audio = recognizer.record(source)
25
+ text = recognizer.recognize_sphinx(audio)
26
  return text.strip()
27
  except Exception:
28
  return f"STT Error:\n{traceback.format_exc()}"