File size: 681 Bytes
7bfec74
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# tools/audio_transcriber.py

import os
import tempfile
import whisper

# Load Whisper model only once (tiny, base, or small recommended for speed)
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)}"