iqbalc/openAI-base
0
1import os2os.system("pip install git+https://github.com/openai/whisper.git")3 4import gradio as gr5import whisper6model = whisper.load_model("base")7 8import time9 10def transcribe(audio):11 # load audio for 30 seconds12 audio = whisper.load_audio(audio)13 audio = whisper.pad_or_trim(audio)14 15 # make log-Mel spectrogram and move to device as the model16 mel = whisper.log_mel_spectrogram(audio).to(model.device)17 18 # detect the spoken language19 _, probs = model.detect_language(mel)20 print(f"Detected language: {max(probs, key=probs.get)}")21 22 # decoding the audio23 options = whisper.DecodingOptions(fp16 = False)24 result = whisper.decode(model, mel, options)25 print(result.text)26 return result.text27 28gr.Interface(29 title = 'Speech to Text with OpenAI (base)', 30 fn=transcribe, 31 inputs=[32 gr.inputs.Audio(source="microphone", type="filepath")33 ],34 outputs=[35 "textbox"36 ],37 live=True).launch()