how to play mp3

前端 未结 12 1659
醉酒成梦
醉酒成梦 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:18

    with pygame I have installation problem and not sure, how good is use it this way:

    Can you provide more details about the pygame installation error?

    I was able to use PYGAME with this code, where "hello.mp3" is a file in the same directory

    from gtts import gTTS
    tts = gTTS(text='Hello', lang='en')
    
    tts.save("hello.mp3")
    
    from Tkinter import *
    root = Tk()
    
    from pygame import mixer
    mixer.init()
    mixer.music.load('hello.mp3')
    mixer.music.play()
    
    root.mainloop()
    

    vlc just how to install it?

    I also used VLC. I have installed it with these commands:

    sudo pip install python-vlc
    

    And I got this error:

    NameError: no function 'libvlc_new
    

    So, I tryed the command:

    sudo apt-get install vlc
    

    And it worked with this code:

    from gtts import gTTS
    tts = gTTS(text='Hello', lang='en')
    tts.save("hello.mp3")
    
    from Tkinter import *
    root = Tk()
    
    import vlc
    p = vlc.MediaPlayer("hello.mp3")
    p.play()
    
    root.mainloop()
    

    Hope It help You.

提交回复
热议问题