8

i'm trying to use pydub, but when i import it to python with AudioSegment it will give me an error saying it doesn't recognize it. i tried using pip install and searching online. any help?? i'm using python 2.7

from pydub import AudioSegment
Sh0z
  • 127
  • 1
  • 2
  • 7
  • try to install it from here: https://pypi.python.org/pypi/pydub#downloads – Liam Apr 02 '17 at 17:00
  • can you post entire error-dump? , Also did the install was successful. – Anil_M Apr 03 '17 at 20:20
  • error im getting: **libpng warning: sBIT: invalid. ** my code: import pydub from AudioSegment sound1 = AudioSegment.from_wave('chill.wav') sound2 = AudioSegment.from_wave('p1.wav') sound1= sound1[:] + 6 sound2=sound2+8 #louder combined = sound1.overlay(sound2) combined.export("pydubtry.wav", format='wav') – Sh0z Apr 08 '17 at 17:31
  • would appreciate the help :) @Anil_M. i tried to install but it didn't work.. – Sh0z Apr 08 '17 at 17:33
  • @Liam the installation didn't work.. just opened a zip compress program. any suggestions?? – Sh0z Apr 08 '17 at 17:34
  • can u uninstall and try installing using `pip install pydub`. Also make sure pydub path is in the PYTHONPATH or system PATH. What OS are you using? – Anil_M Apr 08 '17 at 17:49
  • @Anil_M thanks. i tried pip install but it's still giving me an error unfortunately. i use windows (10). by pydub in the path- do you mean the name of the folder itself? could you show an example please? – Sh0z Apr 10 '17 at 07:25
  • @Anil_M btw this is what i get after installing with pip install: `Successfully installed pydub-0.18.0` . is that what im meant to be getting? – Sh0z Apr 10 '17 at 08:09
  • find out where `pydub` got installed. I've in `C:\Python27\Lib\site-packages\pydub`. Open a command-prompt and type in , `set PATH=c:\Python27\Scripts;c:\Python27\Lib;C:\Python27\Lib\site-packages\pydub;%PATH%` . Then try running `pydub` program on `cmd` screen. Once successful you will need to add pydub path to system environment variables section. – Anil_M Apr 11 '17 at 13:37
  • @Anil_M thanks for all the help it finally worked! do you by any chance know what this error means? `RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)` ? – Sh0z Apr 13 '17 at 17:39
  • Looks like `pydub` cant find `ffmpeg` or `avconv`. you may need to install or add path to system – Anil_M Apr 13 '17 at 19:14
  • @Anil_M it looks like everything is working.. its creating all the files with the effects. should i look into this more? – Sh0z Apr 14 '17 at 09:11
  • If it's working I would let it be. It's just warning anyway. – Anil_M Apr 14 '17 at 13:37
  • thanks for all the help! @Anil_M – Sh0z Apr 15 '17 at 18:18
  • Glad I could help. Up-voting comments will help me as well as the post. – Anil_M Apr 16 '17 at 05:37
  • @Anil_M im new to this website, how do i do that? – Sh0z Apr 18 '17 at 13:13
  • @Sh0z: I compiled my comments into an answer. You can upvote + accept that by selecting up arrow and selecting checkmark next to the question. This way the question will show as being answered and also will close the loop. That's better way to go about it. – Anil_M Apr 18 '17 at 13:19
  • @Anil_M just voted. again thanks for all the help!! :) – Sh0z Apr 18 '17 at 13:54

7 Answers7

4

I was also getting the same issue .and it was coming due to ffmpeg was not correctly configured. i have download latest ffmpeg from official website https://www.ffmpeg.org/download.html and setting up the class path worked for me

geisterfurz007
  • 5,292
  • 5
  • 33
  • 54
3

I'm getting the same error because ffmpeg wasn't installed on my MAC. Installed it with brew install ffmpeg and it fixed the problem.

Esterlinkof
  • 1,444
  • 3
  • 22
  • 27
2

if you're using Linux, try this sudo apt install ffmpeg will fix the problem.

Hope it help !!!

leminhnguyen
  • 1,518
  • 2
  • 13
  • 19
1

Can u uninstall and try installing using pip install pydub. Also make sure pydub path is in the PYTHONPATH or system PATH. What OS are you using?

find out where pydub got installed.
I've in C:\Python27\Lib\site-packages\pydub.
Open a command-prompt and type in ,
set PATH=c:\Python27\Scripts;c:\Python27\Lib;C:\Python27\Lib\sit‌​e-packages\pydub;%PA‌​TH%

Then try running pydub program on cmd screen. Once successful you will need to add pydub path to system environment variables section.

Also for error:

RuntimeWarning: Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work warn("Couldn't find ffmpeg or avconv - defaulting to ffmpeg, but may not work", RuntimeWarning)

Looks like pydub cant find ffmpeg or avconv. You may need to install or add path to system. If it's working I would let it be. It's just warning anyway

Anil_M
  • 10,893
  • 6
  • 47
  • 74
1

Tried @paolov's solution - didn't work until I had restarted pycharm / python editor...

Also - see Python convert mp3 to wav with Pydub for quick alternative that doesn't necessary require pydub (but still needs ffmpeg)... involves import subprocess, thanks to @Roland Smith

PS - also, see http://blog.gregzaal.com/how-to-install-ffmpeg-on-windows/ for description of how to add to PATH - in context of ffmpeg). I added to folder within my PyCharm/Python project instead of straight on C drive... either should work, but as I say, try restarting editor, and check cmd line > ffmpeg -codecs after adding to PATH...

JB-007
  • 2,156
  • 1
  • 6
  • 22
0

What worked for me was:

  1. Google for a suitable ffmpeg download. I needed a windows 64 bit package, which I downloaded from https://ffmpeg.zeranoe.com/builds/
  2. Opened the downloaded zip file. Then took the files inside the bin folder and placed those inside the pydub folder.

Since i have already placed pydub in the system PATH previously, this removed the need to update the system PATH. The files can be placed elsewhere and that should work as well as long as the PATH is updated.

paolov
  • 2,139
  • 1
  • 34
  • 43
0

Assuming that you installed ffmpeg correctly, make sure that you restart your python environment such that your path contains the ffmpeg.

I had to open a new terminal and relaunch my notebook to get it working.