File size: 764 Bytes
9d3afd7
3a6c9ee
48a358e
3a6c9ee
48a358e
c6c4c19
48a358e
 
 
 
 
 
9d3afd7
36bd290
 
 
 
 
 
 
b004a55
36bd290
9d3afd7
36bd290
 
 
9d3afd7
36bd290
 
 
9d3afd7
36bd290
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
from transformers import pipeline
import gradio as gr
import torch

device = "cuda:0" if torch.cuda.is_available() else "cpu"

asr = pipeline(
    "automatic-speech-recognition",
    model="MaximilianChen/Casper",
    chunk_length_s=30,
    device=device,
)

def transcribe_audio(mic=None, file=None):
    if mic is not None:
        audio = mic
    elif file is not None:
        audio = file
    else:
        return "You must either provide a mic recording or a file"
    transcription = asr(audio)["text"]
    return transcription


gr.Interface(
    fn=transcribe_audio,
    inputs=[
        gr.Audio(source="microphone", type="filepath", optional=True),
        gr.Audio(source="upload", type="filepath", optional=True),
    ],
    outputs="text",
).launch()