【问题标题】:Watson keyword spotting unityWatson 关键字发现统一性
【发布时间】:2017-09-01 03:17:46
【问题描述】:

我已经下载了 Watson unity SDK 并按照图片中的方式进行了设置,并且可以正常工作。 我的问题是如何添加关键字发现? 我读过这个问题For Watson's Speech-To-Text Unity SDK, how can you specify keywords? 但是我不能例如找到 SendStart 函数。

【问题讨论】:

  • 天哪,我不喜欢将 Watson 连接到 Unity:/

标签: unity3d ibm-watson watson


【解决方案1】:

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. 此版本是一项重大更改,并删除了所有更高级别的(小部件、配置等)功能。

【讨论】:

  • Speech to Text 服务确实支持关键字定位,但我认为 Unity SDK 可能还不支持。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-07-14
  • 2019-01-31
  • 1970-01-01
相关资源
最近更新 更多