我正在使用带有VS Code编辑器的python Anaconda构建聊天机器人。我正在使用Google Cloud进行文本语音转换,并且可以正常工作,除非我问它一个问题,它必须执行if "mean" in text
,它说PermissionError: [Errno 13] Permission denied: 'D:\\Programming\\python\\thief.mp3'
。
注意:对于其余的elif语句(我在这里没有显示),它的作用就像是一种魅力,并且在语音中反应完美,这使该问题不再与其他任何问题重复。
一段代码:
from PyDictionary import PyDictionary
dictionary=PyDictionary()
bannedWord=["what","does","mean"]
from google.cloud import texttospeech
client = texttospeech.TextToSpeechClient()
voice = texttospeech.types.VoiceSelectionParams(
language_code='en-US',
ssml_gender=texttospeech.enums.SsmlVoiceGender.NEUTRAL)
audio_config = texttospeech.types.AudioConfig(
audio_encoding=texttospeech.enums.AudioEncoding.MP3)
class commander:
def __init__(self):
pass
def discover(self,text):
if "mean" in text:
x=' '.join(i for i in text.split() if i not in bannedWord)
print(x)
#noun=dictionary.meaning(x)["Noun"]
noun=dictionary.meaning(x)
if noun["Noun"]:
for count,ele in enumerate(noun["Noun"]):
self.respond(ele)
elif noun["Verb"]:
for count,ele in enumerate(noun["Verb"]):
self.respond(ele)
elif noun["Adjective"]:
for count,ele in enumerate(noun["Adjective"]):
self.respond(ele)
elif noun["Adverb"]:
for count,ele in enumerate(noun["Adverb"]):
self.respond(ele)
def respond(self,response):
print(response)
synthesis_input = texttospeech.types.SynthesisInput(text=response)
response = client.synthesize_speech(synthesis_input, voice, audio_config)
with open(r'D:\Programming\python\thief.mp3', 'wb') as out:
out.write(response.audio_content)
print('Audio content written to file "output.mp3"')
music.load(r"D:\Programming\python\thief.mp3")
music.play()
while pygame.mixer.music.get_busy():
pygame.time.Clock().tick(10)