diff --git a/Assets/07.RKVoiceCommand/Editor.meta b/Assets/07.RKVoiceCommand/Editor.meta new file mode 100644 index 0000000..a01f9c9 --- /dev/null +++ b/Assets/07.RKVoiceCommand/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 639fe5e44b4245e48b45ae80da27e408 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/07.RKVoiceCommand/README.md b/Assets/07.RKVoiceCommand/README.md new file mode 100644 index 0000000..f44b9a0 --- /dev/null +++ b/Assets/07.RKVoiceCommand/README.md @@ -0,0 +1 @@ +# Rokid语音命令工具 diff --git a/Assets/07.RKVoiceCommand/README.md.meta b/Assets/07.RKVoiceCommand/README.md.meta new file mode 100644 index 0000000..cac31cb --- /dev/null +++ b/Assets/07.RKVoiceCommand/README.md.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 2007d74d73bee7d468ab76b4f3466708 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/07.RKVoiceCommand/RunTime.meta b/Assets/07.RKVoiceCommand/RunTime.meta new file mode 100644 index 0000000..716d4ec --- /dev/null +++ b/Assets/07.RKVoiceCommand/RunTime.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: d1654ed807ee7c24c94cab4c172e6f91 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/07.RKVoiceCommand/RunTime/IVoiceCommandSystem.cs b/Assets/07.RKVoiceCommand/RunTime/IVoiceCommandSystem.cs new file mode 100644 index 0000000..3814ac3 --- /dev/null +++ b/Assets/07.RKVoiceCommand/RunTime/IVoiceCommandSystem.cs @@ -0,0 +1,64 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Stary.Evo; + +public interface IVoiceCommandSystem : ISystem +{ + public void AddVoiceCommand(string content,string spell, Action action); + public void DeleteVoiceCommand(string content); + public void ClearAllVoiceCommands(); +} + +public class VoiceCommandSystem : AbstractSystem,IVoiceCommandSystem +{ + private VoiceCommandController _voiceController; + protected virtual string ControllerName + { + get { return "VoiceCommandController"; } + } + + private void createVoiceCommandContriller() + { + GameObject VoiceControllerObject = GameObject.Find(ControllerName); + if (VoiceControllerObject == null) + { + VoiceControllerObject = new GameObject(ControllerName); + } + _voiceController = VoiceControllerObject.GetComponent(); + if (_voiceController == null) + { + _voiceController = VoiceControllerObject.AddComponent(); + } + } + + public void AddVoiceCommand(string content,string spell, Action action) + { + if (_voiceController == null) createVoiceCommandContriller(); + _voiceController.RegisteredVoiceCommand(content, spell, action); + } + + public void DeleteVoiceCommand(string content) + { + if(_voiceController!=null) _voiceController.DeleteVoiceCommand(content); + } + + public void ClearAllVoiceCommands() + { + if (_voiceController != null) + { + _voiceController.ClearAllVoiceCommand(); + GameObject.Destroy(_voiceController.gameObject); + } + } + public override void Dispose() + { + ClearAllVoiceCommands(); + } + + protected override void OnInit() + { + throw new System.NotImplementedException(); + } +} \ No newline at end of file diff --git a/Assets/07.RKVoiceCommand/RunTime/IVoiceCommandSystem.cs.meta b/Assets/07.RKVoiceCommand/RunTime/IVoiceCommandSystem.cs.meta new file mode 100644 index 0000000..7963cbb --- /dev/null +++ b/Assets/07.RKVoiceCommand/RunTime/IVoiceCommandSystem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 073d8fadbb202ad42a540fd5299555c3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/07.RKVoiceCommand/RunTime/RKVoiceCommand.RunTime.asmdef b/Assets/07.RKVoiceCommand/RunTime/RKVoiceCommand.RunTime.asmdef new file mode 100644 index 0000000..47e6458 --- /dev/null +++ b/Assets/07.RKVoiceCommand/RunTime/RKVoiceCommand.RunTime.asmdef @@ -0,0 +1,14 @@ +{ + "name": "RKVoiceCommand.RunTime", + "rootNamespace": "", + "references": [], + "includePlatforms": [], + "excludePlatforms": [], + "allowUnsafeCode": false, + "overrideReferences": false, + "precompiledReferences": [], + "autoReferenced": true, + "defineConstraints": [], + "versionDefines": [], + "noEngineReferences": false +} \ No newline at end of file diff --git a/Assets/07.RKVoiceCommand/RunTime/RKVoiceCommand.RunTime.asmdef.meta b/Assets/07.RKVoiceCommand/RunTime/RKVoiceCommand.RunTime.asmdef.meta new file mode 100644 index 0000000..bfec013 --- /dev/null +++ b/Assets/07.RKVoiceCommand/RunTime/RKVoiceCommand.RunTime.asmdef.meta @@ -0,0 +1,13 @@ +fileFormatVersion: 2 +<<<<<<<< HEAD:Assets/05.TableTextConversion/Editor/Excel.meta +guid: 10c9b58b77ad42b4193e2a393b1a9899 +folderAsset: yes +DefaultImporter: +======== +guid: 44e8639d57fc2a94b94ecef44bf1e36a +AssemblyDefinitionImporter: +>>>>>>>> 04.AudioCore:Assets/04.AudioCore/RunTime/AudioCore.RunTime.asmdef.meta + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/07.RKVoiceCommand/RunTime/VoiceCommandController.cs b/Assets/07.RKVoiceCommand/RunTime/VoiceCommandController.cs new file mode 100644 index 0000000..24c6508 --- /dev/null +++ b/Assets/07.RKVoiceCommand/RunTime/VoiceCommandController.cs @@ -0,0 +1,104 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using Stary.Evo; +using Rokid.UXR.Module; +using UnityEngine.Android; + +public class VoiceCommandController : MonoBehaviour +{ + public Dictionary VoiceCommands = new Dictionary(); + public bool isInit = false; + + void Awake() + { + + } + + void Start() + { + //if (!Permission.HasUserAuthorizedPermission("android.permission.RECORD_AUDIO")) return; + + } + + /// + /// 注册语音指令 + /// + /// + /// + /// + public void RegisteredVoiceCommand(string content, string spell, Action action) + { + if (!isInit) + { + if (!Permission.HasUserAuthorizedPermission("android.permission.RECORD_AUDIO")) + { + Permission.RequestUserPermission("android.permission.RECORD_AUDIO"); + } + + ModuleManager.Instance.RegistModule("com.rokid.voicecommand.VoiceCommandHelper", false); + OfflineVoiceModule.Instance.ChangeVoiceCommandLanguage(LANGUAGE.CHINESE); + isInit = true; + } + + if (!VoiceCommands.ContainsKey(content)) + { + VoiceCommands.Add(content, action); + } + else + { + Debug.LogError($"语音命令 :“'{content}' ”已经注册了!!!"); + return; + } + OfflineVoiceModule.Instance.AddInstruct(LANGUAGE.CHINESE, content, spell, this.gameObject.name, "OnReceive"); + OfflineVoiceModule.Instance.Commit(); + } + + /// + /// 删除语音指令 + /// + /// + public void DeleteVoiceCommand(string content) + { + if (VoiceCommands.ContainsKey(content)) + { + VoiceCommands.Remove(content); + } + else + { + Debug.LogWarning($"语音命令 :“'{content}' 不存在!!!"); + } + } + + /// + /// 清除所有语音指令 + /// + public void ClearAllVoiceCommand() + { + VoiceCommands.Clear(); + OfflineVoiceModule.Instance.ClearAllInstruct(); + OfflineVoiceModule.Instance.Commit(); + } + + void OnReceive(string msg) + { + if (VoiceCommands.TryGetValue(msg, out Action action)) + { + action?.Invoke(); + } + + } + + void Update() + { + if (Input.GetKeyDown(KeyCode.Space)) + { + if (VoiceCommands.TryGetValue("变成绿色", out Action action)) + { + action?.Invoke(); + } + } + } + +} diff --git a/Assets/07.RKVoiceCommand/RunTime/VoiceCommandController.cs.meta b/Assets/07.RKVoiceCommand/RunTime/VoiceCommandController.cs.meta new file mode 100644 index 0000000..02d14c5 --- /dev/null +++ b/Assets/07.RKVoiceCommand/RunTime/VoiceCommandController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 9f55b7179dceeae47826f4f0f08ba3fd +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/07.RKVoiceCommand/package.json b/Assets/07.RKVoiceCommand/package.json new file mode 100644 index 0000000..fb28b25 --- /dev/null +++ b/Assets/07.RKVoiceCommand/package.json @@ -0,0 +1,20 @@ +{ + "name": "com.staryevo.rkvoicecommand", + "version": "1.0.0", + "displayName": "07.RKVoiceCommand", + "description": "Rokid语音命令工具", + "unity": "2021.3", + "unityRelease": "23f1", + "keywords": [ + "unity", + "scirpt" + ], + "author": { + "name": "staryEvo", + "url": "https://www.unity3d.com" + }, + "dependencies": { + "com.rokid.xr.unity":"3.0.3", + "com.staryevo.main":"1.x.x" + } +} diff --git a/Assets/07.RKVoiceCommand/package.json.meta b/Assets/07.RKVoiceCommand/package.json.meta new file mode 100644 index 0000000..2d5f4e9 --- /dev/null +++ b/Assets/07.RKVoiceCommand/package.json.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: c1e566c37939b1c45885d8ca929414a7 +TextScriptImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: