0

I just wrote simple code to play some music, using PyDub module in Python:

from pydub import AudioSegment
from pydub.playback import play

audio1 = AudioSegment.from_wav("music.wav")
play(audio1)

But I get this error:

Traceback (most recent call last):
File "D:\codes\Lessons.IzuchaemPython\pydub1.py", line 16, in <module> play(audio1)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\playback.py", line 71, in play _play_with_ffplay(audio_segment)
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\playback.py", line 15, in _play_with_ffplay
seg.export(f.name, "wav")
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\audio_segment.py", line 867, in export
out_f, _ = _fd_or_path_or_tempfile(out_f, 'wb+')
File "C:\Users\User\AppData\Local\Programs\Python\Python39\lib\site-packages\pydub\utils.py", line 60, in _fd_or_path_or_tempfile
fd = open(fd, mode=mode)
PermissionError: [Errno 13] Permission denied:'C:\\Users\\User\\AppData\\Local\\Temp\\tmp4_bp0wu1.wav'

I have installed FFmpeg. Please, explain to me how to make this simple program work.

2 Answers2

0

You need to have either pyaudio installed or ffplay.

It will obviously open another window since it needs an application to play the audio, as an FYI. (Can't play from command prompt or terminal ;P)

Otherwise it should work, function is working fine for me.

Note: Also make sure you are in the right directories etc.,

NewCoder18
  • 310
  • 1
  • 9
0

You can look this Errno 13 Permission denied Python

or

I see the web from https://realpython.com/playing-and-recording-sound-python/

Although pydub can open and save WAV files without any dependencies, you need to have an audio playback package installed to play audio.

Myabe you should try to install an audio playback.

Peter
  • 100
  • 10