Yassmen commited on
Commit
a72e07e
·
verified ·
1 Parent(s): c2a1fe9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -16
app.py CHANGED
@@ -8,7 +8,17 @@ from keras.models import Sequential
8
  from keras.layers import *
9
  from midi2audio import FluidSynth
10
  import shutil
 
11
 
 
 
 
 
 
 
 
 
 
12
 
13
  ####################### Music Generation Functions #######################
14
  def generate(seq_len,x):
@@ -181,14 +191,9 @@ if st.sidebar.button('Generate My Music'):
181
  with st.spinner('✨ Your music is now under processing... ✨'):
182
  time.sleep(10) # Simulate processing time
183
  generate(10, len_notes)
184
- if shutil.which("fluidsynth") is None:
185
- st.error("FluidSynth is not available. Unable to convert MIDI to audio.")
186
- else:
187
- fs = FluidSynth('font.sf2', sample_rate=44100)
188
- fs.midi_to_audio('test_output2.mid', 'output.wav')
189
- st.audio('output.wav')
190
- st.markdown("Here you are! You can download your music by right-clicking on the media player.")
191
-
192
  else:
193
  # Fallback to the default value if no selection is made
194
  with st.container():
@@ -197,11 +202,6 @@ if st.sidebar.button('Generate My Music'):
197
  with st.spinner('✨ Your music is now under processing... ✨'):
198
  time.sleep(10) # Simulate processing time
199
  generate(10, default_len_notes)
200
- if shutil.which("fluidsynth") is None:
201
- st.error("FluidSynth is not available. Unable to convert MIDI to audio.")
202
- else:
203
- fs = FluidSynth('font.sf2', sample_rate=44100)
204
- fs.midi_to_audio('test_output2.mid', 'output.wav')
205
- st.audio('output.wav')
206
- st.markdown("Here you are! You can download your music by right-clicking on the media player.")
207
-
 
8
  from keras.layers import *
9
  from midi2audio import FluidSynth
10
  import shutil
11
+ import pretty_midi
12
 
13
+ def midi_to_audio(midi_file, output_file):
14
+ # Load the MIDI file
15
+ midi_data = pretty_midi.PrettyMIDI(midi_file)
16
+
17
+ # Synthesize the audio from the MIDI data
18
+ audio_data = midi_data.synthesize()
19
+
20
+ # Save to a WAV file
21
+ pretty_midi.write(output_file, audio_data, fs=44100)
22
 
23
  ####################### Music Generation Functions #######################
24
  def generate(seq_len,x):
 
191
  with st.spinner('✨ Your music is now under processing... ✨'):
192
  time.sleep(10) # Simulate processing time
193
  generate(10, len_notes)
194
+ midi_to_audio('test_output2.mid', 'output.wav')
195
+ st.audio('output.wav')
196
+ st.markdown("Here you are! You can download your music by right-clicking on the media player.")
 
 
 
 
 
197
  else:
198
  # Fallback to the default value if no selection is made
199
  with st.container():
 
202
  with st.spinner('✨ Your music is now under processing... ✨'):
203
  time.sleep(10) # Simulate processing time
204
  generate(10, default_len_notes)
205
+ midi_to_audio('test_output2.mid', 'output.wav')
206
+ st.audio('output.wav')
207
+ st.markdown("Here you are! You can download your music by right-clicking on the media player.")