Spaces:
Sleeping
Sleeping
Create asr.py
Browse files- models/asr.py +14 -0
models/asr.py
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# models/asr.py
|
| 2 |
+
|
| 3 |
+
import whisper
|
| 4 |
+
from config.hf_config import ASR_MODEL_NAME
|
| 5 |
+
|
| 6 |
+
# Load Whisper model once
|
| 7 |
+
asr_model = whisper.load_model(ASR_MODEL_NAME.replace("openai/", ""))
|
| 8 |
+
|
| 9 |
+
def transcribe_audio(audio_path: str) -> str:
|
| 10 |
+
"""
|
| 11 |
+
Transcribe audio file to text using Whisper.
|
| 12 |
+
"""
|
| 13 |
+
result = asr_model.transcribe(audio_path)
|
| 14 |
+
return result["text"]
|