File size: 572 Bytes
1595c2e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import os
import tempfile
import whisper

MODEL_NAME = "base"
whisper_model = whisper.load_model(MODEL_NAME)

def transcribe_audio(audio_file_path: str) -> str:
    """
    Transcribes speech from an audio file using OpenAI Whisper.
    Args:
        audio_file_path (str): Path to the local audio file (.mp3, .wav, etc.).
    Returns:
        str: Transcribed text or error message.
    """
    try:
        result = whisper_model.transcribe(audio_file_path)
        return result["text"].strip()
    except Exception as e:
        return f"Transcription error: {str(e)}"