cowrycode commited on
Commit
1595c2e
·
verified ·
1 Parent(s): 9479d34

Update agent_tools/audio_transcriber.py

Browse files
Files changed (1) hide show
  1. agent_tools/audio_transcriber.py +20 -0
agent_tools/audio_transcriber.py CHANGED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import tempfile
3
+ import whisper
4
+
5
+ MODEL_NAME = "base"
6
+ whisper_model = whisper.load_model(MODEL_NAME)
7
+
8
+ def transcribe_audio(audio_file_path: str) -> str:
9
+ """
10
+ Transcribes speech from an audio file using OpenAI Whisper.
11
+ Args:
12
+ audio_file_path (str): Path to the local audio file (.mp3, .wav, etc.).
13
+ Returns:
14
+ str: Transcribed text or error message.
15
+ """
16
+ try:
17
+ result = whisper_model.transcribe(audio_file_path)
18
+ return result["text"].strip()
19
+ except Exception as e:
20
+ return f"Transcription error: {str(e)}"