# Add voice to rasa webchat

**URL:** <https://forum.rasa.com/t/add-voice-to-rasa-webchat/54507>\
**Category:** Getting Started with Rasa\
**Created:** [July 26, 2022, 9:31am UTC](https://forum.rasa.com/t/add-voice-to-rasa-webchat/54507 "2022-07-26T09:31:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![intissar](https://avatars.discourse-cdn.com/v4/letter/i/dfb087/32.png) [@intissar](https://forum.rasa.com/u/intissar)\
**Post date:** [July 26, 2022, 9:31am UTC](https://forum.rasa.com/t/add-voice-to-rasa-webchat/54507/1 "2022-07-26T09:31:59Z")

</div>

Hello, I am new in rasa chatbot. I am trying to implement voice in my bot , I am using rasa web chat [https://github.com/botfront/rasa-webchat](https://github.com/botfront/rasa-webchat) and I have a python code that contains the voice. still searching for a solution ,how to link this python file with rasa webchat. any idea please ? this is the python code:

import requests from gtts import gTTS from playsound import playsound import speech\_recognition as sr # import the library import os

bot\_message = “” message=""

r = requests.post(‘[http://localhost:5002/webhooks/rest/webhook](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}”)

tts =gTTS(text=bot\_message , lang=“en”) tts.save(“hello.mp3”) audio\_file = os.path.dirname( **file** ) + “hello.mp3” playsound(audio\_file) #playsound=playsound(“hello.mp3”) os.remove(audio\_file)

while bot\_message != “goodbye” or bot\_message!=‘thank you’: r = sr.Recognizer() # initialize recognizer with sr.Microphone() as source: # mention source it will be either Microphone or audio files. print(“Speak Anything :”) audio = r.listen(source) # listen to the source try: message = r.recognize\_google(audio) # use recognizer to convert our audio into text part. print(“You said : {}”.format(message))

```
    except:
        print("Sorry could not recognize your voice") # In case of voice not recognized clearly
if len(message)==0:
    continue
print("Sending message now...")

r = requests.post('http://localhost:5002/webhooks/rest/webhook', json={"message": message})

print("Bot says, ",end=' ')
for i in r.json():
    bot_message = i['text']
    print(f"{bot_message}")

tts =gTTS(text=bot_message , lang="ar")
tts.save("hello.mp3")
audio_file = os.path.dirname( __file__ ) + "hello.mp3"
playsound(audio_file)
#playsound=playsound("hello.mp3")
os.remove(audio_file)
```
