Rasa Voice Assistance

import requests import subprocess import speech_recognition as sr from gtts import gTTS from playsound import playsound import random from translate import Translator import json

bot_message = “” message = “”

translator = Translator(to_lang = ‘fr’)

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}​​​​​​​”)

myobj = gTTS(text=translator.translate(bot_message), lang=‘fr’) i=random.randint(1,1000) file=‘new’+str(i)+’.mp3’ myobj.save(file) playsound(file)

while bot_message != “Bye” or bot_message != “thanks”:

r = sr.Recognizer()


with sr.Microphone() as source:
    print("Speak ")
    audio = r.listen(source)
    try:
        message = r.recognize_google(audio)
        translator = Translator(to_lang='en')
        print("you said : {​​​​​​​}​​​​​​​".format(translator.translate(message)))
    except:
        print("Sorry could not recognize your voice")
if len(message)==0:
    continue
print("sending message now ...")

r = requests.post('http://localhost:5002/webhooks/rest/webhook',json = {​​​​​​​"message":translator.translate(message)}​​​​​​​)
print ("Bot Says, ",end = '')
for i in r.json():
    bot_message = i['text']
    print(f"{​​​​​​​bot_message}​​​​​​​")   



translator = Translator(to_lang='hi')
myobj = gTTS(text=translator.translate(bot_message))
i=random.randint(1,100)
file1='new'+str(i)+'.mp3'
myobj.save(file1) 



playsound(file1)

In above code , I’m using microphone as an audio source, now I want to deploy my voice assistant on server and for that I need to use Webrtc as an audio source. I don’t know how to use webrtc with rasa. Any help or suggestions will be appreciated.

Thanks

Hi @harman93singh

What’s the problem with implementing similar to what you have shown in the code snippet?

I think you could improve your code above by incorporating it into a custom channel for your input. There is a example given in this documentation:

Happy to answer any follow-on questions related to setting up the custom channel. Although, I’m not familiar with Webrtc specifically.