Spaces:
Runtime error
Runtime error
Commit
•
c31cd65
1
Parent(s):
1fd1f0c
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy as np
|
2 |
+
import gradio as gr
|
3 |
+
|
4 |
+
def generate_tone(note, octave, duration):
|
5 |
+
sampling_rate = 48000
|
6 |
+
a4_freq, tones_from_a4 = 440, 12 * (octave - 4) + (note - 9)
|
7 |
+
frequency = a4_freq * 2 ** (tones_from_a4 / 12)
|
8 |
+
audio = np.linspace(0, int(duration), int(duration) * sampling_rate)
|
9 |
+
audio = (20000 * np.sin(audio * (2 * np.pi * frequency))).astype(np.int16)
|
10 |
+
return sampling_rate, audio
|
11 |
+
|
12 |
+
gr.Interface(
|
13 |
+
generate_tone,
|
14 |
+
[
|
15 |
+
gr.inputs.Dropdown(["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"], type="index"),
|
16 |
+
gr.inputs.Slider(4, 6, step=1),
|
17 |
+
gr.inputs.Textbox(type="number", default=1, label="Duration in seconds"),
|
18 |
+
],
|
19 |
+
"audio",
|
20 |
+
title="Generate a Musical Tone!"
|
21 |
+
).launch()
|