bartman081523 commited on
Commit
e1bc836
1 Parent(s): cae93e7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -69,6 +69,12 @@ def play_and_download_sound(noise_ratio, lowcut, highcut, duration, pop_rate):
69
 
70
  return audio
71
 
 
 
 
 
 
 
72
  iface = gr.Interface(
73
  fn=play_and_download_sound,
74
  inputs=[
@@ -80,7 +86,12 @@ iface = gr.Interface(
80
  ],
81
  outputs=[
82
  gr.outputs.Audio(type="numpy", label="Vinyl Sound"),
83
- gr.outputs.Button(label="Download Vinyl Sound", type="button", callback=download_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.",
@@ -92,4 +103,3 @@ iface = gr.Interface(
92
  )
93
 
94
  iface.launch()
95
-
 
69
 
70
  return audio
71
 
72
+ def download_sound(noise_ratio, lowcut, highcut, duration, pop_rate):
73
+ data, sample_rate = generate_vinyl_sound(noise_ratio, lowcut, highcut, duration, pop_rate)
74
+ temp_file = convert_to_wav(data, sample_rate)
75
+ shutil.move(temp_file, "download.wav")
76
+ return "download.wav"
77
+
78
  iface = gr.Interface(
79
  fn=play_and_download_sound,
80
  inputs=[
 
86
  ],
87
  outputs=[
88
  gr.outputs.Audio(type="numpy", label="Vinyl Sound"),
89
+ gr.outputs.HTML("<button onclick='downloadSound()'>Download Vinyl Sound</button>"
90
+ "<script>function downloadSound(){"
91
+ "var link = document.createElement('a');"
92
+ "link.href = '/download';"
93
+ "link.download = 'vinyl_sound.wav';"
94
+ "link.click();}</script>")
95
  ],
96
  title="Vinyl Sound Generator",
97
  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.",
 
103
  )
104
 
105
  iface.launch()