Answer the question
In order to leave comments, you need to log in
PlaySound is not working. What to do?
Hello
, I decided to write a voice assistant.
from gtts import gTTS
import random
import time
import playsaund
def say_message(message):
print(message)
vfile = gTTS(message, lang="ru")
file_name = str("_audio_" + "golos" + str(time.time()) + "_" + str(random.randint(0, 10000)) + ".mp3")
vfile.save(file_name)
playsound.playsound(file_name)
def lislisten_command():
return input("Скажите вашу команнду: ")
def do_this_command(message):
message = message.lower()
if "привет" in message:
say_message("Привет друг")
elif "пока" in message:
say_message("Пока")
exit()
else:
say_message("Данной команды не существует!")
while True:
command = lislisten_command()
do_this_command(command)
C:\Users\Дом\Desktop\Py>golos.py
Скажите вашу команнду: привет
Привет друг
Traceback (most recent call last):
File "C:\Users\Дом\Desktop\Py\golos.py", line 33, in <module>
do_this_command(command)
File "C:\Users\Дом\Desktop\Py\golos.py", line 23, in do_this_command
say_message("Привет друг")
File "C:\Users\Дом\Desktop\Py\golos.py", line 12, in say_message
playsound.playsound(file_name)
AttributeError: 'function' object has no attribute 'playsound'
C:\Users\Дом\Desktop\Py>
Answer the question
In order to leave comments, you need to log in
Hello. I also make an assistant for this video tutorial (:
Literally I just managed to fix it, replace the lines
>import playsound
>playsound.playsound(file_voice_name)
Changed to
>Import playsound2
>playsound2.playsound(file_voice_name)
Do not forget to download the libraries via pip install before that
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question