keshavbhandari commited on
Commit
5749979
β€’
1 Parent(s): 2f25933

testing midi file

Browse files
Files changed (4) hide show
  1. Dockerfile_archived.txt β†’ Dockerfile +0 -0
  2. app.py +25 -10
  3. example.mid +0 -0
  4. setup.txt +19 -1
Dockerfile_archived.txt β†’ Dockerfile RENAMED
File without changes
app.py CHANGED
@@ -3,22 +3,37 @@ import spaces
3
  import librosa
4
  import soundfile as sf
5
  import wavio
6
-
7
  import subprocess
8
 
9
- # Run the apt-get command
10
- try:
11
- subprocess.run(["apt-get", "install", "-y", "fluidsynth"], check=True)
12
- print("FluidSynth installed successfully")
13
- except subprocess.CalledProcessError as e:
14
- print(f"An error occurred while installing FluidSynth: {e}")
15
-
16
- import fluidsynth
 
 
 
 
 
 
 
 
 
 
 
17
 
18
  # @spaces.GPU(duration=120)
19
  def gradio_generate(prompt, temperature):
 
 
 
 
20
  # Get example audio file
21
- filename = librosa.ex('trumpet')
22
  output_wave, samplerate = sf.read(filename, dtype='float32')
23
  output_filename = "temp.wav"
24
  wavio.write(output_filename, output_wave, rate=16000, sampwidth=2)
 
3
  import librosa
4
  import soundfile as sf
5
  import wavio
6
+ import os
7
  import subprocess
8
 
9
+
10
+ def save_wav(filepath):
11
+ # Extract the directory and the stem (filename without extension)
12
+ directory = os.path.dirname(filepath)
13
+ stem = os.path.splitext(os.path.basename(filepath))[0]
14
+
15
+ # Construct the full paths for MIDI and WAV files
16
+ midi_filepath = os.path.join(directory, f"{stem}.mid")
17
+ wav_filepath = os.path.join(directory, f"{stem}.wav")
18
+
19
+ # Run the fluidsynth command to convert MIDI to WAV
20
+ process = subprocess.Popen(
21
+ f"fluidsynth -r 48000 soundfont.sf -g 1.0 --quiet --no-shell {midi_filepath} -T wav -F {wav_filepath} > /dev/null",
22
+ shell=True
23
+ )
24
+ process.wait()
25
+
26
+ return wav_filepath
27
+
28
 
29
  # @spaces.GPU(duration=120)
30
  def gradio_generate(prompt, temperature):
31
+ # Convert midi to wav
32
+ filename = "example.mid"
33
+ save_wav(filename)
34
+ filename = filename.replace(".mid", ".wav")
35
  # Get example audio file
36
+ # filename = librosa.ex('trumpet')
37
  output_wave, samplerate = sf.read(filename, dtype='float32')
38
  output_filename = "temp.wav"
39
  wavio.write(output_filename, output_wave, rate=16000, sampwidth=2)
example.mid ADDED
Binary file (14 kB). View file
 
setup.txt CHANGED
@@ -4,4 +4,22 @@ install_requires = []
4
  if os.path.isfile(requirement_path):
5
  with open(requirement_path) as f:
6
  install_requires = f.read().splitlines()
7
- setup(name="mypackage", install_requires=install_requires, [...])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4
  if os.path.isfile(requirement_path):
5
  with open(requirement_path) as f:
6
  install_requires = f.read().splitlines()
7
+ setup(name="mypackage", install_requires=install_requires, [...])
8
+
9
+
10
+ import subprocess
11
+
12
+ # Command to download the soundfont file
13
+ command = "wget -O soundfont.sf https://www.dropbox.com/scl/fi/t8gou8stesm42sc559nzu/DoreMarkYamahaS6-v1.6.sf2?rlkey=28ecl63kkjjmwxrkd6hnzsq8f&dl=0"
14
+
15
+ # Run the command
16
+ subprocess.run(command, shell=True, check=True)
17
+
18
+
19
+ import subprocess
20
+ # Run the apt-get command
21
+ try:
22
+ subprocess.run(["apt-get", "install", "-y", "fluidsynth"], check=True)
23
+ print("FluidSynth installed successfully")
24
+ except subprocess.CalledProcessError as e:
25
+ print(f"An error occurred while installing FluidSynth: {e}")