In order to read a Chinese story via TTS, the speech module is not perfect in reading Chinese because of multiple pronunciation.
So I use a online speech API to generate MP3.
def online_speech(text, vol, per, spd, pit):
#api code
... #generate text speech link from API
urllib.request.urlretrieve(url,'temp.mp3') #save mp3
sound.play_effect('temp.mp3') #read mp3
if __name__ == '__main__':
online_speech('Hello',5,'woman',2,5)
the result was, whatever the text I'd changed, it always said the same word 'Hello'
for example, if I changed the code below after running the code above
online_speech('Hello world',5,'woman',2,5)
it said 'Hello'. if I deleted the 'temp.mp3' and run again, it said 'Hello' again!!
I had no idea... what was going on, then I tried to use sound.player()
def online_speech(text, vol, per, spd, pit):
#api code
... #generate text speech link from API
urllib.request.urlretrieve(url,'temp.mp3') #save mp3
player = sound.Player('temp.mp3')
player.play() #read mp3
if __name__ == '__main__':
online_speech('Hello',5,'woman',2,5)
it didn't say anything!!
the player only works like this:
def online_speech(text, vol, per, spd, pit):
#api code
... #generate text speech link from API
urllib.request.urlretrieve(url,'temp.mp3') #save mp3
if __name__ == '__main__':
online_speech('Hello',5,'woman',2,5)
player = sound.Player('temp.mp3')
player.play() #read mp3
I have a class for reading story. so when I write like this:
def read_story(self,text):
from online_speech import *
online_speech(text,5,'woman',2,5)
player = sound.Player('temp.mp3')
player.play() #read mp3
it kept silent .... I really don't know what to do here.... does anyone meet this before?
It really doesn't make any sense.