This commit is contained in:
2025-04-21 11:11:15 +08:00
9 changed files with 244 additions and 0 deletions

View File

@@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: d1654ed807ee7c24c94cab4c172e6f91
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -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<VoiceCommandController>();
if (_voiceController == null)
{
_voiceController = VoiceControllerObject.AddComponent<VoiceCommandController>();
}
}
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()
{
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 073d8fadbb202ad42a540fd5299555c3
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,18 @@
{
"name": "RKVoiceCommand.RunTime",
"rootNamespace": "",
"references": [
"GUID:6447e10b87dc140ab924878c1ecef665",
"GUID:fe14bc9dd681249d19cf4ef377c7e29e",
"GUID:d1a793c2b6959e04ea45b972eaa369c8"
],
"includePlatforms": [],
"excludePlatforms": [],
"allowUnsafeCode": false,
"overrideReferences": false,
"precompiledReferences": [],
"autoReferenced": true,
"defineConstraints": [],
"versionDefines": [],
"noEngineReferences": false
}

View File

@@ -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:

View File

@@ -0,0 +1,92 @@
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<string, Action> VoiceCommands = new Dictionary<string, Action>();
public bool isInit = false;
void Awake()
{
}
void Start()
{
//if (!Permission.HasUserAuthorizedPermission("android.permission.RECORD_AUDIO")) return;
}
/// <summary>
/// 注册语音指令
/// </summary>
/// <param name="content"></param>
/// <param name="spell"></param>
/// <param name="action"></param>
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();
}
/// <summary>
/// 删除语音指令
/// </summary>
/// <param name="content"></param>
public void DeleteVoiceCommand(string content)
{
if (VoiceCommands.ContainsKey(content))
{
VoiceCommands.Remove(content);
}
else
{
Debug.LogWarning($"语音命令 :“'{content}' 不存在!!!");
}
}
/// <summary>
/// 清除所有语音指令
/// </summary>
public void ClearAllVoiceCommand()
{
VoiceCommands.Clear();
OfflineVoiceModule.Instance.ClearAllInstruct();
OfflineVoiceModule.Instance.Commit();
}
void OnReceive(string msg)
{
if (VoiceCommands.TryGetValue(msg, out Action action))
{
action?.Invoke();
}
}
}

View File

@@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 9f55b7179dceeae47826f4f0f08ba3fd
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View File

@@ -0,0 +1,20 @@
{
"name": "com.staryevo.rkvoicecommand",
"version": "1.0.3",
"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"
}
}

View File

@@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: c1e566c37939b1c45885d8ca929414a7
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant: