Sunday, May 31
Shadow

How to build a Multilingual Voice Bot | Rasa chatbot | Coronavirus Awareness

Chatbot is that we can build easily but we need a voice bot that can talk to us, but there are people who don’t understand English language. Either they understand their local language or they are not really good in english speaking and feel proud speaking there local language. So they only prefer their local language. So this session is for them who prefer their local language for speaking.

This is an awareness post for all to tell them about the corona virus, to help them be safe, prevent them for getting into the contact of coronavirus. What are the symptoms, vaccination availability, incubation, concerns, etc.

In this post you will learn and understand how to build a voice bot that can talk you in your local language whichever you will prefer to talk to someone. Also you will learn and understand how to write the code to do it.

Now let’s get started and understand how to build a voice bot that can talk to you in different language. Firstly, we have to build a chatbot that can be used with the voice bot to spread the awareness for coronavirus. If you are new to Rasa then checkout this link to learn how to build a rasa chatbot:

http://innovateyourself.in/building-an-end-to-end-conversational-chat-bot-cum-assistant-with-rasa/

Also, you can check this session to learn how to build the Rasa chatbot,


When you have your chatbot ready with you now we can start further to convert it to the voice bot and how to do this conversion we have already done in our previous post.

Now when we are done with the conversion of the rasa chat bot to the voice bot (in English language). It’s time to learn how to take the input in any language other than English and to reply accordingly. For this step we have to make changes in the Voice_bot.py file which we have created during the conversion process.

First, install a module named “translate” which will be used here to translate one language to the other. To install this firstly activate the environment in terminal where you have all the packages installed for the rasa chatbot and then type:

pip install translate

this will install the module translate and also all the dependencies that are required for the module.

After the installation, we have to merge the below code as and where the language translation is required:

from translate import Translator 
translator = Translator(from_lang='en',to_lang='hi') 
translation = translator.translate("hello")

In the above code we are importing the class name Translator from the module which is created to take the input in any language(for example. Hindi) to any language(for example. English). Here translator is the object that is make sure what will be the input language and what will be the output language and accordingly the method name “translate” from the object “translator” will take the input text in the language specified in “from_lang”and convert it into the language specified in “to_lang”.

Also, if in case you don’t know the input language of the spoken phrase then you can leave “from_lang” and only specify the “to_lang”. In this case google will automatically detect the input language and accordingly translate it into the language mentioned.

You can get the complete code on my git repository. To get the full code with the working go to this link:

https://github.com/ashus3868/CoronsaVirus_voice_bot

Also, if you wish to see the practical implementation of the project the do check this session as well:

For any doubts or queries related to the topic, feel free to leave a comment below in the comment section. Also do comment your valuable feedback in the feedback so as to appreciate or improve ourselves. For any further information or queries you can also WhatsApp me at +91 8209829808.

Till then stay tuned and happy learning 🤗

10 Comments

  • Kajenthirakumar

    import requests
    from translate import Translator

    bot_message = “”
    message=””

    r = requests.post(‘http://localhost:5002/webhooks/rest/webhook’, json={“message”: “Hello”})

    print(“Bot says, “,end=’ ‘)
    for i in r.json():
    bot_message = i[‘text’]
    print(f”{bot_message}”)

    translator= Translator(to_lang=”hi”)
    translation = translator.translate(bot_message)

    ——– sir its showssome error can u correct me ——

      • Kajenthirakumar

        Bot says, Hey! I’m Bus booking Assistant, How Can I help You ?
        अरे! मैं बस बुकिंग सहायक हूं, मैं आपकी कैसे मदद कर सकता हूं?

        Process finished with exit code 0

        sir i got this type error

        • Kajenthirakumar

          Sir can i implement this code in action file ? or how can i pass user input here and how can pass user response
          —————————————————————————————

          import requests
          from translate import Translator

          bot_message = “”
          message=””

          translator = Translator(from_lang=’en’,to_lang=’hi’)
          translation = translator.translate(“hello”)

          r = requests.post(‘http://localhost:5002/webhooks/rest/webhook’, json={“message”: “Hello”})

          print(“Bot says, “,end=’ ‘)
          for i in r.json():
          bot_message = i[‘text’]
          print(f”{bot_message}”)

          translator= Translator(to_lang=’hi’)
          translation = translator.translate(bot_message)
          print(translation)

Leave a Reply

Your email address will not be published. Required fields are marked *