renee127 commited on
Commit
939279a
·
1 Parent(s): 1b11bd4

Create app.py

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