jotrigo commited on
Commit
6610633
1 Parent(s): 77c5baa

Upload nota.py

Browse files
Files changed (1) hide show
  1. nota.py +25 -0
nota.py ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+
7
+ def generate_tone(note, octave, duration):
8
+ sr = 48000
9
+ a4_freq, tones_from_a4 = 440, 12 * (octave - 4) + (note - 9)
10
+ frequency = a4_freq * 2 ** (tones_from_a4 / 12)
11
+ duration = int(duration)
12
+ audio = np.linspace(0, duration, duration * sr)
13
+ audio = (20000 * np.sin(audio * (2 * np.pi * frequency))).astype(np.int16)
14
+ return (sr, audio)
15
+
16
+
17
+ gr.Interface(
18
+ generate_tone,
19
+ [
20
+ gr.Dropdown(notes, type="index"),
21
+ gr.Slider(minimum=4, maximum=6, step=1),
22
+ gr.Textbox(type="text", value=1, label="Duration in seconds"),
23
+ ],
24
+ "audio",
25
+ ).launch()