File size: 1,146 Bytes
96818bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
from funasr import AutoModel

# Initialize the FunASR model with the specified components
model = AutoModel(
    model="paraformer-zh", model_revision="v2.0.4",
    vad_model="fsmn-vad", vad_model_revision="v2.0.4",
    punc_model="ct-punc-c", punc_model_revision="v2.0.4",
    # Uncomment the next line to enable speaker verification/diarization
    # spk_model="cam++", spk_model_revision="v2.0.2",
)

def transcribe(audio_file):
    # Processing the input audio file
    result = model.generate(
        input=audio_file.name,
        batch_size_s=300, 
        hotword='魔搭'  # This is an example keyword; replace or remove as necessary
    )
    return result

# Gradio interface setup
interface = gr.Interface(
    fn=transcribe,
    inputs=gr.inputs.Audio(source="microphone", type="filepath", label="Upload your audio in Mandarin"),
    outputs="text",
    title="FunASR Speech Recognition",
    description="This Gradio app uses the paraformer-zh model for speech recognition with additional features like VAD and punctuation restoration."
)

# Run the Gradio app
if __name__ == "__main__":
    interface.launch()