Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.Windows.Speech;
- using System.Collections.Generic;
- using System.Linq;
- public class Recognition : MonoBehaviour {
- KeywordRecognizer keywordRecognizer;
- Dictionary<string, System.Action> keywords = new Dictionary<string, System.Action>();
- private void Start()
- {
- keywords.Add("Ka", () =>
- {
- GoCalled();
- });
- keywords.Add("Ma", () =>
- {
- GoCalled2();
- });
- keywords.Add("Te", () =>
- {
- GoCalled3();
- });
- keywordRecognizer = new KeywordRecognizer(keywords.Keys.ToArray());
- keywordRecognizer.OnPhraseRecognized += KeyWordRecognizerOnPhraseRecognized;
- keywordRecognizer.Start();
- }
- void KeyWordRecognizerOnPhraseRecognized(PhraseRecognizedEventArgs args)
- {
- System.Action keywordAction;
- if(keywords.TryGetValue(args.text, out keywordAction))
- {
- keywordAction.Invoke();
- }
- }
- void GoCalled()
- {
- print("ISSO É");
- }
- void GoCalled2()
- {
- print("MOERTE");
- }
- void GoCalled3()
- {
- print("VIDA");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement