【m】添加图像识别
This commit is contained in:
@@ -4,61 +4,67 @@ using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using Stary.Evo;
|
||||
|
||||
public interface IVoiceCommandSystem : ISystem
|
||||
namespace Stary.Evo.RKTools
|
||||
{
|
||||
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
|
||||
public interface IVoiceCommandSystem : ISystem
|
||||
{
|
||||
get { return "VoiceCommandController"; }
|
||||
public void AddVoiceCommand(string content, string spell, Action action);
|
||||
public void DeleteVoiceCommand(string content);
|
||||
public void ClearAllVoiceCommands();
|
||||
}
|
||||
|
||||
private void createVoiceCommandContriller()
|
||||
|
||||
public class VoiceCommandSystem : AbstractSystem, IVoiceCommandSystem
|
||||
{
|
||||
GameObject VoiceControllerObject = GameObject.Find(ControllerName);
|
||||
if (VoiceControllerObject == null)
|
||||
private VoiceCommandController _voiceController;
|
||||
|
||||
protected virtual string ControllerName
|
||||
{
|
||||
VoiceControllerObject = new GameObject(ControllerName);
|
||||
get { return "VoiceCommandController"; }
|
||||
}
|
||||
_voiceController = VoiceControllerObject.GetComponent<VoiceCommandController>();
|
||||
if (_voiceController == null)
|
||||
|
||||
private void createVoiceCommandContriller()
|
||||
{
|
||||
_voiceController = VoiceControllerObject.AddComponent<VoiceCommandController>();
|
||||
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)
|
||||
public void AddVoiceCommand(string content, string spell, Action action)
|
||||
{
|
||||
_voiceController.ClearAllVoiceCommand();
|
||||
GameObject.Destroy(_voiceController.gameObject);
|
||||
if (_voiceController == null) createVoiceCommandContriller();
|
||||
_voiceController.RegisteredVoiceCommand(content, spell, action);
|
||||
}
|
||||
}
|
||||
public override void Dispose()
|
||||
{
|
||||
ClearAllVoiceCommands();
|
||||
}
|
||||
|
||||
protected override void OnInit()
|
||||
{
|
||||
|
||||
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()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,87 +6,92 @@ using Stary.Evo;
|
||||
using Rokid.UXR.Module;
|
||||
using UnityEngine.Android;
|
||||
|
||||
public class VoiceCommandController : MonoBehaviour
|
||||
namespace Stary.Evo.RKTools
|
||||
{
|
||||
public Dictionary<string, Action> VoiceCommands = new Dictionary<string, Action>();
|
||||
public bool isInit = false;
|
||||
|
||||
void Awake()
|
||||
public class VoiceCommandController : MonoBehaviour
|
||||
{
|
||||
|
||||
}
|
||||
public Dictionary<string, Action> VoiceCommands = new Dictionary<string, Action>();
|
||||
public bool isInit = false;
|
||||
|
||||
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)
|
||||
void Awake()
|
||||
{
|
||||
if (!Permission.HasUserAuthorizedPermission("android.permission.RECORD_AUDIO"))
|
||||
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
Permission.RequestUserPermission("android.permission.RECORD_AUDIO");
|
||||
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;
|
||||
}
|
||||
|
||||
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}' 不存在!!!");
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
|
||||
/// <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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user