Spaces:
Runtime error
Runtime error
Commit
·
5074feb
1
Parent(s):
1203e14
Update app.py
Browse files
app.py
CHANGED
@@ -5,18 +5,9 @@ import soundfile as sf
|
|
5 |
from PIL import Image
|
6 |
from io import BytesIO
|
7 |
|
8 |
-
# Process the color information to create audio frequencies with extended parameters
|
9 |
-
def process_color_to_audio(array, sample_rate=44100, duration=5, **kwargs):
|
10 |
-
amplitude_modulation = kwargs.get('amplitude_modulation', 1.0)
|
11 |
-
frequency_modulation = kwargs.get('frequency_modulation', 0.0)
|
12 |
-
harmonic_content = kwargs.get('harmonic_content', 1.0)
|
13 |
-
attack_time = kwargs.get('attack_time', 0.005)
|
14 |
-
decay_time = kwargs.get('decay_time', 0.1)
|
15 |
-
sustain_level = kwargs.get('sustain_level', 0.7)
|
16 |
-
release_time = kwargs.get('release_time', 0.3)
|
17 |
-
vibrato_freq = kwargs.get('vibrato_freq', 5.0)
|
18 |
-
vibrato_depth = kwargs.get('vibrato_depth', 0.005)
|
19 |
|
|
|
|
|
20 |
normalized_colors = array / 255.0
|
21 |
brightness = np.mean(normalized_colors, axis=(0, 1))
|
22 |
brightness = brightness ** harmonic_content
|
@@ -43,20 +34,15 @@ def main():
|
|
43 |
image = Image.open(uploaded_file)
|
44 |
st.image(image, caption='Uploaded PNG image', use_column_width=True)
|
45 |
|
46 |
-
|
47 |
-
amplitude_modulation = st.slider("Amplitude Modulation", 0.0, 2.0, 1.0, 0.1)
|
48 |
-
frequency_modulation = st.slider("Frequency Modulation", -1.0, 1.0, 0.0, 0.1)
|
49 |
-
harmonic_content = st.slider("Harmonic Content", 0.1, 2.0, 1.0, 0.1)
|
50 |
-
attack_time = st.slider("Attack Time", 0.001, 0.1, 0.005, 0.001)
|
51 |
-
decay_time = st.slider("Decay Time", 0.01, 0.5, 0.1, 0.01)
|
52 |
-
sustain_level = st.slider("Sustain Level", 0.1, 1.0, 0.7, 0.1)
|
53 |
-
release_time = st.slider("Release Time", 0.1, 1.0, 0.3, 0.1)
|
54 |
-
vibrato_freq = st.slider("Vibrato Frequency", 0.1, 10.0, 5.0, 0.1)
|
55 |
-
vibrato_depth = st.slider("Vibrato Depth", 0.001, 0.01, 0.005, 0.001)
|
56 |
|
57 |
if st.button("Generate Audio"):
|
58 |
array = np.array(image)
|
59 |
-
audio_data, sample_rate = process_color_to_audio(array
|
60 |
-
|
61 |
-
|
62 |
-
|
|
|
|
|
|
|
|
|
|
5 |
from PIL import Image
|
6 |
from io import BytesIO
|
7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
|
9 |
+
# Process the color information to create audio frequencies with extended parameters
|
10 |
+
def process_color_to_audio(array, sample_rate=44100, duration=5, amplitude_modulation=1.0, frequency_modulation=0.0, harmonic_content=1.0, attack_time=0.005, decay_time=0.1, sustain_level=0.7, release_time=0.3, vibrato_freq=5.0, vibrato_depth=0.005):
|
11 |
normalized_colors = array / 255.0
|
12 |
brightness = np.mean(normalized_colors, axis=(0, 1))
|
13 |
brightness = brightness ** harmonic_content
|
|
|
34 |
image = Image.open(uploaded_file)
|
35 |
st.image(image, caption='Uploaded PNG image', use_column_width=True)
|
36 |
|
37 |
+
st.write("Audio will be generated with default parameters.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
if st.button("Generate Audio"):
|
40 |
array = np.array(image)
|
41 |
+
audio_data, sample_rate = process_color_to_audio(array)
|
42 |
+
|
43 |
+
with BytesIO() as output:
|
44 |
+
sf.write(output, audio_data, sample_rate, format='wav')
|
45 |
+
st.audio(output.getvalue(), format='audio/wav')
|
46 |
+
|
47 |
+
if __name__ == '__main__':
|
48 |
+
main()
|