当音频文件停止使用播放声音模块时,我可以删除它吗?我已经写了一个代码,但我做不到:
from gtts import gTTS
import os
import playsound
def say(textg):
tts = gTTS(text=textg, lang='en')
tts.save('audio.mp3')
playsound('audio.mp3')
time.sleep(here, what i have to do?)
os.remove('audio.mp3')
我正在使用Python 2.7.15
playsound
是模块的名称,您应该改用playsound.playsound
(这是一个函数名称):
from gtts import gTTS
import os
import playsound
def say(textg):
tts=gTTS(text=textg,lang='en')
tts.save('audio.mp3')
playsound.playsound('audio.mp3')
os.remove('audio.mp3')
调用playsound.playsound
后,程序将等待完成。