- Home /
"Keyword already used" error message by voice recognizer script
The script below is one that I've attached to the small sphere in the image below. It is a modified clone of a working script that I have attached to the large sphere in the image below. The working script will move the large sphere forward and back, up and down, using voice commands. I want to use voice commands to change the color of the small sphere to yellow, blue, green, or red. I have a third script that is working and which allows me to change the color of the plane using keyboard inputs, e.g. typing Y changes the plane to yellow.
To create script for the small sphere, I'm trying to use the known good color rendering code of the script for the plane and the known good voice movement code of the script for the large sphere. Unfortunately, I'm running to a "keyword already used" type of error when I do this. The error message is "Argument Exception: At least one keyword must be specified. Parameter name: keywords".
NOTE: In the working voice script the statement "actions.Add("forward", Forward);" was fine and produce no error message so, in the clone script, I used "actions.Add('yellow", Yellow);" but that produced an error that "yellow was already used as a keyword". When I commented out that statement, I got the error message that "...At least one keyword must be specified". So I'm kind of in a Catch 22 situation.
QUESTION: What can be done to fix this? Thanks in advance for you help. It is greatly appreciated. I'm new to Unity. Cheers, Bob G
IMAGE:
SCRIPT: using System; using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.Windows.Speech;
public class VoiceInput05 : MonoBehaviour { private KeywordRecognizer keywordRecognizer; private Dictionary actions = new Dictionary (); public Color altColor = Color.blue; public Renderer rend;
//public Action White { get; private set; }
void Start()
{
//Got warning from Unity that, for VoiceInput05, the terms "Forward, Back, Up, and Down were a problem ("forward" is already a keyword used by Keyword Recognizer)
//so I commented their actions out but then got a warning that "at least one keyword was required". So replaced the Forward with Yellow etc. But then I got a warning
//that red, yellow, blue, and green were already defined as keywords so I commmented them out as well. Now I get the warning "...At least one keyword must be specified".
//actions.Add("forward", Forward);
//actions.Add("back", Back);
//actions.Add("up", Up);
//actions.Add("down", Down);
//actions.Add("yellow", Yellow);
//actions.Add("blue", Blue);
//actions.Add("green", Green);
//actions.Add("red", Red);
keywordRecognizer = new KeywordRecognizer(actions.Keys.ToArray());
keywordRecognizer.OnPhraseRecognized += RecognizedSpeech;
keywordRecognizer.Start();
rend = GetComponent<Renderer>();
}
private void RecognizedSpeech(PhraseRecognizedEventArgs speech)
{
//Debug.Log(speech.text);
actions[speech.text].Invoke();
}
private void Red()
{
rend.material.color = Color.red;
}
private void Yellow()
{
rend.material.color = Color.yellow;
}
private void Blue()
{
rend.material.color = Color.blue;
}
private void Green()
{
rend.material.color = Color.green;
}
}
Answer by ragsr · Dec 31, 2018 at 06:16 PM
UPDATE FOR MY POST: I just retested the behavior of the script for the small sphere after reinstating the "actions.Add("yellow", Yellow);" like statements for the four colors and it WORKED!
QUESTION: Is it ok to ignore the error messages?
Error message form: Error: there already is a keyword recognizer with "yellow" as one of its keywords. UnityEngine.Windows.Speech.KeywordRecognizer:.ctor(String[])
Cheers, Bob G.
Your answer
Follow this Question
Related Questions
health script do not work when collision detected 1 Answer
Keyboard detector 0 Answers
does not want to setparent 2 Answers
Rotate with script and point 1 Answer
Dense joid joining! Help 0 Answers