OfflineVoiceModule.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. namespace Rokid.UXR.Module
  5. {
  6. public class OfflineVoiceModule : MonoSingleton<OfflineVoiceModule>
  7. {
  8. private static string RK_VOICE_SERVICE = "RKVoiceCommand.";
  9. private bool m_Init = false;
  10. protected override void OnSingletonInit()
  11. {
  12. base.OnSingletonInit();
  13. this.gameObject.name = "OfflineVoiceModule";
  14. }
  15. /// <summary>
  16. /// 初始化
  17. /// </summary>
  18. public void Initialized()
  19. {
  20. if (m_Init) return;
  21. m_Init = true;
  22. }
  23. /// <summary>
  24. /// add intruct
  25. /// </summary>
  26. /// <param name="language">0 - zh, 1 - en</param>
  27. /// <param name="name">voice name</param>
  28. /// <param name="pinyin"></param>
  29. /// <param name="gameobj"></param>
  30. /// <param name="unitycallbackfunc"></param>
  31. /// <param name="tmp"></param>
  32. public void AddInstruct(LANGUAGE language, string name, string pinyin, string callbackObj, string callbackMethod)
  33. {
  34. Request re;
  35. if (language == LANGUAGE.CHINESE || language == LANGUAGE.ENGLISH)
  36. {
  37. Debug.Log("-uxr- OfflineVoiceModule AddInstruct.");
  38. re = Request.Build()
  39. .Name(RK_VOICE_SERVICE + "addCommand")
  40. .Param("zhKey", name)
  41. .Param("zhPinyin", pinyin)
  42. .AndroidCallback(CallBridge.CreateCallback(callbackObj, callbackMethod));
  43. }else
  44. {
  45. return;
  46. }
  47. CallBridge.CallAndroid(re);
  48. }
  49. public void ClearAllInstruct()
  50. {
  51. CallBridge.CallAndroid(Request.Build()
  52. .Name(RK_VOICE_SERVICE + "clearCommand"));
  53. }
  54. public void Commit()
  55. {
  56. CallBridge.CallAndroid(Request.Build()
  57. .Name(RK_VOICE_SERVICE + "addCommandFinish"));
  58. }
  59. public void ChangeVoiceCommandLanguage(LANGUAGE language)
  60. {
  61. int la = (int)language;
  62. CallBridge.CallAndroid(Request.Build()
  63. .Name(RK_VOICE_SERVICE + "changeVoiceLanguage").Param("language", la));
  64. }
  65. }
  66. public enum LANGUAGE
  67. {
  68. CHINESE = 0,
  69. ENGLISH = 1
  70. }
  71. }