Skip to content

Instantly share code, notes, and snippets.

@flushpot1125
Created January 29, 2017 05:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save flushpot1125/ec1db09a7f32e85cfa9288ef52393a72 to your computer and use it in GitHub Desktop.
Save flushpot1125/ec1db09a7f32e85cfa9288ef52393a72 to your computer and use it in GitHub Desktop.
/*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", () => {
// Call the OnReset method on every descendant object.
this.BroadcastMessage("OnReset");
});
keywords.Add("Drop", () => {
var focusObject = GazeGestureManager.Instance.FocusedObject;
if (focusObject != null) {
// Call the OnDrop method on just the focused object.
focusObject.SendMessage("OnDrop"); }
});
/*added by @WheetTweet*/
/*Recognized : 認識した*/
keywords.Add("Expand Sphere", () => {
var focusObject = GazeGestureManager.Instance.FocusedObject;
if (focusObject != null) {
// Call the OnDrop method on just the focused object.
focusObject.SendMessage("OnExpand");
}
});
/*added by @WheetTweet*/
/*Recognized : 日本語で「回転」と発音し、認識した*/
keywords.Add("kaiten", () => {
var focusObject = GazeGestureManager.Instance.FocusedObject;
if (focusObject != null) {
// Call the OnDrop method on just the focused object.
focusObject.SendMessage("OnRotate");
}
});
// 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