如何在IBM Watson Speech to Text Unity SDK中访问单词的时间戳?
这是我正在使用的代码段。我能够获得给定音频的正确成绩单,但时间戳变量仍为空。
[SerializeField]
private AudioClip m_AudioClip = new AudioClip();
private SpeechToText m_SpeechToText = new SpeechToText();
void Start()
{
Debug.Log("start");
m_SpeechToText.EnableTimestamps = true;
m_SpeechToText.Recognize(m_AudioClip, OnRecognize);
}
void OnRecognize(SpeechRecognitionEvent result)
{
Debug.Log("Here");
if (result != null && result.results.Length > 0)
{
foreach (var res in result.results)
{
foreach (var alt in res.alternatives)
{
var timestamps = alt.timestamps;
Debug.Log(timestamps);
}
}
}
}
答案 0 :(得分:1)
您可以在SpeechRecognitionAlternatives对象中找到时间戳。
void OnRecognize(SpeechRecognitionEvent result)
{
Debug.Log("Here");
if (result != null && result.results.Length > 0)
{
foreach (var res in result.results)
{
foreach (var alt in res.alternatives)
{
if (alt.Timestamps != null)
foreach (var timestamp in alt.Timestamps)
Debug.Log(string.Format("timestamp word: {0}, start: {1}, end: {2}", timestamp.Word, timestamp.Start, timestamp.End));
}
}
}
}