File size: 589 Bytes
173f818
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import gradio as gr
import numpy as np
from datasets import load_dataset

speech_commands = load_dataset("speech_commands", "v0.02", split="test")
id2label = speech_commands.features["label"].int2str


def generate_audio():
    example = speech_commands.shuffle()[0]
    audio = example["audio"]
    return (audio["sampling_rate"], (audio["array"] * 32_767).astype(np.int16)), id2label(example["label"])


with gr.Blocks() as demo:
    with gr.Column():
        for _ in range(4):
            audio, label = generate_audio()
            output = gr.Audio(audio, label=label)

demo.launch()