0
我剛開始使用Hololens,並且一直在從Microsoft網站上的教程中弄到語音識別腳本。我一直在使用unity來創建3D文本,但是,如果我嘗試使用語音命令更改文本不起作用!不能更改hololens上的文本
這是我下面的代碼:
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Windows.Speech;
using UnityEngine.UI;
public class VoiceRecognized : MonoBehaviour {
KeywordRecognizer kr = null;
Dictionary<string, System.Action> keywords = new Dictionary<string, System.Action>();
// Use this for initialization
public Text name_text;
private string testName = "Drop";
void begin() {
keywords.Add("Change",() =>
{
this.BroadcastMessage("OnReset");
});
kr = new KeywordRecognizer(keywords.Keys.ToArray());
kr.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized;
kr.Start();
}
public void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args)
{
System.Action keywordAction;
if (keywords.TryGetValue(args.text, out keywordAction))
{
keywordAction.Invoke();
}
}
// Update is called once per frame
void Update() {
}
}
其他程序,在聽到「更改」更改文本。
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
using UnityEngine;
public class ChangeText : MonoBehaviour {
public Text name_text;
void Start()
{
}
void OnReset()
{
name_text.text = "Change";
}
}
在此代碼中,我使用語音識別腳本將初始文本「Hello World」更改爲「更改」。我不確定我的Unity是否存在問題,但是我目前正在關注微軟在教程中所做的一切。
1)你確定語音命令被識別嗎? 2)是'ChangeText'類與'voiceRecognized'類位於同一個對象上嗎? –
謝謝!它不是在更改文本類 – marshmellooooooos
開始方法叫做什麼? – Everts