MBilal-72 Alpha108 commited on
Commit
78b975b
·
verified ·
1 Parent(s): 941d0c1

Create audio_utils.py (#8)

Browse files

- Create audio_utils.py (596821af6dce176e5670b1917a3f3439cfe1837d)


Co-authored-by: Alpha bey <Alpha108@users.noreply.huggingface.co>

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"]