yiwv commited on
Commit
4f0fbd3
1 Parent(s): 4a09570

not use fluidsynth for haggingface space

Browse files
Files changed (2) hide show
  1. .gitignore +2 -0
  2. app.py +8 -8
.gitignore CHANGED
@@ -1,3 +1,5 @@
1
 
2
  generated_music.mid
3
  output.wav
 
 
 
1
 
2
  generated_music.mid
3
  output.wav
4
+
5
+ flagged
app.py CHANGED
@@ -4,7 +4,7 @@ import numpy as np
4
  import pretty_midi
5
  import tensorflow as tf
6
  import soundfile as sf
7
- import fluidsynth
8
  import subprocess
9
  from huggingface_hub import from_pretrained_keras
10
 
@@ -39,9 +39,9 @@ def predict_next_note(notes, keras_model, temperature=1.0):
39
 
40
 
41
 
42
- def convert_midi_to_wav(midi_path, wav_path, soundfont_path):
43
- cmd = ["fluidsynth", "-ni", soundfont_path, midi_path, "-F", wav_path, "-r", "44100"]
44
- subprocess.run(cmd)
45
 
46
 
47
  def notes_to_midi(notes, out_file, instrument_name):
@@ -113,10 +113,10 @@ def generate_music(input_text, instrument_name="Acoustic Grand Piano"):
113
  output_file_name = "generated_music.mid"
114
  notes_to_midi(generated_notes_array, output_file_name, instrument_name)
115
 
116
- try:
117
- convert_midi_to_wav(output_file_name, 'output.wav', "GeneralUserGS.sf2")
118
- except:
119
- convert_midi_to_wav_with_pretty_midi(output_file_name, 'output.wav')
120
 
121
  return 'output.wav'
122
 
 
4
  import pretty_midi
5
  import tensorflow as tf
6
  import soundfile as sf
7
+ # import fluidsynth
8
  import subprocess
9
  from huggingface_hub import from_pretrained_keras
10
 
 
39
 
40
 
41
 
42
+ # def convert_midi_to_wav(midi_path, wav_path, soundfont_path):
43
+ # cmd = ["fluidsynth", "-ni", soundfont_path, midi_path, "-F", wav_path, "-r", "44100"]
44
+ # subprocess.run(cmd)
45
 
46
 
47
  def notes_to_midi(notes, out_file, instrument_name):
 
113
  output_file_name = "generated_music.mid"
114
  notes_to_midi(generated_notes_array, output_file_name, instrument_name)
115
 
116
+ # try:
117
+ # convert_midi_to_wav(output_file_name, 'output.wav', "GeneralUserGS.sf2")
118
+ # except:
119
+ convert_midi_to_wav_with_pretty_midi(output_file_name, 'output.wav')
120
 
121
  return 'output.wav'
122