Create audio_utils.py

#8
by Alpha108 - opened
Files changed (1) hide show
  1. utils/audio_utils.py +11 -0
utils/audio_utils.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import whisper
2
+ import tempfile
3
+
4
+ # Transcribe uploaded audio file to text using Whisper
5
+ def transcribe_audio(audio_file) -> str:
6
+ model = whisper.load_model("base")
7
+ with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp:
8
+ tmp.write(audio_file.read())
9
+ tmp_path = tmp.name
10
+ result = model.transcribe(tmp_path)
11
+ return result["text"]