File size: 926 Bytes
2befe53
 
99caa7a
64f24b5
624e848
2befe53
 
13787ef
2befe53
c508458
2befe53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13787ef
c508458
99caa7a
 
13787ef
99caa7a
13787ef
 
99caa7a
 
 
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
import openai
import whisper
import gradio as gr
import os



app = gr.Blocks()


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)
 


def run():
    with app:
        gr.Interface(fn=transcribe, inputs="microphone", outputs="text")
    app.launch(server_name='0.0.0.0', server_port=7860)

if __name__ == '__main__':
    run()