跳到主要內容

發表文章

目前顯示的是有「Cortana」標籤的文章

[C#] 實作如何讓Cortana Skill 呼叫UWP

前言 當我們在實作Cortana Skill的時候, 我們可以將雲上的資料回傳給Cortana 並且顯示在Canvas上 來跟使用者互動 但實務上, 有些情況因為Canvas本身的限制, 所以需要再刻一個負責前端的UWP來顯示Skill回傳的資料 以下即介紹如透過實作UWP的 Deep link使之與 Cortana 互動 UWP的部分 設定Protocol 右鍵 Package.appxmanifest 選擇 View Code 加入 <Extensions> <uap:Extension Category= "windows.protocol" > <uap:Protocol Name= "YOUR_URL" > <uap:DisplayName> " YOUR_NAME " </uap:DisplayName> </uap:Protocol> </uap:Extension> </Extensions> 這邊假設 YOUR_URL = skill.mytest.clien YOUR_NAME = mytest 複寫OnActivated 當程式被Cortana叫起來時, 這個函式會被執行 複寫它, 使之將頁面切換至相應的頁面 var protocolArgs = args as ProtocolActivatedEventArgs; rootFrame.Navigate( typeof (Views.ListPhotos), protocolArgs.Uri.Query); 如範例所示, 我們會將頁面導向到 Views .ListPhotos Views.ListPhotos複寫OnNavigatedTo 讓我們在導向至這個頁面的時候, 可以先去載入相關資料 protected overrid...

[C#]Make Cortana speak Dialog prompt

This article focuses on how to make Cortana speak PromptDialog. It's quite simple, we have to specify message spoken by Cortana in PromptOption.speak and pass PromptOption to PromptDialog.Confirm() or PropmtDialog.Choice. Prompt Choice Prompt Confirm If you don't want show option on the canvas you can empty PromptOption.options field from the code. Reference: https://docs.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-text-to-speech https://docs.microsoft.com/en-us/bot-framework/dotnet/bot-builder-dotnet-cortana-skill https://docs.microsoft.com/en-us/dotnet/api/microsoft.bot.builder.dialogs.promptoptionswithsynonyms-1.-ctor?view=botbuilder-3.11.0

[UWP] 背景處理Cortana 的Voice Command 請求

前言 如果你希望開發一支UWP在背景處理事情, 然後將處理完的資料或狀態顯示在Cortana的Canvas上面的話, 我們會需要寫一個backgound server去處理Cortana的請求, 而基本上有以下幾個步驟 Step 1. 前置步驟 新增專案 選擇Windows Runtime Component 專案建立好之後, 我們先把Class1.cs重新命名(列如 MyVoiceCommandService.cs) 設定Package.appxmanifest 加入以下的程式碼, 然後把EntryPoint指定到剛剛建立的MyVoiceCommandService.cs 編輯VoiceCommand.xml 實作IBackgroundTask Step 2. 處理Cortana VoiceCommand的請求 取得VoiceCommandServiceConnection實體 這是用來讓我們的背景程式與Cortana溝通的介面 建立Response的內容 基本上我們可以回傳VoiceCommandUserMessage, VoiceCommandContentTile這兩種內容給Cortana User Messag 讓Cortana說話, 或是讓她秀訊息在Canvas上面 Content Tile 這個有點像是Bot Framework中的Card, 我們可以把文字跟圖片塞在Content Tile中讓Canvas顯示出來, 我們可以一次回傳多個Content Tile, 當使用者點了其中一個之後, 就會觸發開啟我們程式的事件 VoiceCommandResponse 建立VoiceCommandResponse的實體, 然後塞入剛剛建立的VoiceCommandUserMessage 或是 VoiceCommandContentTile, 最後再透過VoiceCommandServiceConnection回傳給Cortana Demo Hey Cortana, find God Father on My Library 完整程式碼 https://github.com/andy51002000/Simple-UWP...

[UWP] 實作VoiceCommand, 建立語音驅動(Voice Driven)的應用程式

前言: 微軟Window 10 的語音助理Cortana, 實現了用語音去驅動我們應用程式的情境, 開發人員可以在UWP的專案裡, 定義Voice Command, 當使用者的語音輸入符合相對應的指令,(如 Add new Movie on My Library), 程式就會被觸發, 簡單的說, 我們可以用語音把程式叫起來 , 然後讓它去做一些事情 如果想要建立一支能夠被Voice Command觸發的程式, 基本上有幾個步驟 建立一個專案 定義應用程式的Voice Command 修改App.xaml.cs 處理程式被觸發時的動作, 複寫OnLaunched和OnActivated (比如說做一個顯示使用者的電影資料的程式 ) 建立一個新專案 在專案中建立Data Model "Movie" 表示電影資訊 定義Voice Command 這邊定義兩個command showMovies, 這個動作會把程式的MainPage叫起來, 然後我們會在頁面上顯示所有電影資訊 addNewMovie, 這個動作會把語句中的電影名稱抓出來然後加到主頁面上 基本上要做到這件事, 必須要在VoiceCommand中定義PhraseList, 並且在ListFor的語句中標示出來, 列如 add {MovieName} Cortana就會根據原先定義在PhraseList中的MovieName item去解析出句子中的電影名稱, 然後傳遞給我們程式 修改App.xaml.cs 在OnLaunched 最後面呼叫InstallCommandDefinitionsFromStorageFileAsync去安裝VoiceCommand 複寫OnActivated, 我們可以從SpeechRecognitionResult這個類別中知道語意識別的結果, 或是擷取語句中的{MovieName}, 如speechRecognitionResult.SemanticInterpretation.Properties["MovieName"].FirstOrDefault(); MainPage.xaml 在MainPage.xaml 裡定義一個ListBox 然後綁...

[Bot framework] 實作Windows上的聊天機器人, Cortana Skill

在新版的Bot Builder 中(3.8之後) 我們可以發現Connector.Activity 這個類別裡面 多了 Speak  ,InputHint 這些新的 Property可以使用 我們可以透過操作 Speak 的內容讓Bot在Cortana上講話             var response = context.MakeMessage(); response.Summary = "Hi! Try asking me things like " ; response.Text= "'show me the high score', 'search for the high score' or 'start a new game'" ; response.Speak = " Hi! Try asking me things like "+ "'show me the high score', 'search for the high score' or 'start a new game'" ; await  context.PostAsync(response); 除此之外, InputHint 則是可以決定 Cortana 說完話之後的行為 如果將 InputHint 設為 InputHint .ExpectingInput var response = context.MakeMessage(); response.InputHint = InputHints .ExpectingInput; Cortana 在說完話之後就會開啟聆聽的模式, 使用者就能直接對談, 不再按原本右下角的麥克風按鈕 Source code https://github.com/andy51002000/Cortana-with-BotFramework.git 注意: 目前Cortana Skill只開放US的區域...