File size: 522 Bytes
710a34d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1bdd33b
710a34d
 
1bdd33b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import whisper
import pydub
import os

whisper_model = "medium"


def load_model():
    print("Loading audio model...")
    return whisper.load_model(whisper_model)


def audio_to_text(model, audio_file):
    audio = pydub.AudioSegment.from_file(audio_file)
    # Export for loading later
    audio.export("audio_tmp")
    try:
        audio = whisper.load_audio("audio_tmp")
        result = whisper.transcribe(model=model, audio=audio, verbose=True)
    finally:
        os.remove("audio_tmp")
    return result["text"]