I’m working on a Unity project where I’m using Azure Cognitive Services for speech recognition. I can see that the recognized speech text is correctly updated in the Inspector under the Text component, but the changes do not appear on the screen during gameplay.
I’m using a Text component within a Canvas to display recognized speech text. I update the text using a script called DisplaySpeechRecognition:
using UnityEngine;
using UnityEngine.UI;
public class DisplaySpeechRecognition : MonoBehaviour
{
public Text recognizedText;
private void Start()
{
if (recognizedText != null)
{
Debug.Log("Text component is assigned successfully.");
recognizedText.text = "Say something...";
Canvas.ForceUpdateCanvases();
Debug.Log("Initial text set to: 'Say something...'");
}
else
{
Debug.LogError("Text component is not assigned in the Inspector.");
}
}
public void UpdateRecognizedText(string recognizedSpeech)
{
if (recognizedText != null)
{
recognizedText.text = recognizedSpeech;
Canvas.ForceUpdateCanvases();
Debug.Log("Text updated to: " + recognizedSpeech);
}
else
{
Debug.LogWarning("Text component is not assigned.");
}
}
}
Debugging Results:
The text component is correctly assigned (Debug.Log confirms this).
The initial text (“Say something…”) is set correctly and is visible on the screen.
The recognized speech text is successfully captured and updates in the Inspector but is not displayed on the UI during gameplay.
Question:
Why is the Text component updating correctly in the Inspector but not displaying the changes on the screen during runtime? How can I fix this issue so the recognized speech text is visible on the UI in real-time?
Shashank Kumar Singh is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
5