[英]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.
我正在尝试为例如 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.我的问题是当最后一行运行
os.system("welcome.mp3")
我不希望它打开 groovy 应用程序说音频。 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:如果要直接播放歌曲,可以使用python playsound模块:
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:其他 os 模块使用您的默认媒体播放器,您可以在文件名前提及您想要播放 mp3 的程序,在 linux 中有一个终端声音播放器,称为
mpg123
,您可以使用:
# apt install mpg123
os.system("mpg123 " + file)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.