abidlabs HF Staff commited on
Commit
04f6e63
·
1 Parent(s): 33465c2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -0
app.py ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import numpy as np
2
+
3
+ import gradio as gr
4
+
5
+ notes = ["C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B"]
6
+
7
+
8
+ def generate_tone(note, octave, duration):
9
+ sr = 48000
10
+ a4_freq, tones_from_a4 = 440, 12 * (octave - 4) + (note - 9)
11
+ frequency = a4_freq * 2 ** (tones_from_a4 / 12)
12
+ duration = int(duration)
13
+ audio = np.linspace(0, duration, duration * sr)
14
+ audio = (20000 * np.sin(audio * (2 * np.pi * frequency))).astype(np.int16)
15
+ return sr, audio
16
+
17
+
18
+ demo = gr.Interface(
19
+ generate_tone,
20
+ [
21
+ gr.Dropdown(notes, type="index"),
22
+ gr.Slider(4, 6, step=1),
23
+ gr.Textbox(value=1, type="number", label="Duration in seconds"),
24
+ ],
25
+ "audio",
26
+ )
27
+
28
+ demo.launch()