1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Runtime.InteropServices;
- using UnityEngine;
- public class UnityCallAndroid_Voice : MonoBehaviour
- {
- private AndroidJavaObject Voice;
- [HideInInspector]
- public bool isStart = false;
- void Start()
- {
-
- Func();
- }
-
- public void Func()
- {
- AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
- AndroidJavaObject jo = jc.GetStatic<AndroidJavaObject>("currentActivity");
- Debug.unityLogger.logEnabled = true;
-
- try
- {
- Debug.Log("Voice");
- Voice = new AndroidJavaObject("com.iflytek.mscv5plusdemo.AsrDemo", jo);
- Debug.Log("Voice Has Been Called");
- }
- catch (Exception e)
- {
- Debug.LogError($"Func Expection{e}");
- }
- StartVoice();
- }
- public void StartVoice()
- {
- try
- {
- Voice.Call("StartSpeechRecognition");
- isStart = true;
- }
- catch (Exception e)
- {
- Debug.LogError($"StartVoice Expection{e}");
- }
- }
- public int GetRecognitions()
- {
- return Voice.Call<int>("GetRecognition");
- }
- private void OnApplicationQuit()
- {
- Voice.Call("StopSpeechRecognition");
- }
- }
|