bartman081523
commited on
Commit
•
a4d4ae8
1
Parent(s):
400c3a4
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,6 @@
|
|
1 |
import numpy as np
|
2 |
-
import soundfile as sf
|
3 |
from scipy import signal
|
4 |
import gradio as gr
|
5 |
-
import shutil
|
6 |
-
import tempfile
|
7 |
|
8 |
def generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate):
|
9 |
# Parameters
|
@@ -50,56 +47,14 @@ def generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate):
|
|
50 |
|
51 |
return vinyl_sound.astype(np.float32), sample_rate
|
52 |
|
53 |
-
def convert_to_wav(data, sample_rate):
|
54 |
-
# Normalize to between -1 and 1
|
55 |
-
data /= np.max(np.abs(data))
|
56 |
-
|
57 |
-
# Save to a temporary .wav file
|
58 |
-
temp_file = tempfile.mktemp(suffix=".wav")
|
59 |
-
sf.write(temp_file, data, sample_rate)
|
60 |
-
|
61 |
-
return temp_file
|
62 |
-
|
63 |
-
def download_wav(noise_ratio, lowcut, highcut, duration, pop_rate):
|
64 |
-
data, sample_rate = generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate)
|
65 |
-
temp_file = convert_to_wav(data, sample_rate)
|
66 |
-
shutil.move(temp_file, "download.wav")
|
67 |
-
return "download.wav"
|
68 |
-
|
69 |
-
# HTML template for the custom UI
|
70 |
-
html_template = """
|
71 |
-
<div style="padding: 20px;">
|
72 |
-
<h2>Vinyl Sound Generator</h2>
|
73 |
-
<p>Adjust the parameters to generate a synthetic vinyl sound:</p>
|
74 |
-
<form method="POST" action="/" target="_blank">
|
75 |
-
<label for="noise_ratio">Noise Ratio:</label>
|
76 |
-
<input type="range" id="noise_ratio" name="noise_ratio" min="0" max="1" step="0.001" value="0.001">
|
77 |
-
<br><br>
|
78 |
-
<label for="lowcut">Lowcut Frequency (Hz):</label>
|
79 |
-
<input type="range" id="lowcut" name="lowcut" min="20" max="20000" step="10" value="300">
|
80 |
-
<br><br>
|
81 |
-
<label for="highcut">Highcut Frequency (Hz):</label>
|
82 |
-
<input type="range" id="highcut" name="highcut" min="20" max="20000" step="10" value="5000">
|
83 |
-
<br><br>
|
84 |
-
<label for="duration">Duration (seconds):</label>
|
85 |
-
<input type="range" id="duration" name="duration" min="1" max="60" step="1" value="10">
|
86 |
-
<br><br>
|
87 |
-
<label for="pop_rate">Pop Rate (pops per second):</label>
|
88 |
-
<input type="range" id="pop_rate" name="pop_rate" min="1" max="100" step="1" value="10">
|
89 |
-
<br><br>
|
90 |
-
<input type="submit" value="Generate Vinyl Sound">
|
91 |
-
</form>
|
92 |
-
</div>
|
93 |
-
"""
|
94 |
-
|
95 |
def vinyl_sound_app(noise_ratio, lowcut, highcut, duration, pop_rate):
|
96 |
data, sample_rate = generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate)
|
97 |
-
return data
|
98 |
|
99 |
iface = gr.Interface(
|
100 |
fn=vinyl_sound_app,
|
101 |
inputs=["slider", "slider", "slider", "slider", "slider"],
|
102 |
-
outputs="audio",
|
103 |
title="Vinyl Sound Generator",
|
104 |
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.",
|
105 |
examples=[
|
@@ -110,8 +65,7 @@ iface = gr.Interface(
|
|
110 |
allow_flagging=False,
|
111 |
layout="horizontal",
|
112 |
capture_session=True,
|
113 |
-
live=False
|
114 |
-
template=html_template
|
115 |
)
|
116 |
|
117 |
iface.launch(inbrowser=True)
|
|
|
1 |
import numpy as np
|
|
|
2 |
from scipy import signal
|
3 |
import gradio as gr
|
|
|
|
|
4 |
|
5 |
def generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate):
|
6 |
# Parameters
|
|
|
47 |
|
48 |
return vinyl_sound.astype(np.float32), sample_rate
|
49 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
50 |
def vinyl_sound_app(noise_ratio, lowcut, highcut, duration, pop_rate):
|
51 |
data, sample_rate = generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate)
|
52 |
+
return data, sample_rate
|
53 |
|
54 |
iface = gr.Interface(
|
55 |
fn=vinyl_sound_app,
|
56 |
inputs=["slider", "slider", "slider", "slider", "slider"],
|
57 |
+
outputs=["audio", "number"],
|
58 |
title="Vinyl Sound Generator",
|
59 |
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.",
|
60 |
examples=[
|
|
|
65 |
allow_flagging=False,
|
66 |
layout="horizontal",
|
67 |
capture_session=True,
|
68 |
+
live=False
|
|
|
69 |
)
|
70 |
|
71 |
iface.launch(inbrowser=True)
|