Spaces:
Sleeping
Sleeping
Update stt.py
Browse files
stt.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
-
import
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
|
|
|
|
|
|
| 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()
|