2

I am trying to build a voice assistant. I am facing a problem with the playsound library. Please view my code snippet.

def respond(output):
    """
    function to respond to user questions
    """
    num=0
    print(output)
    num += 1
    response=gTTS(text=output, lang='en')
    file = str(num)+".mp3"
    response.save(file)
    play(file, True) #playsound import playsound as play

if __name__=='__main__':
    respond("Hi! I am Zoya, your personal assistant")

My audio file is getting generated, however at the line play(file,True) it is throwing the following error.

---------------------------------------------------------------------------
CalledProcessError                        Traceback (most recent call last)
<ipython-input-52-be0c0a53e7e6> in <module>()
      1 if __name__=='__main__':
----> 2     respond("Hi! I am Zoya, your personal assistant")
      3 
      4     while(1):
      5         respond("How can I help you?")

6 frames
/usr/lib/python3.7/subprocess.py in check_call(*popenargs, **kwargs)
    361         if cmd is None:
    362             cmd = popenargs[0]
--> 363         raise CalledProcessError(retcode, cmd)
    364     return 0
    365 

CalledProcessError: Command '['/usr/bin/python3', '/usr/local/lib/python3.7/dist-packages/playsound.py', '1.mp3']' returned non-zero exit status 1.

How do I resolve the issue? I would also like to mention that I am working on google colab.

2 Answers2

0

Try installing the PyObjC library to bridge the gap between python and objective C gap. Playsound library uses subprocess which are dependent on PyObjC library. When it returns exit status 1 it means that it wasn't able to complete the process because of unavailability of some dependencies.

This is my first answer on stack overflow, please don't mind any mistakes.

0

I think you could use PyObjC, however, that's only for MacOS. It doesn't necessarily solve the problem for Windows.

Epoch
  • 29
  • 2