Python Playsound is not playing an audio

Asked

Viewed 351 times

0

I created a program that synthesizes a Python speech with the gTTS library, but at the end when I play the saved audio this error appears:

    Traceback (most recent call last):
    File "C:/Users/vinic/Desktop/Programação/Projetos/Lia/Lia/Lia.py", line 4, in <module>
    Falar("Bom dia")
    File "C:\Users\vinic\Desktop\Programação\Projetos\Lia\Lia\Habilidades\Falar.py", line 15, in Falar
    playsound.playsound("C:\\Users\\vinic\\Desktop\\Programação\\Projetos\\Lia\\Lia\\Sons\\Fala.mp3")
    File "C:\Users\vinic\AppData\Local\Programs\Python\Python37\lib\site-packages\playsound.py", line 35, in _playsoundWin
    winCommand('open "' + sound + '" alias', alias)
    File "C:\Users\vinic\AppData\Local\Programs\Python\Python37\lib\site-packages\playsound.py", line 30, in winCommand
'\n    ' + errorBuffer.value.decode())
    UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe3 in position 24: invalid continuation byte

Program

    from Subprogramas.BarraDiretorio import BarraDiretorio
    from gtts import gTTS
    import playsound
    import os

    def Falar(Texto):

    Barra = BarraDiretorio()

    Diretorio = os.getcwd().replace('Habilidades', 'Sons')

    Sintese = gTTS(Texto, lang='pt', slow=False)
    Sintese.save(Diretorio + '{}Fala.mp3'.format(Barra))

    playsound.playsound("C:\\Users\\vinic\\Desktop\\Programação\\Projetos\\Lia\\Lia\\Sons\\Fala.mp3")

If anyone knows anything please tell me :)

  • from Subprogramas.BarraDiretorio import BarraDiretorio - What is this?

  • What text did you ask him to speak?

  • from Subprograms.Barradiretorio import Barradiretorio It’s a function I created to take the user’s operating system and return a bar ( or / )

  • And the text is passed as function input Talk about( )

2 answers

1

For me, it worked perfectly:

from gtts import gTTS
import playsound
import os

def falar(texto):
    sintese = gTTS(texto, lang='pt', slow=False)
    arq = os.path.join(os.getcwd(), 'fala.mp3')
    sintese.save(arq)
    playsound.playsound(arq)

falar("Boa tarde. Ei, como você está?")

I just had to give the pip install gtts and the pip install playsound before executing.

  • Strange, copied and pasted, but still returns the same error

1

I think I found the problem, probably was the directory I was using. It had a folder called "Programming", and maybe playsound do not accept accents on the way, because I switched to "Programming" and it worked.

  • The bug is within the playsound library here: https://github.com/TaylorSMarks/playsound/blob/master/playsound.py#L23

Browser other questions tagged

You are not signed in. Login or sign up in order to post.