如何在播放完mp3文件后退出VLC

2024-04-23 08:23:36 发布

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

我有这个函数,我需要在退出函数之前关闭文件,比如(“一些文本”)。在

def say(self, text):
    tts = gTTS(text, lang='fr')
    file="text.mp3"
    tts.save(file)
    audio = MP3(file)
    p = vlc.MediaPlayer(file)
    p.play()
    time.sleep((audio.info.length)) #to avoid it listening to itself
    p.stop()
    return file

因为如果我不这样做,我就有这个错误

OS Error: [Errno -9993] Illegal combination of I/O device

我认为发生这个错误是因为我试图在调用函数say之后监听,而文件仍然是打开的。在

注:我正在使用python3


Tags: 文件to函数text文本selflangdef