Here's the relevant part of my code that is supposed to play back two separate strings but it only convert the first one to an audio file, saves it, plays it then my program crashes (python.exe has stopped working).
I'm running it in PyCharm on Windows 10 if that matters
str1="hello"
str2="world"
tts = gTTS(text=str1, lang='en')
tts.save("hello.mp3")
playsound('hello.mp3') #works as expected till here
tts = gTTS(text=str2, lang='en') # i believe this line is not executed properly
tts.save("hello.mp3")
playsound('hello.mp3')
i have already tried deleting the hello.mp3 file before trying to save it again ( os.remove() ).
PS: I'm very new to python so please let me know whats wrong in simple terms
play sound doesn't do good! after saving use the following to play the file
import os import pyglet tts.save(filename) music = pyglet.media.load(filename, streaming=False) music.play() sleep(music.duration) #prevent from killing os.remove(filename) #remove temperory file
Hope this works according to what you expected!
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.