Advertisement
Caminhoneiro

Input voz windows

Feb 8th, 2017
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.24 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.Windows.Speech;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6.  
  7. public class Recognition : MonoBehaviour {
  8.  
  9.     KeywordRecognizer keywordRecognizer;
  10.     Dictionary<string, System.Action> keywords = new Dictionary<string, System.Action>();
  11.  
  12.     private void Start()
  13.     {
  14.         keywords.Add("Ka", () =>
  15.         {
  16.             GoCalled();
  17.         });
  18.  
  19.         keywords.Add("Ma", () =>
  20.         {
  21.             GoCalled2();
  22.         });
  23.        
  24.         keywords.Add("Te", () =>
  25.         {
  26.             GoCalled3();
  27.         });
  28.  
  29.         keywordRecognizer = new KeywordRecognizer(keywords.Keys.ToArray());
  30.         keywordRecognizer.OnPhraseRecognized += KeyWordRecognizerOnPhraseRecognized;
  31.         keywordRecognizer.Start();
  32.     }
  33.  
  34.     void KeyWordRecognizerOnPhraseRecognized(PhraseRecognizedEventArgs args)
  35.     {
  36.         System.Action keywordAction;
  37.  
  38.         if(keywords.TryGetValue(args.text, out keywordAction))
  39.         {
  40.             keywordAction.Invoke();
  41.         }
  42.     }
  43.  
  44.     void GoCalled()
  45.     {
  46.         print("ISSO É");
  47.     }
  48.  
  49.     void GoCalled2()
  50.     {
  51.         print("MOERTE");
  52.     }
  53.  
  54.     void GoCalled3()
  55.     {
  56.         print("VIDA");
  57.     }
  58.  
  59. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement