Spaces:
Paused
Paused
Commit
·
eb3d745
1
Parent(s):
1f41a8a
updated
Browse files
backend/services/interview_engine.py
CHANGED
|
@@ -175,31 +175,36 @@ def convert_webm_to_wav(webm_path, wav_path):
|
|
| 175 |
logging.error(f"Error converting audio: {e}")
|
| 176 |
return None
|
| 177 |
|
|
|
|
|
|
|
| 178 |
def whisper_stt(audio_path):
|
|
|
|
| 179 |
try:
|
| 180 |
-
if not audio_path or
|
| 181 |
-
logging.error(f"Audio file
|
| 182 |
-
return ""
|
| 183 |
-
|
| 184 |
-
if os.path.getsize(audio_path) == 0:
|
| 185 |
-
logging.error(f"Audio file is empty: {audio_path}")
|
| 186 |
return ""
|
| 187 |
|
| 188 |
-
# Convert
|
| 189 |
-
|
| 190 |
-
|
| 191 |
-
"ffmpeg",
|
| 192 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
|
| 194 |
-
if not os.path.exists(
|
| 195 |
-
logging.error(f"
|
| 196 |
return ""
|
| 197 |
|
| 198 |
model = load_whisper_model()
|
| 199 |
-
segments, _ = model.transcribe(
|
| 200 |
transcript = " ".join(segment.text for segment in segments)
|
| 201 |
return transcript.strip()
|
| 202 |
-
|
| 203 |
except Exception as e:
|
| 204 |
logging.error(f"Error in STT: {e}")
|
| 205 |
return ""
|
|
|
|
| 175 |
logging.error(f"Error converting audio: {e}")
|
| 176 |
return None
|
| 177 |
|
| 178 |
+
import subprocess # top of the file if not already imported
|
| 179 |
+
|
| 180 |
def whisper_stt(audio_path):
|
| 181 |
+
"""Speech-to-text using Faster-Whisper"""
|
| 182 |
try:
|
| 183 |
+
if not os.path.exists(audio_path) or os.path.getsize(audio_path) == 0:
|
| 184 |
+
logging.error(f"Audio file is empty or missing: {audio_path}")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
return ""
|
| 186 |
|
| 187 |
+
# Convert webm to wav using ffmpeg
|
| 188 |
+
wav_path = audio_path.replace(".webm", ".wav")
|
| 189 |
+
cmd = [
|
| 190 |
+
"ffmpeg",
|
| 191 |
+
"-y", # overwrite
|
| 192 |
+
"-i", audio_path,
|
| 193 |
+
"-ar", "16000",
|
| 194 |
+
"-ac", "1",
|
| 195 |
+
"-f", "wav",
|
| 196 |
+
wav_path
|
| 197 |
+
]
|
| 198 |
+
subprocess.run(cmd, stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL)
|
| 199 |
|
| 200 |
+
if not os.path.exists(wav_path) or os.path.getsize(wav_path) == 0:
|
| 201 |
+
logging.error(f"FFmpeg conversion failed or produced empty file: {wav_path}")
|
| 202 |
return ""
|
| 203 |
|
| 204 |
model = load_whisper_model()
|
| 205 |
+
segments, _ = model.transcribe(wav_path)
|
| 206 |
transcript = " ".join(segment.text for segment in segments)
|
| 207 |
return transcript.strip()
|
|
|
|
| 208 |
except Exception as e:
|
| 209 |
logging.error(f"Error in STT: {e}")
|
| 210 |
return ""
|