speech-to-text / speech_to_text.py
MSchell0129
separated files based on function
a76862a
raw
history blame
1.01 kB
import openai
import whisper
from api_key import open_ai_key
llm = openai(temperature=0, openai_api_key='open_ai_key')
#This is another alternative, but this block allows for the detection of the language and it also provides lowever-level access to the model
def transcribe(aud_inp, whisper_lang):
if aud_inp is None:
return ''
model = whisper.load_audo('base')
#load audo and pad/trim it to fit 30seconds
audio = whisper.load_audio(aud_inp)
audio = whisper.pad_or_trim(audio)
#make log-Mel spectrogram and move to the same devcice as the model
mel = whisper.log_mel_spectogram(audio).to(model.device)
#detect the spoken language
_,probs = model.detect_language(mel)
print(f'Detected language: {max(probs, key=probs.get)}')
#decode the audio
options = whisper.DecodingOptions()
result = whisper.decode(model, mel, options)
print(result.text)
return result
if __name__ == '__main__':
transcribe('audio_file_path', 'whisper-1')