コード例 #1
0
        public IActionResult Callback([FromBody] Models.Updates updates)
        {
            // Проверяем, что находится в поле "type"
            switch (updates.Type)
            {
            // Если это уведомление для подтверждения адреса
            case "confirmation":
                // Отправляем строку для подтверждения
                return(Ok(_configuration["Config:Confirmation"]));

            case "message_new":
            {
                // Десериализация
                var    msg    = Message.FromJson(new VkResponse(updates.Object));
                string answer = IntentDetector.DetectIntent(msg.Text);
                // Отправим в ответ полученный от пользователя текст
                _vkApi.Messages.Send(new MessagesSendParams
                    {
                        RandomId = new DateTime().Millisecond,
                        PeerId   = msg.PeerId.Value,
                        Message  = answer
                    });
                break;
            }
            }
            // Возвращаем "ok" серверу Callback API
            return(Ok("ok"));
        }
コード例 #2
0
    void Start()
    {
        intentDetector = new IntentDetector(intentsJson);

        int confirm_arr_length = affirm_words.Length + cancel_words.Length;

        confirm_words = new string[confirm_arr_length];
        affirm_words.CopyTo(confirm_words, 0);
        cancel_words.CopyTo(confirm_words, affirm_words.Length);

        ClearVoiceUI();

        trigger_recognizer = new KeywordRecognizer(trigger_words);
        trigger_recognizer.OnPhraseRecognized += GetDictation;
        trigger_recognizer.Start();

        confirm_recognizer = new KeywordRecognizer(confirm_words);
        confirm_recognizer.OnPhraseRecognized += GetConfirmation;

        m_DictationRecognizer = new DictationRecognizer();
        m_DictationRecognizer.AutoSilenceTimeoutSeconds = 2;

        m_DictationRecognizer.DictationResult += (text, confidence) =>
        {
            Debug.LogFormat("Dictation result: {0}", text);
            m_Recognitions.color     = Color.green;
            m_Recognitions.fontSize  = 18;
            m_Recognitions.fontStyle = FontStyle.Bold;
            m_Recognitions.text      = text;
        };

        m_DictationRecognizer.DictationHypothesis += (text) =>
        {
            Debug.LogFormat("Dictation hypothesis: {0}", text);
            m_Recognitions.color     = Color.yellow;
            m_Recognitions.fontSize  = 16;
            m_Recognitions.fontStyle = FontStyle.Normal;

            m_Recognitions.text = text;
        };

        m_DictationRecognizer.DictationComplete += (completionCause) =>
        {
            if (completionCause != DictationCompletionCause.Complete &&
                completionCause != DictationCompletionCause.TimeoutExceeded)
            {
                Debug.LogErrorFormat("Dictation completed unsuccessfully: {0}.", completionCause);
            }

            activeIntent            = intentDetector.GetIntent(m_Recognitions.text);
            actionConfirmation.text = activeIntent.action.description;
            Debug.Log(activeIntent);

            StartConfirm();
        };

        m_DictationRecognizer.DictationError += (error, hresult) =>
        {
            Debug.LogErrorFormat("Dictation error: {0}; HResult = {1}.", error, hresult);
        };
    }