我正在构建一个聊天机器人使用python,Anaconda与VS代码编辑器。我正在使用googlecloud进行文本到语音转换,它的工作很好,除非我问它一个问题,它必须执行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)
目前没有回答
相关问题 更多 >
编程相关推荐