Created
January 29, 2017 00:11
-
-
Save flushpot1125/7643a95e1fede12182601bac42ebb859 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*copied from "https://developer.microsoft.com/en-us/windows/holographic/holograms_101"*/ | |
using System.Collections.Generic; | |
using System.Linq; | |
using UnityEngine; | |
using UnityEngine.Windows.Speech; | |
public class SpeechManager : MonoBehaviour | |
{ | |
KeywordRecognizer keywordRecognizer = null; | |
Dictionary<string, System.Action> keywords = new Dictionary<string, System.Action>(); | |
// Use this for initialization | |
void Start() | |
{ | |
keywords.Add("Reset world", () => | |
{ | |
// Call the OnReset method on every descendant object. | |
this.BroadcastMessage("OnReset"); | |
}); | |
keywords.Add("Drop Sphere", () => | |
{ | |
var focusObject = GazeGestureManager.Instance.FocusedObject; | |
if (focusObject != null) | |
{ | |
// Call the OnDrop method on just the focused object. | |
focusObject.SendMessage("OnDrop"); | |
} | |
}); | |
// Tell the KeywordRecognizer about our keywords. | |
keywordRecognizer = new KeywordRecognizer(keywords.Keys.ToArray()); | |
// Register a callback for the KeywordRecognizer and start recognizing! | |
keywordRecognizer.OnPhraseRecognized += KeywordRecognizer_OnPhraseRecognized; | |
keywordRecognizer.Start(); | |
} | |
private void KeywordRecognizer_OnPhraseRecognized(PhraseRecognizedEventArgs args) | |
{ | |
System.Action keywordAction; | |
if (keywords.TryGetValue(args.text, out keywordAction)) | |
{ | |
keywordAction.Invoke(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment