speech-and-text-unity-ios-android icon indicating copy to clipboard operation
speech-and-text-unity-ios-android copied to clipboard

speech to text just doesnot work

Open Isaac-dot opened this issue 2 years ago • 0 comments

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);
}

} `

Isaac-dot avatar Sep 14 '22 05:09 Isaac-dot