Spaces:
Sleeping
Sleeping
NonameSsSs
commited on
Commit
•
23a1dca
1
Parent(s):
1a34e43
Create SimpleGradioexample.py
Browse files- SimpleGradioexample.py +24 -0
SimpleGradioexample.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
notes = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
|
5 |
+
|
6 |
+
def generate_tone(note, octave, duration):
|
7 |
+
sr = 48000
|
8 |
+
a4_freq, tones_from_a4 = 440, 12 * (octave - 4) + (note - 9)
|
9 |
+
frequency = a4_freq * 2 ** (tones_from_a4 / 12)
|
10 |
+
duration = int(duration)
|
11 |
+
audio = np.linspace(0, duration, duration * sr)
|
12 |
+
audio = (20000 * np.sin(audio * (2 * np.pi * frequency))).astype(np.int16)
|
13 |
+
|
14 |
+
demo = gr.Interface(
|
15 |
+
generate_tone,
|
16 |
+
[
|
17 |
+
gr.Dropdown(notes, type="index"),
|
18 |
+
gr.Slider(4, 6, step=1),
|
19 |
+
gr.Textbox(value="1", label="Duration in seconds"),
|
20 |
+
],
|
21 |
+
"audio",
|
22 |
+
)
|
23 |
+
if __name__ == "__main__":
|
24 |
+
demo.launch()
|