2014-05-05 22 views
7

Tôi muốn tích hợp các lệnh thoại Cortana vào ứng dụng Windows Phone của mình. Tôi biết rằng bản cập nhật cuối cùng của ứng dụng Wikipedia là Cortana. Đồng thời tôi không thể tìm thấy bất kỳ tài liệu nào về API Cortana. Có ai biết nơi tôi có thể tìm thấy nó?Tài liệu Cortana API có sẵn không?

+1

Tôi đã thấy rất nhiều bài viết trên kênh 9 về điều này. Đây có thể là điểm khởi đầu tốt: http://channel9.msdn.com/coding4fun/blog/Cortana-show-me-how-I-can-add-you-to-my-apps Ngoài ra: http: // www .wp7connect.com/2014/04/06/new-in-depth-cortana-build-session-hiển thị-tính năng-ứng dụng-tích hợp-video / –

Trả lời

4

Không có một điều như một API Cortana, ít nhất là bây giờ.

là gì hiện nay là yêu cầu Cortana bắn ứng dụng của riêng bạn với bất cứ tham số người dùng cho biết, thông tin thêm về điều đó ở đây: http://msdn.microsoft.com/en-us/library/dn630430.aspx

Tại sao tôi nói rằng không phải là một API cho Cortana? Bởi vì bạn không thể lập trình hỏi Cortana về thời tiết hay bất cứ điều gì bạn muốn. Những gì bạn làm là nói với Cortana một cái gì đó để khởi động ứng dụng của bạn và từ thời điểm đó trên đó là ứng dụng của bạn cung cấp cho người dùng những phản hồi, thông tin hoặc bất cứ điều gì cần thiết.

1

Bạn có thể tích hợp Cortana vào ứng dụng của bạn bằng cách:

Tạo một định nghĩa Voice Command (VCD)

<?xml version="1.0" encoding="utf-8" ?> 
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.1"> 
    <CommandSet xml:lang="en-us" Name="HomeControlCommandSet_en-us"> 
    <CommandPrefix>HomeControl</CommandPrefix> 
    <Example>Control alarm, temperature, light and others</Example> 

    <Command Name="Activate_Alarm"> 
     <Example>Activate alarm</Example> 
     <ListenFor>[Would] [you] [please] activate [the] alarm [please]</ListenFor> 
     <ListenFor RequireAppName="BeforeOrAfterPhrase">Activate alarm</ListenFor> 
     <Feedback>Activating alarm</Feedback> 
     <Navigate /> 
    </Command> 

    <Command Name="Change_Temperature"> 
     <Example>Change temperature to 25º degrees</Example> 
     <ListenFor>Change temperature to {temperature} degrees</ListenFor> 
     <Feedback>Changing temperature to {temperature} degrees</Feedback> 
     <Navigate /> 
    </Command> 

    <Command Name="Change_Light_Color"> 
     <Example>Change light color to yellow</Example> 
     <ListenFor>Change light color to {colors}</ListenFor> 
     <Feedback>Changing light color to {colors}</Feedback> 
     <Navigate /> 
    </Command> 

    <PhraseList Label="colors"> 
     <Item>yellow</Item> 
     <Item>green</Item> 
     <Item>red</Item> 
    </PhraseList> 

    <PhraseTopic Label="temperature"> 
    </PhraseTopic> 

    </CommandSet> 
</VoiceCommands> 

Đăng ký VCD tại App Startup

StorageFile vcdStorageFile = await Package.Current.InstalledLocation.GetFileAsync(@"HomeControlCommands.xml"); 
await VoiceCommandManager.InstallCommandSetsFromStorageFileAsync(vcdStorageFile); 

Xử lý lệnh

protected override void OnActivated(IActivatedEventArgs e) 
{ 
    // Handle when app is launched by Cortana 
    if (e.Kind == ActivationKind.VoiceCommand) 
    { 
     VoiceCommandActivatedEventArgs commandArgs = e as VoiceCommandActivatedEventArgs; 
     SpeechRecognitionResult speechRecognitionResult = commandArgs.Result; 

     string voiceCommandName = speechRecognitionResult.RulePath[0]; 
     string textSpoken = speechRecognitionResult.Text; 
     IReadOnlyList<string> recognizedVoiceCommandPhrases; 

     System.Diagnostics.Debug.WriteLine("voiceCommandName: " + voiceCommandName); 
     System.Diagnostics.Debug.WriteLine("textSpoken: " + textSpoken); 

     switch (voiceCommandName) 
     ... 
} 

Bạn có thể tìm thêm thông tin tại http://talkitbr.com/2015/07/13/integrando-a-cortana-em-seu-aplicativo-windows-10/

Ngoài ra, nếu bạn quan tâm đến việc đáp ứng với người dùng thông qua cửa sổ Cortana, kiểm tra post này về Cortana ở chế độ nền.