1
该程序只运行两次。之后,发生错误。我不知道它为什么会工作两次然后停下来。PermissionError:[Errno 13] Permission denied:'file.mp3'
import tkinter, sys, pygame
from tkinter import messagebox
from gtts import gTTS
soundfile="file.mp3"
def ex():
sys.exit()
的主要问题是有:
def read():
t = e.get()
tts = gTTS(text=t, lang="en")
tts.save(soundfile)
pygame.mixer.init(frequency=16000, size=-16, channels=2, buffer=4096)
pygame.mixer.music.load(soundfile)
pygame.mixer.music.set_volume(1.0)
pygame.mixer.music.play(0,0.0)
while pygame.mixer.music.get_busy()==True:
continue
pygame.quit()
下一步是为按钮的代码。
def clear():
e.delete(0, 'end')
main = tkinter.Tk()
e = tkinter.Entry(main, justify = "center")
l = tkinter.Label(main, text = "Write text")
b1 = tkinter.Button(main, text = "Read", command = read)
b2 = tkinter.Button(main, text = "Clear", command = clear)
b3 = tkinter.Button(main, text = "Exit", command = ex)
所以,我没有任何想法解决它。
启用调试。你会得到什么输出? –
第三读取后: 回溯(最近通话最后一个): 文件 “d:\ Programy \的Python 3.4.0 \ LIB \ Tkinter的\ __ init__.py”,线1482,在__call__ 回报self.func(* ARGS ) 文件“C:\ Users \ Piotrek \ Desktop \ Python_Emotiv \ StnezatorEnglish.py”,第13行,在读 tts.save(soundfile) 文件“D:\ Programy \ Python 3.4.0 \ lib \ site-packages \ gtts-1.1.4-py3.4.egg \ gtts \ tts.py“,第93行,保存为 ,并打开(savefile,'wb')为f: PermissionError:[Errno 13] Permission denied:'D :/01_Pulpit/syntezator.mp3' – Peter
我有同样的问题,像@ user45193:[link](http://stackoverflow.com/questions/31809050/how-to-free-resource-in-pygame-mixer) – Peter