Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -1,28 +1,28 @@
|
|
1 |
-
from transformers import pipeline
|
2 |
-
|
3 |
import gradio as gr
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
def
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import matplotlib.pyplot as plt
|
4 |
+
|
5 |
+
# This function returns the waveform data to be displayed
|
6 |
+
def record_audio(audio):
|
7 |
+
if audio is not None:
|
8 |
+
data = audio[0] # Extract the audio data from the tuple
|
9 |
+
sample_rate = audio[1] # Extract the sample rate
|
10 |
+
|
11 |
+
# Create a mm plot
|
12 |
+
plt.figure(figsize=(10, 4))
|
13 |
+
plt.plot(data)
|
14 |
+
plt.title("Real-Time Audio Waveform")
|
15 |
+
plt.xlabel("Sample Number")
|
16 |
+
plt.ylabel("Amplitude")
|
17 |
+
plt.grid(True)
|
18 |
+
return plt
|
19 |
+
|
20 |
+
# Define the Gradio interface
|
21 |
+
gr.Interface(
|
22 |
+
fn=record_audio,
|
23 |
+
inputs=gr.Audio(type="numpy"), # Capture audio as numpy array
|
24 |
+
outputs="plot", # Output the waveform plot
|
25 |
+
live=True, # Enable real-time recording
|
26 |
+
title="Real-Time Audio Recording",
|
27 |
+
description="Record audio in real time and view the waveform."
|
28 |
+
).launch()
|