[英]how to use gtts repeatedly?
when i call my function once i have no errors but if i call it repeatedly i will have the following error : 当我一次调用函数时,没有错误,但是如果我反复调用它,则会出现以下错误:
Exception has occurred: PermissionError [Errno 13] Permission denied: 'tolkback.mp3' 发生异常: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")
the program should talk back the text 程序应该回话
this is the solution that i made >> with the Gide of my friend furas 这是我用朋友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")
generating a new .mp3 file with a random name and deleting it after using it 生成一个具有随机名称的新.mp3文件,并在使用后将其删除
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.