pearl6527 commited on
Commit
5a8a027
1 Parent(s): 24557db

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -0
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(share=False)