简体   繁体   中英

gTTS (Google-Text-to-Speech) Error: Audio gets saved but only play after opening the groovy app



from gtts import gTTS
import os

mytext = 'Welcome to the hub!'

language = 'en'

myobj = gTTS(text=mytext, lang=language, slow=False)

myobj.save("welcome.mp3")

os.system("welcome.mp3")

The above is my code. im trying to make a smart speaker for eg google home.

My problem is when the last line is ran os.system("welcome.mp3") i dont want it to open the groovy app to say the audio. I want it to just reply within the terminal is that possible?

if you want to directly play the song, you can use python playsound module:

from playsound import playsound
playsound('welcome.mp3')

other os module uses your default media player, you can mention the program you want the mp3 be played with before the file name, there is a terminal sound player for terminal in linux called mpg123 you can use:

# apt install mpg123
os.system("mpg123 " + file)

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM