我创建了一个简单的应用程序来测试IBM Watson的Speech To Text。我的计划是使用它部署一个Android应用程序。我的应用在Unity上播放时可以运行,但是在Android设备上构建并运行后无法运行。
通过在Android Studio上浏览Logcat,我发现它在标题中提到的while循环中遇到了无限循环。我的代码的凭据部分也在下面。
同样,它可以在我的PC上运行。在Android上构建和部署后不起作用。有人知道我在想什么吗?我假设这与Android有关,但我不确定。我已经死胡同寻找答案了。
private void Start()
{
Debug.Log("Start");
recordedText = GameObject.Find("RecordedText").GetComponent<Text>();
LogSystem.InstallDefaultReactors();
// create Watson service
Runnable.Run(CreateService());
// note if there are mic devices found
foreach (string device in Microphone.devices)
{
Debug.Log(device);
}
audioSource = gameObject.AddComponent<AudioSource>();
}
// creates Watson credentials and initializes STT service
private IEnumerator CreateService()
{
if (string.IsNullOrEmpty(_iamApikey))
{
throw new WatsonException("Plesae provide IAM ApiKey for the service.");
}
// Create credential and instantiate service
Credentials credentials = null;
// Authenticate using iamApikey
TokenOptions tokenOptions = new TokenOptions()
{
IamApiKey = _iamApikey
};
credentials = new Credentials(tokenOptions, _serviceUrl);
if(credentials != null) Debug.Log("Credentials is not null!");
// Wait for tokendata
while (!credentials.HasIamTokenData())
{
Debug.Log("In the while loop"); // INFINITE LOOP ON ANDROID
yield return null;
}
Debug.Log("OUT of the while loop");
_speechToText = new SpeechToText(credentials); // NEVER REACHES ON ANDROID
}