小编Pet*_*ter的帖子

PermissionError: [Errno 13] 权限被拒绝: 'file.mp3'

该程序仅运行两次。后来,错误发生。我不知道为什么它工作两次然后停止。

import tkinter, sys, pygame
from tkinter import messagebox
from gtts import gTTS

soundfile="file.mp3"

def ex():
    sys.exit()
Run Code Online (Sandbox Code Playgroud)

主要问题在于:

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()
Run Code Online (Sandbox Code Playgroud)

接下来是按钮的代码。

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 = …
Run Code Online (Sandbox Code Playgroud)

python mp3 pygame python-2.7 python-3.x

3
推荐指数
1
解决办法
4016
查看次数

标签 统计

mp3 ×1

pygame ×1

python ×1

python-2.7 ×1

python-3.x ×1