malleswar commited on
Commit
b419444
·
verified ·
1 Parent(s): d126afc

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -4
app.py CHANGED
@@ -78,6 +78,13 @@ def format_srt_time(seconds):
78
  s = seconds % 60
79
  return f"{h:02}:{m:02}:{int(s):02},{int((s-int(s))*1000):03}"
80
 
 
 
 
 
 
 
 
81
  def transcribe_to_srt(audio_file, language="hindi"):
82
  """Transcribe audio to SRT"""
83
 
@@ -90,11 +97,13 @@ def transcribe_to_srt(audio_file, language="hindi"):
90
  print(f"{'='*60}\n")
91
 
92
  if USE_FASTER_WHISPER:
93
- # faster-whisper approach - handles long audio better on CPU
94
- print("Transcribing with faster-whisper...")
 
 
95
  segments, info = model.transcribe(
96
  audio_file,
97
- language=language if language != "auto" else None,
98
  word_timestamps=False
99
  )
100
 
@@ -115,7 +124,7 @@ def transcribe_to_srt(audio_file, language="hindi"):
115
  'text': ' '.join(full_text)
116
  }
117
  else:
118
- # transformers pipeline approach
119
  print("Transcribing with transformers pipeline...")
120
  result = pipe(
121
  audio_file,
 
78
  s = seconds % 60
79
  return f"{h:02}:{m:02}:{int(s):02},{int((s-int(s))*1000):03}"
80
 
81
+ # Language code mapping for faster-whisper compatibility
82
+ LANGUAGE_CODES = {
83
+ "hindi": "hi",
84
+ "english": "en",
85
+ "auto": None
86
+ }
87
+
88
  def transcribe_to_srt(audio_file, language="hindi"):
89
  """Transcribe audio to SRT"""
90
 
 
97
  print(f"{'='*60}\n")
98
 
99
  if USE_FASTER_WHISPER:
100
+ # faster-whisper requires ISO 639-1 codes (hi, en) not full names (hindi, english)
101
+ lang_code = LANGUAGE_CODES.get(language, language)
102
+
103
+ print(f"Transcribing with faster-whisper (language code: {lang_code})...")
104
  segments, info = model.transcribe(
105
  audio_file,
106
+ language=lang_code,
107
  word_timestamps=False
108
  )
109
 
 
124
  'text': ' '.join(full_text)
125
  }
126
  else:
127
+ # transformers pipeline accepts full names (hindi, english)
128
  print("Transcribing with transformers pipeline...")
129
  result = pipe(
130
  audio_file,