Watson 关键字识别 unity

Watson keyword spotting unity

我已经下载了 Watson unity SDK 并像图片中显示的那样进行设置,它可以正常工作。 我的问题是如何添加关键字识别? 我读过这个问题 但是我无法找到 SendStart 函数。

Speech to Text 服务找不到关键字。要查找关键字,您需要获取最终文本输出并将其发送到 Alchemy Language 服务。 Natural Language Understanding 服务仍在抽象到 Watson Unity SDK 中,但最终将取代 Alchemy Language。

private AlchemyAPI m_AlchemyAPI = new AlchemyAPI();

private void FindKeywords(string speechToTextFinalResponse)
{
    if (!m_AlchemyAPI.ExtractKeywords(OnExtractKeywords, speechToTextFinalResponse))
        Log.Debug("ExampleAlchemyLanguage", "Failed to get keywords.");
}

void OnExtractKeywords(KeywordData keywordData, string data)
{
    Log.Debug("ExampleAlchemyLanguage", "GetKeywordsResult: {0}", JsonUtility.ToJson(resp));
}

编辑 1

Natural Language Understanding 已在 Watson Unity SDK 中进行抽象。

NaturalLanguageUnderstanding m_NaturalLanguageUnderstanding = new NaturalLanguageUnderstanding();
private static fsSerializer sm_Serializer = new fsSerializer();

private void FindKeywords(string speechToTextFinalResponse)
{
    Parameters parameters = new Parameters()
    {
    text = speechToTextFinalResponse,
    return_analyzed_text = true,
    language = "en",
    features = new Features()
    {
        entities = new EntitiesOptions()
        {
            limit = 50,
            sentiment = true,
            emotion = true,
        },
        keywords = new KeywordsOptions()
        {
            limit = 50,
            sentiment = true,
            emotion = true
        }
    }

    if (!m_NaturalLanguageUnderstanding.Analyze(OnAnalyze, parameters))
        Log.Debug("ExampleNaturalLanguageUnderstanding", "Failed to analyze.");
}

private void OnAnalyze(AnalysisResults resp, string customData)
{
    fsData data = null;
    sm_Serializer.TrySerialize(resp, out data).AssertSuccess();
    Log.Debug("ExampleNaturalLanguageUnderstanding", "AnalysisResults: {0}", data.ToString());
}

编辑 2 抱歉,我没有意识到 Speech To Text 具有识别关键字的功能。感谢内森向我指出这一点!我将此功能添加到 Unity SDK 中未来版本的 Speech to Text 中。 Watson Unity SDK 1.0.0 看起来像这样:

void Start()
{
    //  Create credential and instantiate service
    Credentials credentials = new Credentials(_username, _password, _url);
    _speechToText = new SpeechToText(credentials);

    //  Add keywords
    List<string> keywords = new List<string>();
    keywords.Add("speech");
    _speechToText.KeywordsThreshold = 0.5f;
    _speechToText.Keywords = keywords.ToArray();
    _speechToText.Recognize(_audioClip, HandleOnRecognize);
}


private void HandleOnRecognize(SpeechRecognitionEvent result)
{
    if (result != null && result.results.Length > 0)
    {
        foreach (var res in result.results)
        {
            foreach (var alt in res.alternatives)
            {
                string text = alt.transcript;
                Log.Debug("ExampleSpeechToText", string.Format("{0} ({1}, {2:0.00})\n", text, res.final ? "Final" : "Interim", alt.confidence));

                if (res.final)
                    _recognizeTested = true;
            }

            if (res.keywords_result != null && res.keywords_result.keyword != null)
            {
                foreach (var keyword in res.keywords_result.keyword)
                {
                    Log.Debug("ExampleSpeechToText", "keyword: {0}, confidence: {1}, start time: {2}, end time: {3}", keyword.normalized_text, keyword.confidence, keyword.start_time, keyword.end_time);
                }
            }
        }
    }
}

目前您可以找到重构分支 here. 此版本是重大更改,删除了所有更高级别(小部件、配置等)功能。