While trying to use an mp3 file in a python environment I get this error, my file directories are all properly spelt.
Note: the directories are formatted so that within a project folder there is the main code, and 2 sub-folders one for the non-altered mp3 files ("targets"), and one for the altered mp3 files ("altered_targets").
I have already tried to switch AudioSegment.from_file("filename","mp3") with no luck.
from pydub.playback import play
from pydub import AudioSegment
import sys
import os
sys.path.append('/usr/local/lib/python3.7/dist-packages/ffmpeg')
def adjust_volume(file_name, adjustment):
song = AudioSegment.from_mp3(file_name)
new_song = song + adjustment
new_title = "./alter_targets/%s" % (file_name)
new_song.export(new_title, format='mp3')
for target in os.listdir("./targets"):
adjust_volume("./targets/"+target, 10)
This code snippet should slightly increase the volume of the mp3 file within "targets", then save the new mp3 file into the "altered_targets" file.
Instead I get "OSError: [Errno 2] No such file or directory"
Traceback (most recent call last):
File "volume_alter.py", line 19, in <module>
adjust_volume("./targets/"+target, 10)
File "volume_alter.py", line 10, in adjust_volume
song = AudioSegment.from_mp3(file_name)
File "/usr/local/lib/python2.7/dist-packages/pydub/audio_segment.py", line 716, in from_mp3
return cls.from_file(file, 'mp3', parameters=parameters)
File "/usr/local/lib/python2.7/dist-packages/pydub/audio_segment.py", line 665, in from_file
info = mediainfo_json(orig_file)
File "/usr/local/lib/python2.7/dist-packages/pydub/utils.py", line 263, in mediainfo_json
res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
File "/usr/lib/python2.7/subprocess.py", line 394, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subprocess.py", line 1047, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory