Closed catbaron0 closed 5 years ago
I think we got this problem because the script voice_recognition.py
has not been updated for ver.2.0b, maybe.(There is one miss-spelling of recognise
so I wonder if this function really works in ver.1.0). So I tried to fix it. Update the def recognize_speech(self, bot, update, args=[]
block as the code below:
def recognize_speech(self, bot, update, args=[]):
"""
Recognise voice message. Triggered by `/recog`.
Args:
bot: Telegram Bot instance
update: Message update
args: Arguments from message
"""
if not getattr(update.message, "reply_to_message", None):
text = self._("/recog lang_code\n" \
"Reply to a voice with this command to recognize it.\n" \
"examples:\n/recog zh\n/recog en-US\n\nSupported languages:\n")
text += "\n".join("%s: %r" % (i.engine_name, i.lang_list) for i in self.voice_engines)
return self._reply_error(bot, update, text)
if not getattr(update.message.reply_to_message, "voice"):
return self._reply_error(bot, update,
self._("Reply only to a voice with this command to recognize it. (RS02)"))
if update.message.reply_to_message.voice.duration > 60:
return self._reply_error(bot, update, self._("Only voice shorter than 60s is supported. (RS04)"))
f = bot.get_file(update.message.reply_to_message.voice.file_id)
file = tempfile.NamedTemporaryFile()
f.download(out=file)
file.seek(0)
results = OrderedDict()
if not args:
args=['zh']
for i in self.voice_engines:
results["%s (%s)" % (i.engine_name, args[0])] = i.recognize(file.name, args[0])
msg = ""
for i in results:
msg += "\n<b>%s</b>:\n" % html.escape(i)
for j in results[i]:
msg += "%s\n" % html.escape(j)
msg = self._("Results:\n{0}").format(msg)
bot.send_message(update.message.reply_to_message.chat.id, msg,
reply_to_message_id=update.message.reply_to_message.message_id,
parse_mode=telegram.ParseMode.HTML)
file.close()
Baiduspeech works well for me, but I got some problem with Bingspeech:
/recog
Results:
Bing (zh):
å 为ä¹åçè¿å¾å¤é£ç§è·ä½ 说è¿äºåå°±ç®äºåç¶åå¢æ²¡æ³å°æ天ä¸çäºã
å 为ä¹åçè¿å¾å¤é£ç§è·ä½ 说è¿äºå°±ç®äºåç¶åå¢æ²¡æ³å°æ天ä¸çäºã
å 为ä¹åçè¿å¾å¤é£ç§è·ä½ 说è¿äºåå°±ç®äºåç¶åå¢æ²¡æ³å°ä½ ç¶åä¸çäºã
å 为ä¹åçè¿å¾å¤é£ç§è·ä½ 说è¿äºåå°±ç®äºåç¶åå¢æ²¡æ³å°ä½ 天ä»æ¢äºã
å 为ä¹åçè¿å¾å¤é£ç§è·ä½ 说è¿äºå°±ç®äºåç¶åå¢æ²¡æ³å°ä½ ç¶åä¸çäºã
Baidu (zh):
真的受不了了就算了嘛,
Seems some coding problem happened. I just want to recognize speech for wechat so Baidu is enough for now.
Thank you for the report. Actually I'm considering isolating this voice recognition module as a middleware. I will try to fix this when the middleware is released.
Voice recognition implemented as middleware by @catbaron0. Thank you for your effort!
Here is the log: