简体   繁体   English

沃森关键字发现统一

[英]Watson keyword spotting unity

I have downloaded the Watson unity SDK and set it up like show in the picture and it works. 我已经下载了Watson unity SDK,并将其设置为如图所示,并且可以正常工作。 My question is how do I add keyword spotting? 我的问题是如何添加关键字发现? I have read this question For Watson's Speech-To-Text Unity SDK, how can you specify keywords? 我已经阅读了这个问题对于Watson的语音转文本Unity SDK,如何指定关键字? But I cant for example locate the SendStart function. 但是,例如,我无法找到SendStart函数。

在此处输入图片说明

The Speech to Text service does not find keywords. 语音转文字服务找不到关键字。 To find keywords you would need to take the final text output and send it to the Alchemy Language service. 要查找关键字,您需要获取最终的文本输出并将其发送到Alchemy Language服务。 Natural Language Understanding service is still being abstracted into the Watson Unity SDK but will eventually replace Alchemy Language. Natural Language Understanding服务仍在抽象到Watson Unity SDK中,但最终将替代炼金术语言。

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

EDIT 1 编辑1

Natural Language Understanding has been abstracted in tot he Watson Unity SDK. Watson Unity SDK中已经抽象了Natural Language Understanding

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());
}

EDIT 2 Sorry, I didn't realize Speech To Text had the ability to do keyword spotting. 编辑2抱歉,我没有意识到Speech To Text可以进行关键字识别。 Thanks to Nathan for pointing that out to me! 感谢Nathan向我指出! I added this functionality into a future release of Speech to Text in the Unity SDK. 我在Unity SDK的语音到文本的将来版本中添加了此功能。 It will look like this for the Watson Unity SDK 1.0.0: 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);
                }
            }
        }
    }
}

Currently you can find the refactor branch here. 当前,您可以在此处找到重构分支 This release is a breaking change and has all of the higher level (widgets, config, etc) functionality removed. 此版本是一项重大更改,并删除了所有更高级别的功能(窗口小部件,配置等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM