osanseviero commited on
Commit
c476c73
·
0 Parent(s):

Add initial examples

Browse files
__pycache__/app.cpython-310.pyc ADDED
Binary file (2.82 kB). View file
 
app.py ADDED
@@ -0,0 +1,85 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import matplotlib.pyplot as plt
3
+ import numpy as np
4
+ import matplotlib.pyplot as plt
5
+ from scipy.io.wavfile import write
6
+
7
+ audios = [
8
+ ["Book Example", "speaker"],
9
+ ["Swoosh", "swoosh"],
10
+ ["Knocking", "knocking"],
11
+ ["Forest", "forest"],
12
+ ["Evil Laugh", "evil-laugh"],
13
+ ["Morning", "morning"],
14
+ ["Cinematic", "cinematic"],
15
+ ]
16
+
17
+
18
+
19
+ with gr.Blocks() as demo:
20
+ with gr.Tab("Waveforms"):
21
+ gr.Markdown("""## Waveforms
22
+
23
+ In this section, we'll look into the waveforms of multiple audios.
24
+
25
+ """)
26
+ for title, path in audios:
27
+ with gr.Row():
28
+ with gr.Column(scale=1):
29
+ gr.Markdown(f"### {title}")
30
+ with gr.Column(scale=5):
31
+ waveform = gr.Image(value=f"{path}/waveform.png")
32
+ with gr.Column(scale=5):
33
+ video = gr.Video(value=f"{path}/waveform_video.mp4")
34
+
35
+ with gr.Tab("Understanding Frequencies"):
36
+ gr.Markdown("""## Understanding Frequencies
37
+ """)
38
+ freq = gr.Slider(0, 300, step=20, value=40, label="Frequency")
39
+ freq2 = gr.Slider(0, 30, step=5, value=0, label="Second Frequency")
40
+ amplitude = gr.Slider(0.05, 1, step=0.05, value=1, label="Amplitude")
41
+
42
+ audio = gr.Audio()
43
+ with gr.Row():
44
+ plots = gr.Plot(label="Results")
45
+ with gr.Row():
46
+ button = gr.Button(label="Create")
47
+
48
+ # https://github.com/gradio-app/gradio/issues/5469
49
+ @gr.on(inputs=[freq, freq2, amplitude], outputs=[audio, plots])
50
+ def plot_sine(freq, freq2, a):
51
+ sr = 1000 # samples per second
52
+ ts = 1.0/sr # sampling interval
53
+ t = np.arange(0, 1, ts) # time vector
54
+ data = a * np.sin(2 * np.pi * freq * t) + a * np.sin(2 * np.pi * freq2 * t)
55
+ write("test.wav", sr, data)
56
+
57
+ fig, axes = plt.subplots(nrows=2, ncols=1, sharex=False)
58
+ ax_waveform = axes[0]
59
+ ax_spectrum = axes[1]
60
+
61
+ ax_waveform.plot(t, data)
62
+ ax_waveform.set_title(f'Sine wave with frequency {freq} and amplitude {a}')
63
+ ax_waveform.set_xlabel('Time )s)')
64
+ ax_waveform.set_ylabel('Amplitude')
65
+ ax_waveform.set_title("Time domain of the signal")
66
+
67
+ X = np.fft.fft(data)
68
+ N = len(X)
69
+ n = np.arange(N)
70
+ T = N/sr
71
+ freq = n/T
72
+ ax_spectrum.set_xlim((0,300))
73
+ ax_spectrum.stem(freq, np.abs(X), 'r', \
74
+ markerfmt=" ", basefmt="-b")
75
+ ax_spectrum.set_xlabel("Frequency (Hz)")
76
+ ax_spectrum.set_title("Frequency domain of the signal")
77
+
78
+ fig.tight_layout()
79
+ fig.savefig('foo.png')
80
+ return "test.wav", fig
81
+ button.click(plot_sine, inputs=[freq, freq2, amplitude], outputs=[audio, plots])
82
+
83
+
84
+ if __name__ == '__main__':
85
+ demo.launch(debug=True)
cinematic/audio.mp3 ADDED
Binary file (235 kB). View file
 
cinematic/waveform.png ADDED
cinematic/waveform_video.mp4 ADDED
Binary file (166 kB). View file
 
evil-laugh/audio.mp3 ADDED
Binary file (115 kB). View file
 
evil-laugh/waveform.png ADDED
evil-laugh/waveform_video.mp4 ADDED
Binary file (62.5 kB). View file
 
foo.png ADDED
forest/audio.mp3 ADDED
Binary file (482 kB). View file
 
forest/waveform.png ADDED
forest/waveform_video.mp4 ADDED
Binary file (204 kB). View file
 
knocking/audio.mp3 ADDED
Binary file (46.8 kB). View file
 
knocking/waveform.png ADDED
knocking/waveform_video.mp4 ADDED
Binary file (28.4 kB). View file
 
morning/audio.mp3 ADDED
Binary file (449 kB). View file
 
morning/waveform.png ADDED
morning/waveform_video.mp4 ADDED
Binary file (184 kB). View file
 
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ scipy
speaker/_tmp_gradio_90240504697c6f4f6efcdfdfebfd674e574adde4_test.wav ADDED
Binary file (8.06 kB). View file
 
speaker/_tmp_gradio_a75300d3e102dcdfcabf64b3165c9d9559b236d6_test.wav ADDED
Binary file (80.1 kB). View file
 
speaker/audio.wav ADDED
Binary file (160 kB). View file
 
speaker/waveform.png ADDED
speaker/waveform_video.mp4 ADDED
Binary file (72.5 kB). View file
 
swoosh/audio.mp3 ADDED
Binary file (130 kB). View file
 
swoosh/waveform.png ADDED
swoosh/waveform_video.mp4 ADDED
Binary file (58.1 kB). View file
 
test.wav ADDED
Binary file (8.06 kB). View file