Python Forum
Ignore WakeWord after it's said
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ignore WakeWord after it's said
#1
Hello,

I added a wakeword to my voice assistant but now when I say a command like: "Who is Albert Einstein", It searches with the wake word in the command, like so: "Baxter who is Albert Einstein", instead of just searching "who is Albert Einstein".

How can I ignore the wakeword so once I say it, it takes in my commands without concatenating the wakword to it?

Thanks in advance.


The full code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env python3
 
from concurrent.futures import process
import json
import random
import datetime
import operator
import os
import time
import sys
import requests
from bs4 import BeautifulSoup
import wikipedia
import wolframalpha
import pyttsx3
import speech_recognition as sr
 
#-------------------------------------------------------------------------------------
                            #Commander Name (You) and A.I Name
#-------------------------------------------------------------------------------------
Commander = "Commander"
AI_Name = 'Baxter'
#-------------------------------------------------------------------------------------
 
def speak(audio):
    speaker = pyttsx3.init ()
    voices = speaker.getProperty('voices')
    speaker.setProperty('voice',voices[1].id)
    speaker.setProperty ('rate', 180)
    speaker.say (audio)
    speaker.runAndWait ()
## Test to see all avaliable voices
# engine = pyttsx3.init()
# voices = engine.getProperty('voices')
# for voice in voices:
#     print(voice, voice.id)
#     engine.setProperty('voice', voice.id)
#     engine.say("Hello World!")
#     engine.runAndWait()
#     engine.stop()
     
 
def wishMe():
    hour = int(datetime.datetime.now().hour)
    if hour>=0 and hour<12:
        speak("Good Morning" + Commander)
    elif hour>=12 and hour<18:
        speak("Good Afternoon" + Commander)  
    else:
        speak("Good Evening" + Commander)
 
 
def listen():
    hear = sr.Recognizer()
    with sr.Microphone() as source:
        print("Listening...")
        audio = hear.listen(source) 
    #---------------------------
    # Uses google API to listen
    try:
        print("Recognizing...")
        command = hear.recognize_google(audio, language='en-in')
        print(f'{Commander} : {command}\n')
 
        # Wait for WakeWord
        if (command.split(' ')[0] == AI_Name):
            speak("Executing Command")
            process(command)
    #--------------------------------
 
    except:
            pass
 
    return command
 
wishMe()
speak("How may I be of service?")
 
while True:
    listen()
    command = listen()
    command=str(command).lower()
 
    #-------------------------------------------------------------------------------------
                            #Search Wikipedia (General Info)
    #-------------------------------------------------------------------------------------
    if ('weather' not in command):
        if ('who is' in command) or ('what is the' in command) or ('what is a' in command) or ("what is" in command):
            if ('time' not in command):
                if ('news' not in command):
                    speak('Searching Wikipedia...')
                    command = command.replace("who is","")
                    command = command.replace("what is the","")
                    command = command.replace("what is a","")
                    command = command.replace("what is","")
                    results = wikipedia.summary(command, sentences = 2)
                    #----------------------
                    #Auto typing animation:
                    print("Baxter: ", end="")
                    for i in results:
                        sys.stdout.write(i)
                        sys.stdout.flush()
                        time.sleep(0.05)
                    print("\n")
                    #----------------------
                    speak(results)
    #-------------------------------------------------------------------------------------
                    #Search Wolfram Alpha (Math/Conversions, Definitions)
    #-------------------------------------------------------------------------------------
    if ('weather' not in command):
        if ('news' not in command):
            if ('calculate' in command) or ("what's" in command) or ('define' in command):
                speak('Searching Wolfram Alpha...')
                command = command.replace("calculate","")
                command = command.replace("what's","")
                command = command.replace("define","")
                # Wolframalpha App Id
                appId = 'JH9XHR-W9J76L7H5A'
                # Wolfram Instance
                client = wolframalpha.Client(appId)
                res = client.query(''.join(command))
                results = next(res.results).text
                #----------------------
                #Auto typing animation:
                print("Baxter: ", end="")
                for i in results:
                    sys.stdout.write(i)
                    sys.stdout.flush()
                    time.sleep(0.05)
                print("\n")
                #----------------------
                speak(results)
    #-------------------------------------------------------------------------------------
                                #Stop Program/Script Command
    #-------------------------------------------------------------------------------------
    if ('stop' in command) or ('shutdown' in command) or ('quit' in command):
        speak("Shutting Down...")
        response = "Terminating program..."
        #----------------------
        #Auto typing animation:
        print("Baxter: ", end="")
        for i in response:
            sys.stdout.write(i)
            sys.stdout.flush()
            time.sleep(0.2)
        print("\n")
        #----------------------
        exit()
    #-------------------------------------------------------------------------------------
Reply
#2
On line 82 it looks like you've got the command string. Check to see if that starts with the wake word and slice it out.
Reply
#3
(Apr-01-2022, 12:26 AM)popejose Wrote: On line 82 it looks like you've got the command string. Check to see if that starts with the wake word and slice it out.

No luck. It didn't work.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Good way to ignore case when searching elements? Winfried 1 928 Apr-25-2024, 12:39 PM
Last Post: menator01
  How to ignore "Retrying (Retry(total=2, connect=2, read=5, redirect=5, status=None))" const 3 4,383 Mar-26-2022, 08:55 AM
Last Post: ndc85430
  Ignore first few letters of a line when reading file. ShakeyPakey 16 11,588 May-30-2020, 02:17 PM
Last Post: BitPythoner
  How to ignore empty columns from DB? Winfried 1 3,035 May-15-2020, 08:35 PM
Last Post: menator01
  How to make the script ignore down devices. wagnergt12 4 5,014 Apr-20-2020, 11:45 PM
Last Post: wagnergt12
  Regex ignore JohnnyCoffee 1 3,588 Mar-16-2020, 12:16 PM
Last Post: scidam
  Ignore Folder Evil_Patrick 3 5,174 Oct-29-2019, 07:44 AM
Last Post: Gribouillis
  How to ignore formulas when reading excel file SriMekala 3 8,163 Aug-16-2019, 04:04 PM
Last Post: buran
  How to ignore - ERROR: The system was unable to find the specified registry key or va asheru93 9 8,514 Feb-04-2019, 06:35 AM
Last Post: asheru93
  Ignore character in if statement Fizo 6 4,828 Sep-09-2018, 12:39 PM
Last Post: Fizo

Forum Jump:

User Panel Messages

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