当声音停止时,如何删除声音

2024-04-25 04:24:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我的问题是,我可以删除音频文件时,它停止播放声音模块?我已经写了一个代码,但我做不到:

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')

我正在使用Python2.7.15


Tags: 模块代码fromimport声音osdefmp3
1条回答
网友
1楼 · 发布于 2024-04-25 04:24:22

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之后,程序将等待它完成。你知道吗

相关问题 更多 >