gk2410 commited on
Commit
6080639
·
verified ·
1 Parent(s): fdb0470

Update stt.py

Browse files
Files changed (1) hide show
  1. stt.py +9 -3
stt.py CHANGED
@@ -1,6 +1,7 @@
1
- import tempfilehttps://huggingface.co/spaces/gk2410/AIMLInterviewer/settings
2
  from faster_whisper import WhisperModel
3
 
 
4
  model = WhisperModel(
5
  "base",
6
  device="cpu",
@@ -8,11 +9,16 @@ model = WhisperModel(
8
  )
9
 
10
  def transcribe_audio(uploaded_file):
11
- # Save Streamlit UploadedFile to temp file
 
 
 
 
12
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
13
  tmp.write(uploaded_file.read())
14
  audio_path = tmp.name
15
 
16
  segments, _ = model.transcribe(audio_path)
17
 
18
- return " ".join(seg.text for seg in segments).strip()
 
 
1
+ import tempfile
2
  from faster_whisper import WhisperModel
3
 
4
+ # Load model once (CPU-safe for Hugging Face Spaces)
5
  model = WhisperModel(
6
  "base",
7
  device="cpu",
 
9
  )
10
 
11
  def transcribe_audio(uploaded_file):
12
+ """
13
+ Takes a Streamlit UploadedFile and returns transcribed text
14
+ """
15
+
16
+ # Save uploaded audio to a temp file
17
  with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp:
18
  tmp.write(uploaded_file.read())
19
  audio_path = tmp.name
20
 
21
  segments, _ = model.transcribe(audio_path)
22
 
23
+ text = " ".join(segment.text for segment in segments)
24
+ return text.strip()