P
P
Python Newbie2021-08-05 14:30:55
Python
Python Newbie, 2021-08-05 14:30:55

PlaySound is not working. What to do?

Hello

, I decided to write a voice assistant.

Here is the code
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)


On startup I get
mistake
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>


This saves the file
zMAnMkWP.jpg?download=1&name=%D0%A1%D0%BA%D1%80%D0%B8%D0%BD%D1%88%D0%BE%D1%82%2005-08-2021%2014:30:01.jpg


What to do?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
L
laver51455, 2021-08-05
@laver51455

Your import says playsAund and not playsOund

S
svatalex, 2021-12-25
@svatalex

pip uninstall playsound
pip install playsound==1.2.2

A
akatsuki_sanya, 2022-04-08
@akatsuki_sanya

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 question

Ask a Question

731 491 924 answers to any question