Пример #1
0
        private async Task voiceRecognitionServicePropertyChanged(object sender, PropertyChangedEventArgs args)
        {
            if (args.PropertyName == "RecognizedText")
            {
                if (!string.IsNullOrEmpty(_voiceRecognitionService.RecognizedText))
                {
                    // LUISでインテント解析
                    var result = await luisService.DetectIntentAsync(_voiceRecognitionService.RecognizedText);

                    // メモ追加
                    if (result.TopScoringIntent.Intent == "AddIntent")
                    {
                        var item = new Item
                        {
                            Text        = result.Entities.FirstOrDefault(e => e.Type == "text")?.Entity ?? "仮タイトル",
                            Description = result.Entities.FirstOrDefault(e => e.Type == "description")?.Entity ?? string.Empty
                        };
                        Items.Add(item);
                        await DataStore.AddItemAsync(item);
                    }
                    // 一覧読み上げ
                    else if (result.TopScoringIntent.Intent == "ListIntent")
                    {
                        var list = await DataStore.GetItemsAsync();

                        await TextToSpeech.SpeakAsync($"現在のメモの内容をおしらせします。{string.Join(",", list.Select(item => item.Text))}");
                    }
                    //LoadItemsCommand.Execute(null);
                }
            }
            else if (args.PropertyName == "IsRecognizing")
            {
                // 音声認識の実行状況変更がトリガーになった場合、その実行状況をViewModelに取得する。
                IsRecognizing = _voiceRecognitionService.IsRecognizing;
            }
        }