-
Notifications
You must be signed in to change notification settings - Fork 261
Description
In this days my friends are trying to create a robot that could look the person that in front of him than listen him. My job began in here. I have to create a chat bot that listen the person with mic than recognize what he/she says after that answer him.
Now my program can listen people and recognize the words. But my program can answer in English. Because i am Turkish i have make it in Turkish.
Is there anybody in there to help me?
This is all i got for now.
from gtts import gTTS
import os
import speech_recognition as sr
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
chatbot = ChatBot("Ron Obvious")
"""
conversation = [
"merhaba",
"sana da merhaba",
"ne haber",
"iyidir senden",
"kac yasindasin",
"18 yasindayim",
"ismin ne ",
"benim adim aytek",
"hava nasil",
"iyi bea nasil olsun"
]
"""
conversation = open('chats.txt','r').readlines()
chatbot.set_trainer(ListTrainer)
chatbot.train(conversation)
def konusma(metin):
tts= gTTS(text=metin ,lang='tr')
tts.save("aaa.mp3")
os.system("mpg321 aaa.mp3")
r= sr.Recognizer()
with sr.Microphone() as kaynak:
print("Please wait. Calibrating microphone...")
# listen for 5 seconds and calculate the ambient noise energy level
r.adjust_for_ambient_noise(kaynak, duration=5)
konusma('kalibre tamamlandi')
while True:
with sr.Microphone() as kaynak:
ses = r.listen(kaynak,timeout = None)
try:
print(r.recognize_google(ses,language="tr-TR"))
soru=r.recognize_google(ses,language="tr-TR")
response = chatbot.get_response(soru)
print(response)
konusma(str(response))
except sr.UnknownValueError:
print("Anlamadim.")
except sr.RequestError:
print("Bad Request")