0

I get a FileNotFoundError error while trying to call midi2audio. I am working with Python 3.6 - Anaconda - Windows 10. My .py file is in the same folder, together with the .sf2 and the .mid files. My code is:

from midiutil.MidiFile import MIDIFile

from midi2audio import FluidSynth
soundfont = 'C:\\Users\\matteo.stante\\Documents\\4_Python_Scripts\\experiments\\JR_sax.sf2'

filepath = 'C:\\Users\\matteo.stante\\Documents\\4_Python_Scripts\\experiments\\input.mid'

fs = FluidSynth(sound_font=soundfont, sample_rate=22050)

fs.midi_to_audio(filepath, 'output.wav')

I would expect a .wav file in my folder being created. I get instead:

runfile('C:/Users/matteo.stante/Documents/4_Python_Scripts/experiments/AudioBello.py', wdir='C:/Users/matteo.stante/Documents/4_Python_Scripts/experiments')
Traceback (most recent call last):

  File "<ipython-input-43-cdda6b922219>", line 1, in <module>
    runfile('C:/Users/matteo.stante/Documents/4_Python_Scripts/experiments/AudioBello.py', wdir='C:/Users/matteo.stante/Documents/4_Python_Scripts/experiments')

  File "C:\Users\matteo.stante\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 705, in runfile
    execfile(filename, namespace)

  File "C:\Users\matteo.stante\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 102, in execfile
    exec(compile(f.read(), filename, 'exec'), namespace)

  File "C:/Users/matteo.stante/Documents/4_Python_Scripts/experiments/AudioBello.py", line 26, in <module>
    fs.midi_to_audio(filepath, 'output.wav')

  File "C:\Users\matteo.stante\AppData\Local\Continuum\anaconda3\lib\site-packages\midi2audio.py", line 46, in midi_to_audio
    subprocess.call(['fluidsynth', '-ni', self.sound_font, midi_file, '-F', audio_file, '-r', str(self.sample_rate)])

  File "C:\Users\matteo.stante\AppData\Local\Continuum\anaconda3\lib\subprocess.py", line 267, in call
    with Popen(*popenargs, **kwargs) as p:

  File "C:\Users\matteo.stante\AppData\Local\Continuum\anaconda3\lib\site-packages\spyder\utils\site\sitecustomize.py", line 210, in __init__
    super(SubprocessPopen, self).__init__(*args, **kwargs)

  File "C:\Users\matteo.stante\AppData\Local\Continuum\anaconda3\lib\subprocess.py", line 709, in __init__
    restore_signals, start_new_session)

  File "C:\Users\matteo.stante\AppData\Local\Continuum\anaconda3\lib\subprocess.py", line 997, in _execute_child
    startupinfo)

FileNotFoundError: [WinError 2] Impossibile trovare il file specificato
Stammeo
  • 17
  • 5
  • If one of the answers below answered your question, the way this site works , you'd "accept" the answer, more here: What should I do when someone answers my question?. But only if your question really has been answered. If not, consider adding more details to the question. – Martin Feb 06 '19 at 08:12

1 Answers1

0
soundfont = 'C:\\Users\\matteo.stante\\Documents\\4_Python_Scripts\\experiments\\JR_sax.sf2'

filepath = 'C:\\Users\\matteo.stante\\Documents\\4_Python_Scripts\\experiments\\input.mid'
  • Windows: \\ (why 2? Because \ is used by formatting like \n \r ... so you need 2)
  • Linux: /

If the file is in the same folder, then

soundfont = 'R_sax.sf2'

filepath = 'input.mid'

EDIT

I tried it on my PC (windows 10) and I get same error. I documentation I didnt find any mention about OS, but there is obviously some linux commands.

Try this on Linux OS


EDIT2

I put little effort and tried it on Linux too.

1) Error the same - File not found

2) I found out you have to put folder somewhere on the path -command: $PATH

  • I put it to /usr/local/bin/fluidsynth

3) New error: Permission denied (couldnt pass it even with root)

4) I found that I dont have fluidsynth installed

command: apt install fluidsynth

5) your script worked (kind of, output.wav generated)

enter image description here

Possible solution

I believe that the problem - after installing fluidsynth on the linux - that your solution for Windows will be solved after installing fluidsynth on windows.

http://www.fluidsynth.org/

Martin
  • 3,333
  • 2
  • 18
  • 39