File size: 935 Bytes
46e047b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import os
#os.system("python -m pip install --upgrade pip")
os.system("pip install git+https://github.com/openai/whisper.git")
#os.system("pip install --upgrade gradio")
import gradio as gr
import torch
import whisper
import soundfile as sf

#device = "cuda" if torch.cuda.is_available() else "cpu"
#whisper_model = whisper.load_model("tiny.en", device=device)
whisper_model = whisper.load_model("tiny.en")

def audio2text(audio):
    f = sf.SoundFile(audio)
    seconds = int(len(f) / f.samplerate)
    seconds = seconds * 16000
    audio = whisper.load_audio(audio)
    audio = whisper.pad_or_trim(audio, length=int(seconds))
    result = whisper_model.transcribe(audio=audio, language="en")
    huh = result["text"]
    return huh

input_audio = gr.Audio(source="upload", type="filepath")
output_text = gr.Textbox()

interface = gr.Interface(
    fn=audio2text,
    inputs=input_audio,
    outputs=output_text,
)

interface.launch()