def process_listen(self):
if not os.path.isfile("data/temp/heard.pcm") or os.stat("data/temp/heard.pcm").st_size == 0:
await self.bot.send_embed(self.text_channel, ":warning: No input found")
return
func = functools.partial(subprocess.call, ["ffmpeg", "-f", "s16le", "-y", "-ar", "44.1k", "-ac", "2", "-i", "data/temp/heard.pcm", "data/temp/heard.wav"], shell = True)
await self.bot.loop.run_in_executor(None, func)
with speech_recognition.AudioFile("data/temp/heard.wav") as source:
audio = self.recognizer.record(source)
'''
try:
await self.bot.reply("Sphinx thinks you said: " + recognizer.recognize_sphinx(audio))
except speech_recognition.UnknownValueError:
await self.bot.reply("Sphinx could not understand audio")
except speech_recognition.RequestError as e:
await self.bot.reply("Sphinx error; {0}".format(e))
'''
try:
text = self.recognizer.recognize_google(audio)
await self.bot.send_embed(self.text_channel, "I think you said: `{}`".format(text))
except speech_recognition.UnknownValueError:
# await self.bot.send_embed(self.text_channel, ":no_entry: Google Speech Recognition could not understand audio")
await self.bot.send_embed(self.text_channel, ":no_entry: I couldn't understand that")
except speech_recognition.RequestError as e:
await self.bot.send_embed(self.text_channel, ":warning: Could not request results from Google Speech Recognition service; {}".format(e))
else:
response = clients.aiml_kernel.respond(text)
# TODO: Handle brain not loaded?
if not response:
games_cog = client.get_cog("Games")
if not games_cog: return
response = await games_cog.cleverbot_get_reply(text)
await self.bot.send_embed(self.text_channel, "Responding with: `{}`".format(response))
await self.play_tts(response, self.bot.user)
# open("data/heard.pcm", 'w').close() # necessary?
# os.remove ?
评论列表
文章目录