GithubHelp home page GithubHelp logo

Comments (3)

catbaron0 avatar catbaron0 commented on June 12, 2024

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.

from efb-telegram-master.

blueset avatar blueset commented on June 12, 2024

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.

from efb-telegram-master.

blueset avatar blueset commented on June 12, 2024

Voice recognition implemented as middleware by @catbaron0.
Thank you for your effort!

from efb-telegram-master.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.