- Home /
I got no answer
having problems with unity voice recognition,unity voice recognition does not recognize voice
In unity, I am trying to move a simple object using this code. Not only the object does not move but also I see no log in the console. I have also checked the microphone in the setting, attached the script to the player, and checked the mic with other applications. can someone help me? Update: so I have changed the code to this to check if the start void functions well as suggested or not and yes I get the "itworked1" and "itworked2" printed to console, but nothing related to the recognized voice. I am using Unity 2019.4.13f1 personal.
using System.Collections;
using UnityEngine;
using System.Collections.Generic;
using System;
using System.Linq;
using UnityEngine.Windows.Speech;
public class scrip : MonoBehaviour{
KeywordRecognizer keywordRecognizer;
Dictionary<string, System.Action> keywords = new Dictionary<string, System.Action>();
void Start()
{
Debug.Log("it works?1");
keywords.Add("forward", Forward);
keywords.Add("up", Up);
keywords.Add("down", Down);
keywords.Add("back", Back);
keywords.Add("Go", Go);
keywordRecognizer = new KeywordRecognizer(keywords.Keys.ToArray());
keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized;
keywordRecognizer.Start();
Debug.Log("it worked2?");
}
private void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
{
Debug.Log(args.text);
keywords[args.text].Invoke();
}
private void Forward(){
transform.Translate(1,0,0);
}
private void Back(){
transform.Translate(-1,0,0);
}
private void Up(){
transform.Translate(0,1,0);
}
private void Down(){
transform.Translate(0,-1,0);
}
private void Go (){
Debug.Log("Go");
}
}
I have a similar problem, though for me it seemed to work up until either switching to a different PC or upgrading from 2019.4.4f.
On my main PC it works fine with an external USB microphone but it does not work on my laptop with integrated microphone.