File size: 1,164 Bytes
ffd5eab
f150fa4
ffd5eab
 
 
f150fa4
 
 
 
0a6ed9e
f150fa4
 
 
 
f7451c4
 
f150fa4
 
ffd5eab
 
f150fa4
ffd5eab
f150fa4
70da4fb
f150fa4
 
 
 
 
 
 
 
 
 
ffd5eab
 
 
 
 
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
40
import gradio as gr
import ast

model = gr.Interface.load("huggingface/pyannote/voice-activity-detection")

def format_inference(output):
    if output:
        timestamps = []
        for out in output:
            timestamps.append(f"Start: {out['start']}s; Stop: {out['stop']}s")
        return "\n".join(timestamps)
    else:
        return "No voice activity detected."

def inference(audio_file):
    output = model(audio_file)
    output_list = ast.literal_eval(output)
    return format_inference(output_list)

inputs = gr.inputs.Audio(label="Input Audio", type="filepath", source="microphone")
outputs = gr.outputs.Textbox(label="Voice timestamps", type="auto")
title = "Voice Activity Detection"
description = "Record or upload an audio file and detected voices will be timestamped."
examples = ['talk.wav', 'talk2.wav', 'silence.wav', ]
article = "pyannote, https://github.com/pyannote/pyannote-audio"

gr.Interface(inference, 
             inputs, 
             outputs, 
             title=title, 
             description=description, 
             article=article,
             examples=examples,
             theme="grass").launch(debug=True)