Spaces:
Sleeping
Sleeping
neuralworm
commited on
Commit
•
39047c3
1
Parent(s):
9e1277b
Update app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,7 @@ import tempfile
|
|
7 |
from IPython.display import Audio, display
|
8 |
from typing import Tuple
|
9 |
|
10 |
-
def generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate, rpm):
|
11 |
# Parameters
|
12 |
sample_rate = 44100 # sample rate in Hz
|
13 |
num_samples = int(duration * sample_rate)
|
@@ -30,15 +30,15 @@ def generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate, rpm):
|
|
30 |
sos = signal.butter(1, [low, high], btype='band', output='sos')
|
31 |
pink_noise = signal.sosfilt(sos, pink_noise)
|
32 |
|
33 |
-
# Generate low-frequency rumble (optimized using sosfilt,
|
34 |
rumble_noise = np.random.normal(0, 1, num_samples)
|
35 |
sos = signal.butter(2, 0.005, btype='low', output='sos') # Lower cutoff for more rumble
|
36 |
-
rumble_noise = signal.sosfilt(sos, rumble_noise) *
|
37 |
|
38 |
-
# Generate high-frequency hiss (optimized using sosfilt)
|
39 |
hiss_noise = np.random.normal(0, 1, num_samples)
|
40 |
sos = signal.butter(2, 0.4, btype='high', output='sos')
|
41 |
-
hiss_noise = signal.sosfilt(sos, hiss_noise)
|
42 |
|
43 |
# Generate pops with varying loudness and frequency
|
44 |
num_pops = int(duration * pop_rate)
|
@@ -53,7 +53,7 @@ def generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate, rpm):
|
|
53 |
pop_data = signal.lfilter(b, a, pop_data)
|
54 |
|
55 |
# Combine the noises and pops
|
56 |
-
vinyl_sound = noise_ratio * (pink_noise +
|
57 |
|
58 |
# Apply wow and flutter
|
59 |
vinyl_sound = vinyl_sound * (1 + wow_flutter)
|
@@ -65,18 +65,11 @@ def generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate, rpm):
|
|
65 |
|
66 |
|
67 |
def convert_to_wav(data, sample_rate):
|
68 |
-
#
|
69 |
-
data /= np.max(np.abs(data))
|
70 |
-
|
71 |
-
# Save to a temporary .wav file
|
72 |
-
temp_file = tempfile.mktemp(suffix=".wav")
|
73 |
-
sf.write(temp_file, data, sample_rate)
|
74 |
-
|
75 |
-
return temp_file
|
76 |
|
77 |
|
78 |
-
def play_and_download_sound(noise_ratio, lowcut, highcut, duration, pop_rate, rpm):
|
79 |
-
data, sample_rate = generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate, rpm)
|
80 |
temp_file = convert_to_wav(data, sample_rate)
|
81 |
return temp_file, temp_file
|
82 |
|
@@ -89,7 +82,9 @@ iface = gr.Interface(
|
|
89 |
gr.inputs.Slider(minimum=20, maximum=20000, default=5000, step=10, label="Highcut Frequency (Hz)"),
|
90 |
gr.inputs.Slider(minimum=1, maximum=600, default=30, step=1, label="Duration (seconds)"),
|
91 |
gr.inputs.Slider(minimum=1, maximum=180, default=10, step=1, label="Pop Rate (pops per second)"),
|
92 |
-
gr.inputs.Number(default=33.33, label="RPM")
|
|
|
|
|
93 |
],
|
94 |
outputs=[
|
95 |
gr.outputs.Audio(type="numpy", label="Vinyl Sound"),
|
@@ -101,11 +96,11 @@ iface = gr.Interface(
|
|
101 |
"link.click();}</script>")
|
102 |
],
|
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, pop rate, and
|
105 |
examples=[
|
106 |
-
[0.0005, 300, 5000, 30, 10, 33.33], # Example for 33 1/3 RPM
|
107 |
-
[0.001, 500, 4000, 30, 50, 45.0], # Example for 45 RPM
|
108 |
-
[0.0008, 400, 6000, 20, 15, 78.0] # Example for 78 RPM
|
109 |
]
|
110 |
)
|
111 |
|
|
|
7 |
from IPython.display import Audio, display
|
8 |
from typing import Tuple
|
9 |
|
10 |
+
def generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate, rpm, rumble_level, hiss_level):
|
11 |
# Parameters
|
12 |
sample_rate = 44100 # sample rate in Hz
|
13 |
num_samples = int(duration * sample_rate)
|
|
|
30 |
sos = signal.butter(1, [low, high], btype='band', output='sos')
|
31 |
pink_noise = signal.sosfilt(sos, pink_noise)
|
32 |
|
33 |
+
# Generate low-frequency rumble (optimized using sosfilt, controllable level)
|
34 |
rumble_noise = np.random.normal(0, 1, num_samples)
|
35 |
sos = signal.butter(2, 0.005, btype='low', output='sos') # Lower cutoff for more rumble
|
36 |
+
rumble_noise = signal.sosfilt(sos, rumble_noise) * rumble_level # Adjust amplitude
|
37 |
|
38 |
+
# Generate high-frequency hiss (optimized using sosfilt, controllable level)
|
39 |
hiss_noise = np.random.normal(0, 1, num_samples)
|
40 |
sos = signal.butter(2, 0.4, btype='high', output='sos')
|
41 |
+
hiss_noise = signal.sosfilt(sos, hiss_noise) * hiss_level # Adjust amplitude
|
42 |
|
43 |
# Generate pops with varying loudness and frequency
|
44 |
num_pops = int(duration * pop_rate)
|
|
|
53 |
pop_data = signal.lfilter(b, a, pop_data)
|
54 |
|
55 |
# Combine the noises and pops
|
56 |
+
vinyl_sound = noise_ratio * (pink_noise + rumble_noise + hiss_noise) + (1 - noise_ratio) * pop_data
|
57 |
|
58 |
# Apply wow and flutter
|
59 |
vinyl_sound = vinyl_sound * (1 + wow_flutter)
|
|
|
65 |
|
66 |
|
67 |
def convert_to_wav(data, sample_rate):
|
68 |
+
# ... (This function remains the same) ...
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
69 |
|
70 |
|
71 |
+
def play_and_download_sound(noise_ratio, lowcut, highcut, duration, pop_rate, rpm, rumble_level, hiss_level):
|
72 |
+
data, sample_rate = generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate, rpm, rumble_level, hiss_level)
|
73 |
temp_file = convert_to_wav(data, sample_rate)
|
74 |
return temp_file, temp_file
|
75 |
|
|
|
82 |
gr.inputs.Slider(minimum=20, maximum=20000, default=5000, step=10, label="Highcut Frequency (Hz)"),
|
83 |
gr.inputs.Slider(minimum=1, maximum=600, default=30, step=1, label="Duration (seconds)"),
|
84 |
gr.inputs.Slider(minimum=1, maximum=180, default=10, step=1, label="Pop Rate (pops per second)"),
|
85 |
+
gr.inputs.Number(default=33.33, label="RPM"),
|
86 |
+
gr.inputs.Slider(minimum=0, maximum=0.2, default=0.1, step=0.01, label="Rumble Level"),
|
87 |
+
gr.inputs.Slider(minimum=0, maximum=0.1, default=0.05, step=0.01, label="Hiss Level")
|
88 |
],
|
89 |
outputs=[
|
90 |
gr.outputs.Audio(type="numpy", label="Vinyl Sound"),
|
|
|
96 |
"link.click();}</script>")
|
97 |
],
|
98 |
title="Vinyl Sound Generator",
|
99 |
+
description="Generate a synthetic vinyl sound using pink noise, rumble, hiss, and pops. Adjust the noise ratio, bandpass frequencies, duration, pop rate, RPM, rumble level, and hiss level to modify the sound.",
|
100 |
examples=[
|
101 |
+
[0.0005, 300, 5000, 30, 10, 33.33, 0.1, 0.05], # Example for 33 1/3 RPM
|
102 |
+
[0.001, 500, 4000, 30, 50, 45.0, 0.15, 0.08], # Example for 45 RPM
|
103 |
+
[0.0008, 400, 6000, 20, 15, 78.0, 0.2, 0.1] # Example for 78 RPM
|
104 |
]
|
105 |
)
|
106 |
|