0

so this is the code i have been writing and saw it on a video tutorial on making a voice assistant, i copied the code exactly the same as the video but it just keeps popping up saying 'no module named playsound' but i have downloaded it in the command prompt window

below is my code

import os
import time
from playsound import playsound
import speech_recognition as sr 
from gtts import gTTS



def speak(text):
  tts = gTTS(text=text, lang="en")
  filename = "voice.mp3"
  tts.save(filename)
  playsound.playsound(filename)
  speak("hello danny")  `

any idea on what to do?

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61

3 Answers3

0

You can install playsound package from pip

pip install playsound

After that in your code, you have to replace

playsound.playsound(filename) -> playsound(filename)

ParthS007
  • 2,581
  • 1
  • 22
  • 37
  • i have already installed playsound and changed the code but it is still displaying the same error. any more solutions?? – Danny Sharpe Jun 06 '20 at 20:07
0

Most likely wrong version of py so I reckon that you have atleast python 2 installed which means that when you run pip install playsound, its installing into your python2 folder.

Try installing with

pip3 install playsound
akwasiijunior
  • 105
  • 2
  • 7
-1

I was also facing the same issue. I uninstalled the playsound by using "pip uninstall playsound" , and installed playsound using the command "pip3 install playsound" .. it worked . Please try this ..