- Home /
Voice Recognition
Hello,
I am currently working on a project using UnityEngine.Windows.Speech. I have a problem trying to move my character because I think it has to be inside the Update method otherwise it doesn't update every frame and I get a jittery/stutter movement.
//Declaration
private string[] voiceCommands = { "Jump", "Forward" };
private KeywordRecognizer t_KeywordRecognizer;
// Initialisation in Start
t_KeywordRecognizer = new KeywordRecognizer(voiceCommands);
t_KeywordRecognizer.OnPhraseRecognized += OnPhraseRecognized;
t_KeywordRecognizer.Start();
public void OnPhraseRecognized(PhraseRecognizedEventArgs args)
{
[...]
switch (args.text)
{
[...]
case "Forward":
transform.position += transform.forward * Time.deltaTime * movementSpeed;
break;
}
}
The jumping works fine, but the movement is like a small step and stops. However, if I put
transform.position += transform.forward * Time.deltaTime * movementSpeed;
inside the Update method, the character moves forward with no issues.
Any ideas on how I can address this or what I'm doing wrong? :)
EDIT: Forgot to mention that if I call the OnPhraseRecognized in Update with "null" as parameter, it says it cannot convert null to PhraseRecognizedEventArgs
Answer by AtlanticsLeo · Mar 07, 2019 at 06:42 AM
In your case, it actually work like Input.GetKeyDown()
so it will only move one step each time you call it.