0

I have been trying to add sound to my python code. I tried using playsound, pygame, pydub and tkinter but in vsc it doesn't let me install any using the command pip3 install pygame...(and so on) here I have tried it with pydub but this sais that there is no module named pydub and it doesn't let me install it. Can someone help me add this sound to my code?

from pydub import AudioSegment
from pydub.playback import play

psong = AudioSegment.from_mp3("song.mp3")
    play(song)
  • 1
    How are you installing modules? Have you verified that the Python environment that VSCode is using is the same environment you're installing to? As for how to check that, I suggest using Google, since it's a common issue. – Random Davis Jun 24 '21 at 18:19
  • I would recommend installing modules with your CMD prompt/Terminal instead of your VS Code Terminal, although realistically this should not matter, it might help in your case. – TerminalFlow Jun 24 '21 at 19:52

1 Answers1

0

I have two suggestions for this issue:

  1. Install pyaudio (pip3 install pyaudio) as this is the best module that pydub uses.

  2. Change your audio file format to wav instead of mp3 and also change this section of code: psong = AudioSegment.from_mp3("song.mp3") to psong = AudioSegment.from_wav("song.wav").

Source for answer

TerminalFlow
  • 230
  • 2
  • 11