|
|
|
import os |
|
|
|
|
|
os.system("pip install git+https://github.com/openai/whisper.git") |
|
|
|
|
|
import gradio as gr |
|
|
|
|
|
import whisper |
|
|
|
|
|
model = whisper.load_model("base") |
|
|
|
|
|
def inference(audio): |
|
|
|
audio = whisper.load_audio(audio) |
|
|
|
|
|
audio = whisper.pad_or_trim(audio) |
|
|
|
|
|
mel = whisper.log_mel_spectrogram(audio).to(model.device) |
|
|
|
|
|
_, probs = model.detect_language(mel) |
|
|
|
|
|
options = whisper.DecodingOptions(fp16=False) |
|
|
|
|
|
result = whisper.decode(model, mel, options) |
|
|
|
|
|
return result.text |
|
|
|
|
|
iface = gr.Interface( |
|
fn=inference, |
|
inputs=gr.Audio(type="filepath", label="支援格式:WAV、MP3、OGG、FLAC、AAC、M4A、WMA。支援單聲道和多聲道。"), |
|
outputs="text" |
|
) |
|
|
|
|
|
iface.launch() |