Caminhoneiro

VoiceRecogAndStreamming

Apr 11th, 2017
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.30 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. using UnityEngine.SceneManagement;
  7. using System.Diagnostics;
  8.  
  9.  
  10. public class Recognition : MonoBehaviour
  11. {
  12.     KeywordRecognizer keywordRecognizer;
  13.     Dictionary<string, System.Action> keywords = new Dictionary<string, System.Action>();
  14.  
  15.     private static Recognition instance;
  16.  
  17.     [SerializeField]
  18.     [Header("Call Support keyword")]
  19.     string supportKeyWord;
  20.    
  21.     [SerializeField]
  22.     [Header("Call Remote Access keyword")]
  23.     string RemoteAccess;
  24.  
  25.     [SerializeField]
  26.     [Header("Call shutdown keyword")]
  27.     string shutDownKeyword;
  28.  
  29.     [SerializeField]
  30.     [Header("Call Statiscs keyword")]
  31.     string dataKeyword;
  32.  
  33.     [SerializeField]
  34.     [Header("Call Back to main menu keyword")]
  35.     string mainMenuKeyword;
  36.  
  37.     private void Start()
  38.     {
  39.         DontDestroyOnLoad(this.gameObject);
  40.  
  41.         #region Singleton
  42.         if (instance == null)
  43.             instance = this;
  44.         else
  45.         {
  46.             Destroy(this.gameObject);
  47.             return;
  48.         }
  49.         #endregion
  50.  
  51.         keywords.Add(supportKeyWord, () =>
  52.         {
  53.             GoCalled();
  54.         });
  55.  
  56.         keywords.Add(RemoteAccess, () =>
  57.         {
  58.             GoCalled2();
  59.         });
  60.  
  61.         keywords.Add(shutDownKeyword, () =>
  62.         {
  63.             GoCalled3();
  64.         });
  65.  
  66.  
  67.         keywords.Add(dataKeyword, () =>
  68.         {
  69.             GoCalled4();
  70.         });
  71.  
  72.  
  73.         keywords.Add(mainMenuKeyword, () =>
  74.         {
  75.             GoCalled5();
  76.         });
  77.  
  78.  
  79.         keywordRecognizer = new KeywordRecognizer(keywords.Keys.ToArray());
  80.         keywordRecognizer.OnPhraseRecognized += KeyWordRecognizerOnPhraseRecognized;
  81.         keywordRecognizer.Start();
  82.     }
  83.  
  84.     void KeyWordRecognizerOnPhraseRecognized(PhraseRecognizedEventArgs args)
  85.     {
  86.         System.Action keywordAction;
  87.  
  88.         if (keywords.TryGetValue(args.text, out keywordAction))
  89.         {
  90.             keywordAction.Invoke();
  91.         }
  92.     }
  93.  
  94.     void GoCalled()
  95.     {
  96.         print("Suporte Γ© minha rola dura");
  97.     }
  98.  
  99.     void GoCalled2()
  100.     {
  101.         print("Acesso remoto");
  102.         string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, "TeamViewer");
  103.         System.Diagnostics.Process.Start(filePath);
  104.         //Application.OpenURL((Application.dataPath) + "file:///C:/Program%20Files%20(x86)/TeamViewer/CopyRights.txt");
  105.         //Process p = new Process();
  106.         //p.StartInfo.FileName = "file:///C:/Program%20Files%20(x86)/TeamViewer/TeamViewer.exe";
  107.         //Process.Start("Mozilla.exe", "https://rilix.herokuapp.com/login");
  108.         //Application.OpenURL((Application.dataPath) + @"C:\Program Files (x86)\TeamViewer\TeamViewer.exe");
  109.         //System.Diagnostics.Process.Start("TeamViewer.exe");
  110.         //System.Diagnostics.Process.Start(Application.dataPath + "file:///C:/Program%20Files%20(x86)/TeamViewer/TeamViewer.exe");
  111.     }
  112.  
  113.     void GoCalled3()
  114.     {
  115.         print("Sai fora, DESLIGUEI MERMΓƒO");
  116.     }
  117.  
  118.     void GoCalled4()
  119.     {
  120.         print("Estatisticas");
  121.         SceneManager.LoadScene("demo");
  122.     }
  123.  
  124.  
  125.     void GoCalled5()
  126.     {
  127.         print("Back to main");
  128.         SceneManager.LoadScene("Main");
  129.     }
  130. }
Add Comment
Please, Sign In to add comment