尝试调用midi2audio时出现FileNotFoundError错误。 我正在使用Python 3.6-Anaconda-Windows 10。 我的.py文件以及.sf2和.mid文件位于同一文件夹中。 我的代码是:
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')
我希望在我的文件夹中创建一个.wav文件。 我得到了:
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
答案 0 :(得分: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'
如果文件位于同一文件夹中,则
soundfont = 'R_sax.sf2'
filepath = 'input.mid'
编辑
我在PC(Windows 10)上尝试了此操作,但收到相同的错误。我在文档中没有找到有关操作系统的任何信息,但是显然有一些linux命令。
在Linux操作系统上尝试
EDIT2
我不费吹灰之力,并且也在Linux上进行了尝试。
1)错误相同-找不到文件
2)我发现您必须将文件夹放在路径-command的某个位置:$ PATH
3)新错误:权限被拒绝(即使使用root用户也无法通过)
4)我发现我没有安装Fluidsynth
命令:易于安装fluidsynth
5)您的脚本有效(有点,output.wav生成了)
可能的解决方案
我相信问题-在Linux上安装Fluidsynth之后-在Windows上安装Fluidsynth后,您的Windows解决方案将得到解决。