File size: 1,085 Bytes
1869d7a
 
2aa2fbe
 
1869d7a
2aa2fbe
 
 
 
 
 
 
 
 
1869d7a
 
 
2aa2fbe
 
 
 
 
1869d7a
2aa2fbe
f8ebe93
2aa2fbe
 
1869d7a
 
 
f8ebe93
 
1869d7a
 
 
 
 
 
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
import gradio as gr
import torch
import torchaudio
from torchaudio.transforms import Resample

# 定义模型路径
model_path = "https://huggingface.co/Tele-AI/TeleSpeech-ASR1.0/resolve/main/large.pt"

# 下载模型文件
torch.hub.download_url_to_file(model_path, 'large.pt')

# 加载模型
model = torch.jit.load('large.pt')
model.eval()

# 定义处理函数
def transcribe(audio):
    waveform, sample_rate = torchaudio.load(audio)
    resample = Resample(orig_freq=sample_rate, new_freq=16000)
    waveform = resample(waveform)
    
    input_values = waveform.unsqueeze(0)
    with torch.no_grad():
        logits = model(input_values)
    predicted_ids = torch.argmax(logits, dim=-1)
    transcription = tokenizer.decode(predicted_ids[0])
    return transcription

# 创建 Gradio 界面
iface = gr.Interface(
    fn=transcribe,
    inputs=gr.Audio(source="microphone", type="filepath"),
    outputs="text",
    title="TeleSpeech ASR",
    description="Upload an audio file or record your voice to transcribe speech to text using the TeleSpeech ASR model."
)

iface.launch()