how to play mp3

前端 未结 12 1663
醉酒成梦
醉酒成梦 2021-02-09 09:39

my problem starts here:

pyttsx and gTTS module errors

gTTS works well, takes text from text file, but first creates mp3 file, then if I want listen, I must call

相关标签:
12条回答
  • 2021-02-09 10:21

    webbrowser should be part of you standard python install. Check if there is a webbrowser.py under C:\Your_Python_Folder\Lib.

    Below code works just fine for me as webbrowser.py is present at above mentioned folder.

    import webbrowser
    webbrowser.open("rec.mp3")
    
    0 讨论(0)
  • 2021-02-09 10:22

    You can use "subprocess".

    from subprocess import call
    from gtts import gTTS
    import os
    blabla = input('Type IN: ')
    tts = gTTS(text=blabla, lang='en')
    tts.save("test.mp3")
    call(["vlc", "test.mp3"])
    

    This program asks user to type in anything and it will say that trough vlc.
    I use this on Linux but i don't now if it works on Windows.

    0 讨论(0)
  • 2021-02-09 10:22

    I don't know the solution to all of the questions, but the issue you're having with pydub is that you don't have ffmpeg or avconv installed. There are instructions on the pydub github:

    Windows:

    1. Download and extract libav from Windows binaries provided here.
    2. Add the libav /bin folder to your PATH envvar
    3. pip install pydub
    0 讨论(0)
  • 2021-02-09 10:22

    If AVbin error occurs...

    First download AVbin.exe and Install it then Go to local disk C --> windows --> System32 --> search the Avbin.dll and copy that file then paste that particular file in your root directory

    Error will vanish

    0 讨论(0)
  • 2021-02-09 10:24

    You can use playsound module

    from playsound import playsound
    playsound(file.mp3)
    

    Boom that's it.it plays the audio right way works like charm

    0 讨论(0)
  • 2021-02-09 10:33

    Same problem here. It works with playsound 1.2.1 for me.

    Install with :

    $ pip install playsound
    

    test with:

    >>>from playsound import playsound
    >>>playsound('/path/to/a/sound/file/you/want/to/play.mp3')
    
    0 讨论(0)
提交回复
热议问题