【问题标题】:PermissionError: [Errno 13] Permission denied: 'file.mp3'PermissionError:[Errno 13] 权限被拒绝:'file.mp3'
【发布时间】:2016-07-02 22:34:30
【问题描述】:

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

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 行,用 open(savefile, 'wb') 保存为 f: PermissionError: [Errno 13] Permission denied: 'D:/01_Pulpit/syntezator.mp3'
  • 我也有类似@user45193的问题:link

标签: python python-2.7 python-3.x pygame mp3


【解决方案1】:
from gtts import gTTS
import playsound
import os

x = ['sunny', 'sagar', 'akhil']
tts = 'tts'
for i in range(0,3):
    tts = gTTS(text= x[i], lang = 'en')
    file1 = str("hello" + str(i) + ".mp3")
    tts.save(file1)
    playsound.playsound(file1,True)
    os.remove(file1)

为每个新的存档重命名文件,这对我有用。

【讨论】:

    猜你喜欢
    • 2017-02-10
    • 2015-07-17
    • 2016-07-25
    • 2018-11-18
    • 2020-07-01
    • 2016-11-12
    • 2019-11-09
    • 2020-06-06
    • 2021-11-11
    相关资源
    最近更新 更多