Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

speech to text just doesnot work #81

Open
Isaac-dot opened this issue Sep 14, 2022 · 0 comments
Open

speech to text just doesnot work #81

Isaac-dot opened this issue Sep 14, 2022 · 0 comments

Comments

@Isaac-dot
Copy link

Isaac-dot commented Sep 14, 2022

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

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant