bartman081523 commited on
Commit
0f6f036
·
1 Parent(s): 1399f53

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -8
app.py CHANGED
@@ -61,13 +61,11 @@ def convert_to_wav(data, sample_rate):
61
 
62
  def vinyl_sound_app(noise_ratio, lowcut, highcut, duration, pop_rate):
63
  data, sample_rate = generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate)
64
- temp_file = convert_to_wav(data, sample_rate)
65
- return temp_file
66
 
67
- def play_sound(file_path):
68
- with open(file_path, "rb") as f:
69
- audio_data = f.read()
70
- audio_html = f'<audio controls src="data:audio/wav;base64,{audio_data.encode("base64")}"></audio>'
71
  return audio_html
72
 
73
  iface = gr.Interface(
@@ -80,8 +78,9 @@ iface = gr.Interface(
80
  gr.inputs.Slider(minimum=1, maximum=100, default=10, step=1, label="Pop Rate (pops per second)")
81
  ],
82
  outputs=[
83
- gr.outputs.HTML(label="Generated Vinyl Sound", type="html", html=True),
84
- gr.outputs.File(label="Download Vinyl Sound", type="auto", convert=convert_to_wav)
 
85
  ],
86
  title="Vinyl Sound Generator",
87
  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.",
@@ -92,4 +91,11 @@ iface = gr.Interface(
92
  ]
93
  )
94
 
 
 
 
 
 
 
 
95
  iface.launch()
 
61
 
62
  def vinyl_sound_app(noise_ratio, lowcut, highcut, duration, pop_rate):
63
  data, sample_rate = generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate)
64
+ return data
 
65
 
66
+ def play_sound(data):
67
+ data /= np.max(np.abs(data))
68
+ audio_html = f'<audio controls><source src="data:audio/wav;base64,{sf.write(data, "temp.wav", sample_rate)}" type="audio/wav"></audio>'
 
69
  return audio_html
70
 
71
  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.HTML(label="Generated Vinyl Sound", html=True),
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
  ]
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()