获取IBM Watson unity SDK中的时间戳

时间:2017-08-08 11:31:34

标签: unity3d ibm-watson

如何在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);
            }
        }
    }
}

1 个答案:

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