Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
input timer
#1
So I'm revising wake word and input for a project I'm working on I made this sample text so you can see what I'm trying to do basically two ways of waking it up.

The First Way:
you can say wake hi witch will wake it up and do the command all in one input it works

The Second Way:
this is where I'm having trouble so if you say wake it will wait for the command but i want a timer that if no input was given it will return to the top of the loop and wait for the wake word again. However the problem I'm running into is that once it returns to the top of the loop I have to hit enter or type something in before it will refresh the input so it can take the wake word. where am I going wrong and why is it doing this any help would be appreciated.
from threading import Timer


def inp():
    txt = input("cmd: ").lower()
    # txt = speech.record_audio().lower()
    return txt


def wake_word(x):
    wake_words = ['wake', ]  # list of wake words
    x = x.lower()  # converting text to all lower case words

    for phrase in wake_words:
        if phrase in x:
            find_length = len(phrase)
            return [True, find_length]
    return False


while True:

    try:
        timeout = 5
        t = Timer(timeout, print, ['Sorry, times up'])
        print("here")
        text = inp()
        response = ''
        if wake_word(text):

            if wake_word(text)[1] == len(text):  # if only wake word was given with no
                t.start()
                text = input("cmd: ")
                t.cancel()
            if "hi" in text:
                response = "hello"

        print(response)
    except Exception as e:
        print(e)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  email timer/rss feed timer ndiniz 1 730 Feb-02-2021, 07:18 PM
Last Post: nilamo
  input timer Nickd12 13 1,924 Dec-08-2020, 01:55 AM
Last Post: Nickd12

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020