khanhuitse05 / speech-and-text-unity-ios-android

Speed to text in Unity iOS use Native Speech Recognition
MIT License
286 stars 124 forks source link

speech to text just doesnot work #81

Open Isaac-dot opened 1 year ago

Isaac-dot commented 1 year ago

there is no errors in unity editor. when i build it on my android phone(android 9). the speech to text function detect nothing even i tick the "is show popup android". i use unity 2021.3.5f1. following errors showed

09-13 01:09:31.559: E/Unity(26927): A scripted object (probably UnityEngine.XR.MagicLeap.MagicLeapSettings?) has a different serialization layout when loading. (Read 52 bytes but expected 76 bytes) 09-13 01:09:31.559: E/Unity(26927): Did you #ifdef UNITY_EDITOR a section of your serialized properties in any of your scripts?

following is the code that i use for running the function `using System.Collections; using System.Collections.Generic; using UnityEngine; using TextSpeech; using UnityEngine.Android; using UnityEngine.UI; using TMPro;

public class VoiceController : MonoBehaviour { const string LANG_CODE = "en-US"; [SerializeField] TextMeshProUGUI uiText;

void Start()
{
    Setup(LANG_CODE);

if UNITY_ANDROID

    SpeechToText.Instance.onPartialResultsCallback = OnPartialSpeechResult;

endif

    SpeechToText.Instance.onResultCallback = OnFinalSpeechResult;
    TextToSpeech.Instance.onStartCallBack = OnSpeakStart;
    TextToSpeech.Instance.onDoneCallback = OnSpeakStop;
    CheckPermission();
}

void CheckPermission()
{

if UNITY_ANDROID

    if(!Permission.HasUserAuthorizedPermission(Permission.Microphone))
    {
        Permission.RequestUserPermission(Permission.Microphone);
    }

endif

}

#region Text to Speech

public void StartSpeaking(string message)
{
    TextToSpeech.Instance.StartSpeak(message);
}

public void StopSpeaking()
{
    TextToSpeech.Instance.StopSpeak();
}

void OnSpeakStart()
{
    Debug.Log("Talking Start...");
}

void OnSpeakStop()
{
    Debug.Log("Talking stopped...");
}    

#endregion

#region Speech to Text

public void StartListening(string message)
{
    SpeechToText.Instance.StartRecording();

}

public void StopListening()
{
    SpeechToText.Instance.StopRecording();
}

void OnFinalSpeechResult(string result)
{
    uiTtext.text = resul;
}

void OnPartialSpeechResult(string result)
{
    uiText.text = result;
}    

#endregion    

void Setup(string code)
{
    TextToSpeech.Instance.Setting(code, 1, 1);
    SpeechToText.Instance.Setting(code);
}

} `