bartman081523
commited on
Commit
•
8432c80
1
Parent(s):
0f6f036
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,9 @@ import numpy as np
|
|
2 |
import soundfile as sf
|
3 |
from scipy import signal
|
4 |
import gradio as gr
|
|
|
5 |
import tempfile
|
|
|
6 |
|
7 |
def generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate):
|
8 |
# Parameters
|
@@ -59,17 +61,18 @@ def convert_to_wav(data, sample_rate):
|
|
59 |
|
60 |
return temp_file
|
61 |
|
62 |
-
def
|
63 |
data, sample_rate = generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate)
|
64 |
-
|
65 |
|
66 |
-
def
|
67 |
-
data
|
68 |
-
|
69 |
-
|
|
|
70 |
|
71 |
iface = gr.Interface(
|
72 |
-
fn=
|
73 |
inputs=[
|
74 |
gr.inputs.Slider(minimum=0, maximum=1, default=0.001, step=0.001, label="Noise Ratio"),
|
75 |
gr.inputs.Slider(minimum=20, maximum=20000, default=300, step=10, label="Lowcut Frequency (Hz)"),
|
@@ -78,9 +81,8 @@ iface = gr.Interface(
|
|
78 |
gr.inputs.Slider(minimum=1, maximum=100, default=10, step=1, label="Pop Rate (pops per second)")
|
79 |
],
|
80 |
outputs=[
|
81 |
-
gr.outputs.
|
82 |
-
gr.outputs.Button(label="Download Vinyl Sound")
|
83 |
-
gr.outputs.HTML(label="Play Vinyl Sound")
|
84 |
],
|
85 |
title="Vinyl Sound Generator",
|
86 |
description="Generate a synthetic vinyl sound using pink noise, rumble, hiss, and pops. Adjust the noise ratio, bandpass frequencies, duration, and pop rate to modify the sound.",
|
@@ -91,11 +93,4 @@ iface = gr.Interface(
|
|
91 |
]
|
92 |
)
|
93 |
|
94 |
-
iface.layout = "vertical"
|
95 |
-
|
96 |
-
def download_sound(noise_ratio, lowcut, highcut, duration, pop_rate):
|
97 |
-
data, sample_rate = generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate)
|
98 |
-
temp_file = convert_to_wav(data, sample_rate)
|
99 |
-
return temp_file
|
100 |
-
|
101 |
iface.launch()
|
|
|
2 |
import soundfile as sf
|
3 |
from scipy import signal
|
4 |
import gradio as gr
|
5 |
+
import shutil
|
6 |
import tempfile
|
7 |
+
from IPython.display import Audio, display
|
8 |
|
9 |
def generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate):
|
10 |
# Parameters
|
|
|
61 |
|
62 |
return temp_file
|
63 |
|
64 |
+
def play_sound(noise_ratio, lowcut, highcut, duration, pop_rate):
|
65 |
data, sample_rate = generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate)
|
66 |
+
display(Audio(data, rate=sample_rate))
|
67 |
|
68 |
+
def download_sound(noise_ratio, lowcut, highcut, duration, pop_rate):
|
69 |
+
data, sample_rate = generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate)
|
70 |
+
temp_file = convert_to_wav(data, sample_rate)
|
71 |
+
shutil.move(temp_file, "download.wav")
|
72 |
+
return "download.wav"
|
73 |
|
74 |
iface = gr.Interface(
|
75 |
+
fn=None,
|
76 |
inputs=[
|
77 |
gr.inputs.Slider(minimum=0, maximum=1, default=0.001, step=0.001, label="Noise Ratio"),
|
78 |
gr.inputs.Slider(minimum=20, maximum=20000, default=300, step=10, label="Lowcut Frequency (Hz)"),
|
|
|
81 |
gr.inputs.Slider(minimum=1, maximum=100, default=10, step=1, label="Pop Rate (pops per second)")
|
82 |
],
|
83 |
outputs=[
|
84 |
+
gr.outputs.Button(label="Play Vinyl Sound", type="button", callback=play_sound),
|
85 |
+
gr.outputs.Button(label="Download Vinyl Sound", type="button", callback=download_sound)
|
|
|
86 |
],
|
87 |
title="Vinyl Sound Generator",
|
88 |
description="Generate a synthetic vinyl sound using pink noise, rumble, hiss, and pops. Adjust the noise ratio, bandpass frequencies, duration, and pop rate to modify the sound.",
|
|
|
93 |
]
|
94 |
)
|
95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
96 |
iface.launch()
|