It looks like you're using an Ad Blocker.

Please white-list or disable AboveTopSecret.com in your ad-blocking tool.

Thank you.

 

Some features of ATS will be disabled while you continue to use an ad-blocker.

 

Getting a chatbot to SPEAK responses

page: 1
1

log in

join
share:

posted on Jan, 10 2016 @ 05:51 PM
link   
I'm new to programming so you'll have to forgive me for not being well educated on its jargon. I'm starting out on Python as I've just found that easier out of the many so far. I'm dabbling with simple chatbot code and I've got the text responses and the conversation tree working properly, however I'd really like the chatbot to SAY the response chosen.

I've set a list of responses (I'll place the code below) to be chosen at random. I'm able to get my computer to say something using:

os.system("say" 'Hello'")

But that's the only way I've found out how. I've tried placing parts of the code into those brackets in the hopes that I'd stumble across a way but I've so far had no luck. Does anyone know any ideas how I'd get this to work?

HERE'S MY CODE:

import random
import sys
import os
def show_response(options):
---choice = random.randint(0, len(options) -1)
---print(options[choice])

random.seed(None)

while True:
---userInput = input(">>>")

---if userInput in ["Ava, you there?"]:
------list = ["Indeed I am, Sir.", "Yes, Sir. What do you need?", "For you, Sir, always.", "I am now.", "What is it, Sir?", "I'm right here.", "How may I assist you, Sir?", "How may I assist you?", "You need something, Sir?"]
------choice = random.randint(0, len(list) -1)
------print(list[choice])
---elif userInput in ["Wake up, Ava"]:
------list = ["What is it, Sir?", "How can I help?", "How can I help, Sir?", "Hello, Sir.", "Hello, Sir. Is there anything you need?", "How may I assist you?", "How may I assist you, Sir?"]
------choice = random.randint(0, len(list) -1)
------print(list[choice])
---elif userInput in ["Hey, Ava"]:
------list = ["What is it, Sir?", "How can I help?", "How can I help, Sir?", "Hello, Sir.", "Hello, Sir. Need anything?", "How may I assist you?", "How may I assist you, Sir?", "You need something, Sir?"]
------choice = random.randint(0, len(list) -1)
------print(list[choice])


list = ["Responses made by Ava"]
^^ This is what I want to be read out once the console is running. Whatever response is randomly chosen from that list needs to be spoken instantly. No idea if possible with Python. Again, I'm a rookie and have no clue on where to start. My progress has been achieved with the help of a good friend but he's never truly worked on a.i/chatbot programming so he has no idea either haha.

Many thanks in advance!
edit on 10-1-2016 by jonwhite866 because: (no reason given)




posted on Jan, 10 2016 @ 10:48 PM
link   
everywhere you see print(list[choice]), add another line after it:

os.system("say " + "'" + list[choice] + "'")

Note that what looks like 5 ticks above is " ' " without spaces. This quotes the text for passing it to the say command.



posted on Jan, 11 2016 @ 07:14 AM
link   
a reply to: okachobi

Thank you. I've been trying to add print(list[choice]) into it but not like that and NOT below each print haha. I'll give that a go!

EDIT:

Okay, it works but only sometimes. Other times it comes up with this error:

sh: -c: line 0: unexpected EOF while looking for matching `''
sh: -c: line 1: syntax error: unexpected end of file

Or

sh: sayYes sir: command not found

From further analysis, I've found that all the other responses within the 'elif' statements work perfectly. In the 'if', only this one line seems to be causing the problem: "I'm right here."
edit on 11-1-2016 by jonwhite866 because: (no reason given)



posted on Jan, 11 2016 @ 08:10 AM
link   
a reply to: okachobi

Okay, I managed to figure out the problem. For some reason it does not like apostrophes, so any response with an apostrophe (e.g. I'm, don't, there's, etc) instantly creates the 'EOF' error. Still no idea what caused the 'sh: command not found' error, but for now it doesn't matter.

Thanks for your help buddy!
edit on 11-1-2016 by jonwhite866 because: (no reason given)



posted on Jan, 11 2016 @ 06:39 PM
link   
a reply to: jonwhite866

Try changing it to:

os.system("say " + """ + list[choice] + """)

ATS is stripping out the backslash above, but you should put a backslash (can't show it because it is stripped out) before the quote mark between the other two quotes. I've tried editing it multiple times but its stripping it every time. So change the ' to a " but put a backslash in front of the "

That should fix your apostrophe issue.

edit on 11-1-2016 by okachobi because: ATS stripping characters out....



new topics

top topics
 
1

log in

join