GithubHelp home page GithubHelp logo

seksenov / hostedcortanademo Goto Github PK

View Code? Open in Web Editor NEW
1.0 2.0 3.0 3.39 MB

Integrating with Cortana on Windows 10 from a remote website.

License: MIT License

PowerShell 64.27% JavaScript 33.63% HTML 2.11%

hostedcortanademo's Introduction

HostedCortanaDemo

Integrating with Cortana on Windows 10 from a remote website.

In Progress

This project is in progress. It currently supports the Cortana command "Cortana Demo send message" followed by any spoken phrase. The html is not complete to show the text being passed back from Cortana to the site but it can be seen in the console by hitting F12 when the Hosted App is running.

Steps Required to Integrate Cortana on any Hosted Web App

Create a Voice Command Definition (VCD) file

Create an xml VCD file defining your app name, the set of commands your app will handle and how it Cortana will respond to users. The schema definition can be found here. Once you've created the VCD file you need to place it on your server where it's accessible from the web.

Here is the one used in the sample project:

<?xml version="1.0" encoding="utf-8"?>
<VoiceCommands xmlns="http://schemas.microsoft.com/voicecommands/1.2">
  <CommandSet xml:lang="en-us" Name="CortanaDemo">
    <CommandPrefix>Cortana Demo</CommandPrefix>
    <Example>Cortana demo send this is a test</Example>
    <Command Name="send">
      <Example>send {message} using cortana demo</Example>
      <ListenFor RequireAppName="BeforeOrAfterPhrase">send message {messageSubject}</ListenFor>
      <Feedback>sending {messageSubject} to Cortana Demo</Feedback>
      <Navigate Target="/sendMessage.htm"/>
    </Command>
    <PhraseTopic Label="messageSubject" Scenario="Dictation"></PhraseTopic>
  </CommandSet>
</VoiceCommands>

Add the meta tag pointing to the location of your VCD

Next you'll need to add the Cortana meta tag to you html start page. When your app is launched the App Host will scan the html content for a Cortana specific meta tag that points to the location of you VCD file. The App Host will automatically download and register the VCD file with Windows. After this Cortana will recognize the commands uttered by users and activate your app.

Here is the meta tag that is added for this project:

<meta name="msapplication-cortanavcd" content="http://seksenov.github.io/HostedCortanaDemo/vcd.xml"/>

Handle the Cortana activation

To complete Cortana integration you will need to handle the activation event from Cortana in your app. Your app will be need to handle the activation using Windows APIs as show below and extract the speech recognition from the arguments of the event.

Here is the handling in this project:

if (typeof Windows !== 'undefined') {
  console.log('Windows namespace is available');
  // Subscribe to the Windows Activation Event
  Windows.UI.WebUI.WebUIApplication.addEventListener('activated', function (args) {
    var activation = Windows.ApplicationModel.Activation;
    // Check to see if the app was activated by a voice command
    if (args.kind === activation.ActivationKind.voiceCommand) {

      var speechRecognitionResult = args.result;
      var textSpoken = speechRecognitionResult.text;
      var command = speechRecognitionResult.rulePath[0];

      console.log('The command is: ' + command);
      document.getElementById('command').innerHTML = command;
      document.getElementById('speechReco').innerHTML = speechRecognitionResult;
      document.getElementById('text').innerHTML = textSpoken;

      // Determine the command type {play} defined in vcd
      if (command === 'send') {
        // Determine the stream name specified
        console.log('The speech reco result is: ' + speechRecognitionResult);
        console.log('The text spoken is: ' + textSpoken);
      }
      else { 
        // No valid command specified
        console.log('No valid command specified');
      }
    }
  });
} else {
  console.log('Windows namespace is unavaiable');
}

Setup:

  1. Clone or fork the repo
  2. npm install
  3. gulp appx:dev

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.