如何使用 python 将 .mp3 转换为 .wav?
how to convert .mp3 to .wav using python?
我尝试使用 pydub 将 mp3 转换为 wav,但出现此错误:
OSError Traceback (most recent call last)
<ipython-input-43-d2334601378c> in <module>()
5 dst= '/Users/user/Downloads/audio_files/5.wav'
6
----> 7 sound = AudioSegment.from_mp3(src)
8 sound.export(dst, format="wav")
/anaconda2/lib/python2.7/site-packages/pydub/audio_segment.pyc in from_mp3(cls, file, parameters)
714 @classmethod
715 def from_mp3(cls, file, parameters=None):
--> 716 return cls.from_file(file, 'mp3', parameters=parameters)
717
718 @classmethod
/anaconda2/lib/python2.7/site-packages/pydub/audio_segment.pyc in from_file(cls, file, format, codec, parameters, **kwargs)
663 stdin_data = file.read()
664
--> 665 info = mediainfo_json(orig_file)
666 if info:
667 audio_streams = [x for x in info['streams']
/anaconda2/lib/python2.7/site-packages/pydub/utils.pyc in mediainfo_json(filepath)
261
262 command = [prober, '-of', 'json'] + command_args
--> 263 res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
264 output, stderr = res.communicate(input=stdin_data)
265 output = output.decode("utf-8", 'ignore')
/anaconda2/lib/python2.7/subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
392 p2cread, p2cwrite,
393 c2pread, c2pwrite,
--> 394 errread, errwrite)
395 except Exception:
396 # Preserve original exception in case os.close raises.
/anaconda2/lib/python2.7/subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
1045 raise
1046 child_exception = pickle.loads(data)
-> 1047 raise child_exception
1048
1049
OSError: [Errno 2] No such file or directory
我的代码:
src= '/Users/user/Downloads/audio_files/5.mp3'
dst= '/Users/user/Downloads/audio_files/5.wav'
sound = AudioSegment.from_mp3(src)
sound.export(dst, format="wav")
使用 python3 而不是 python2.7(python3 命令)
我为它所做的工作
convert.py
from pydub import AudioSegment
sound = AudioSegment.from_mp3("test.mp3")
sound.export("test.wav", format="wav")
Pydub 安装:
pip3 install pydub
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:mc3man/trusty-media
sudo apt-get install ffmpeg
python3 convert.py
我尝试使用 pydub 将 mp3 转换为 wav,但出现此错误:
OSError Traceback (most recent call last)
<ipython-input-43-d2334601378c> in <module>()
5 dst= '/Users/user/Downloads/audio_files/5.wav'
6
----> 7 sound = AudioSegment.from_mp3(src)
8 sound.export(dst, format="wav")
/anaconda2/lib/python2.7/site-packages/pydub/audio_segment.pyc in from_mp3(cls, file, parameters)
714 @classmethod
715 def from_mp3(cls, file, parameters=None):
--> 716 return cls.from_file(file, 'mp3', parameters=parameters)
717
718 @classmethod
/anaconda2/lib/python2.7/site-packages/pydub/audio_segment.pyc in from_file(cls, file, format, codec, parameters, **kwargs)
663 stdin_data = file.read()
664
--> 665 info = mediainfo_json(orig_file)
666 if info:
667 audio_streams = [x for x in info['streams']
/anaconda2/lib/python2.7/site-packages/pydub/utils.pyc in mediainfo_json(filepath)
261
262 command = [prober, '-of', 'json'] + command_args
--> 263 res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
264 output, stderr = res.communicate(input=stdin_data)
265 output = output.decode("utf-8", 'ignore')
/anaconda2/lib/python2.7/subprocess.pyc in __init__(self, args, bufsize, executable, stdin, stdout, stderr, preexec_fn, close_fds, shell, cwd, env, universal_newlines, startupinfo, creationflags)
392 p2cread, p2cwrite,
393 c2pread, c2pwrite,
--> 394 errread, errwrite)
395 except Exception:
396 # Preserve original exception in case os.close raises.
/anaconda2/lib/python2.7/subprocess.pyc in _execute_child(self, args, executable, preexec_fn, close_fds, cwd, env, universal_newlines, startupinfo, creationflags, shell, to_close, p2cread, p2cwrite, c2pread, c2pwrite, errread, errwrite)
1045 raise
1046 child_exception = pickle.loads(data)
-> 1047 raise child_exception
1048
1049
OSError: [Errno 2] No such file or directory
我的代码:
src= '/Users/user/Downloads/audio_files/5.mp3'
dst= '/Users/user/Downloads/audio_files/5.wav'
sound = AudioSegment.from_mp3(src)
sound.export(dst, format="wav")
使用 python3 而不是 python2.7(python3 命令)
我为它所做的工作
convert.py
from pydub import AudioSegment
sound = AudioSegment.from_mp3("test.mp3")
sound.export("test.wav", format="wav")
Pydub 安装:
pip3 install pydub
sudo apt-get update
sudo apt-get install software-properties-common
sudo add-apt-repository ppa:mc3man/trusty-media
sudo apt-get install ffmpeg
python3 convert.py