File size: 1,133 Bytes
95e0c29
 
 
c2f396b
95e0c29
 
 
 
 
 
3817901
 
 
95e0c29
 
 
 
 
 
 
 
 
4a26935
 
 
 
95e0c29
3817901
95e0c29
 
3817901
95e0c29
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3817901
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import whisper

# You can choose your model from - see it on readme file and update the modelname
modelname = "tiny.en"
model = whisper.load_model(modelname)

import gradio as gr 
import time

def SpeechToText(audio):
    if audio is None:
        return "", "" 
    
    time.sleep(1)

    audio = whisper.load_audio(audio)
    audio = whisper.pad_or_trim(audio)

    # make log-Mel spectrogram and move to the same device as the model
    mel = whisper.log_mel_spectrogram(audio).to(model.device)

    # Detect the Max probability of language ?
    # _, probs = model.detect_language(mel)
    # language = max(probs, key=probs.get)
    language = "Unknown"


    # Decode audio to Text
    options = whisper.DecodingOptions(fp16 = False)
    result = whisper.decode(model, mel, options)
    return language, result.text

print("Starting the Gradio Web UI")
gr.Interface(
    title = 'OpenAI Whisper implementation on Gradio Web UI', 
    fn=SpeechToText, 
    inputs=[
        gr.Audio(source="microphone", type="filepath")
    ],
    outputs=[
        "label",
        "textbox",
    ],
    live=True
).launch(
    debug=False,
)