Kvikontent commited on
Commit
5569dfb
·
1 Parent(s): 5108790

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -8
app.py CHANGED
@@ -5,12 +5,23 @@ import soundfile as sf
5
  from PIL import Image
6
  from io import BytesIO
7
 
8
- 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):
9
- env = np.ones(220500) # Sample shape for the envelope
10
- t = np.linspace(0, duration, 220500, endpoint=False) # Sample shape for the time array
11
- frequencies = np.random.uniform(100, 1000, 220500) # Sample shape for the frequencies
12
- vibrato = np.random.uniform(-0.005, 0.005, 220500) # Sample shape for the vibrato
13
- audio_data = env * amplitude_modulation * np.sin(2 * np.pi * (frequencies + vibrato) * t) # Sample audio generation calculation
 
 
 
 
 
 
 
 
 
 
 
14
  return audio_data, sample_rate
15
 
16
  def main():
@@ -22,8 +33,6 @@ def main():
22
  image = Image.open(uploaded_file)
23
  st.image(image, caption='Uploaded PNG image', use_column_width=True)
24
 
25
- st.write("Audio will be generated with default parameters.")
26
-
27
  if st.button("Generate Audio"):
28
  array = np.array(image)
29
  audio_data, sample_rate = process_color_to_audio(array)
 
5
  from PIL import Image
6
  from io import BytesIO
7
 
8
+ def process_color_to_audio(array, sample_rate=44100, duration=5):
9
+ r_mean = np.mean(array[:, :, 0]) / 255.0
10
+ g_mean = np.mean(array[:, :, 1]) / 255.0
11
+ b_mean = np.mean(array[:, :, 2]) / 255.0
12
+
13
+ min_freq = 100
14
+ max_freq = 1000
15
+
16
+ r_freq = min_freq + (1 - r_mean) * (max_freq - min_freq)
17
+ g_freq = min_freq + (1 - g_mean) * (max_freq - min_freq)
18
+ b_freq = min_freq + (1 - b_mean) * (max_freq - min_freq)
19
+
20
+ t = np.linspace(0, duration, int(sample_rate * duration), endpoint=False)
21
+
22
+ audio_data = np.sin(2 * np.pi * r_freq * t) + np.sin(2 * np.pi * g_freq * t) + np.sin(2 * np.pi * b_freq * t)
23
+ audio_data /= np.max(np.abs(audio_data))
24
+
25
  return audio_data, sample_rate
26
 
27
  def main():
 
33
  image = Image.open(uploaded_file)
34
  st.image(image, caption='Uploaded PNG image', use_column_width=True)
35
 
 
 
36
  if st.button("Generate Audio"):
37
  array = np.array(image)
38
  audio_data, sample_rate = process_color_to_audio(array)