1

当我调用我的函数时,我没有错误,但如果我重复调用它,我将出现以下错误:

发生异常:PermissionError [Errno 13] 权限被拒绝:'tolkback.mp3'

from gtts import gTTS
import pyglet
from playsound import playsound


def TalkBack(case_ans):
    print("in ...................................")
    tts = gTTS(case_ans)

    tts.save('tolkback.mp3')

    print("saving...............................")
    playsound('tolkback.mp3')
    print("saying................................")


TalkBack("my bad end 1")
TalkBack("go go end 2")
TalkBack("find me my self end 3")
TalkBack("games maker end 4")
TalkBack("say my name end 5")

程序应该回话文本

4

1 回答 1

1

这是我用我朋友furas的 Gide 所做的解决方案>>

from playsound import playsound
import webSearch
import os
import random

def name_generator():
    ran = random.randint(1,5000)
    ran = str(ran)
    return ran


def TalkBack(case_ans):
    print("in ...................................")
    tts = gTTS(case_ans)
    new_name = name_generator()
    new_name= new_name+".mp3"
    tts.save(new_name)

    print("saving...............................")
    playsound(new_name)
    print("saying................................")
    try:
        os.remove(new_name) 
    except:
        print("i cant")



TalkBack("my bad end 1")
TalkBack("go go end 2")
TalkBack("find me my self end 3")
TalkBack("games maker end 4")
TalkBack("say my name end 5")

生成一个具有随机名称的新 .mp3 文件,并在使用后将其删除

于 2019-04-10T22:21:06.620 回答