2017-05-09 64 views
0

我有這個功能,我需要在退出函數說(「一些文本」)之前關閉文件。如何在播放mp3文件後退出VLC

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

我認爲,因爲我想聽聽剛過函數的調用說與此錯誤出現文件仍然打開。

注:我使用Python 3

回答

1

工作雖然我不是經歷了TTS,不應該,如果你只是做close(os.getcwd()+'/'+file)工作?

+0

It works thanks @Alexander –