#Speech Recognition module problem

1 messages · Page 1 of 1 (latest)

steep cargoBOT
#

@green carbon

__frostxd Uploaded Some Code
Uploaded these files to a Gist
green carbon
#

The problem's with chat() function, for the rest of the operations, text to speech recognition is working, but for chat(), it's not, I have implemented speaker.Speak in both function as well as else block, but the issue still remains

lilac cape
#

Do you get an error?

green carbon
#

no, the terminal is showing the output, it's just that the speaker.Speak isn't working

lilac cape
#

What output? Your chat() function isn't printing anything to the terminal?

#

Oh I see the problem

#

!exec

if "using ai".lower() or "using AI" in "foo":
    print("ran")
steep cargoBOT
lilac cape
#

!exec

if "using ai".lower() in "foo" or "using AI" in "foo":
    print("ran")
steep cargoBOT
lilac cape
#
elif "Using AI".lower() in query.lower() or "Using Artificial Intelligence".lower() in query.lower(): 

You need to change line 149 to something like that

green carbon
#

what?... there is

lilac cape
#

There is what?

green carbon
#

oh, I didn't copied the print statement from my code, my bad

green carbon
lilac cape
#

"Using AI".lower() always evaluates to True

#

You basically have this...

if True or "Using Artificial Intelligence" in query.lower(): 
lilac cape
green carbon
#

Yo that worked

#

but how?

#

I thought my else block or chat() function was wrong

lilac cape
# green carbon but how?

Because if you want to check if multiple things are in something you need to do it like this:

if "foo" in "bar" or "baz" in "bar":

You can't do

if "foo" or "baz" in "bar"

It's getting evaluated like this:

if ("foo") or ("baz" in "bar")

It's just looking at the "foo" on it's own and since a non-empty string is True then that if statement will always be True

green carbon
#

Wait..

#

My elif block with using ai should only work if I am saying a sentence with words using ai, it shouldn't work in any other case

lilac cape
#

What you had before meant it was running in every case

#

Now it should work as you expect

green carbon
#

oh

#

thx for help

lilac cape
#

No problem