【发布时间】:2020-06-06 21:16:02
【问题描述】:
我正在尝试在 Python 中创建一个 ChatBot,VA,用于接收音频输出
代码如下:
from gtts import gTTS
import speech_recognition as sr
import playsound
import os #to save the file
import time
def speak(text):#this defines the function SPEAK and creates the command for its use
tts = gTTS(text=text, lang="en")
filename = "voice.mp3"
tts.save(filename) #saves the audio file
playsound.playsound(filename)
#function ends here
要播放音频,我按以下方式使用该功能:
>>>speak("I am speaking this text")
上面的 ^^^ 工作得很好,但是当我使用多个语句时:
>>>speak("I am saying this")
>>>speak("And also this!")
它给出了一个错误:
PermissionError: [Errno 13] Permission denied: 'voice.mp3'
我认为这是由于音频文件的名称匹配。但是当我尝试使用循环每次更改数字时,在播放音频指定次数后仍然显示错误。有人可以给我一个解决方案吗?谢谢!
【问题讨论】: