File size: 724 Bytes
8d21854
abb33c7
460f6d7
8d21854
abb33c7
8d21854
abb33c7
 
 
 
 
 
ee73c30
 
abb33c7
 
 
8d21854
ee73c30
abb33c7
 
 
 
 
 
ee73c30
8d21854
abb33c7
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
import gradio as gr
import torch
from transformers import pipeline

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

pipe = pipeline(
    "automatic-speech-recognition",
    model="jonatasgrosman/wav2vec2-large-xlsr-53-persian",
    chunk_length_s=30,
    device=device,
)


def transcribe(audio):
    text = pipe(audio["file"])["text"]
    return text


iface = gr.Interface(
    fn=transcribe,
    inputs=gr.Audio(sources=["upload", "microphone"]),
    outputs="text",
    title="تبدیل گفتار به متن فارسی",
    description="فایل صوتی خود را آپلود کنید یا از طریق میکروفون صحبت کنید تا متن آن را دریافت کنید.",
)

iface.launch()