Home
Microsoft

Getting Started: Build a Cortana Skill that can stream audio on the new Harman Kardon Invoke!

 

This week, Harman Kardon launched Invoke - the voice-activated speaker featuring Cortana. The Harman Kardon Invoke speaker combines the rich, captivating sound that Harman Kardon is known for, with Cortana, in an innovative and beautifully designed speaker for the home.

 

 

Invoke.jpg

 

With Cortana on the Invoke speaker, you can play music, manage calendars and activities, set reminders, check traffic, and much more. The Cortana enabled speaker comes with Skype integration and the ability to voice control compatible smart home devices.

 

That's awesome but what's more awesome is that you can create your own custom Cortana Skill to stream audio files on demand! This audio streaming capability as part of the Cortana Skills Kit can be used to play long running audio content like songs, radio stations, voice recordings, audiobooks, podcasts and much more! Read on to see how you can send the audio stream as part of your Cortana skill's responses. 

  

Let's begin!

 

(Go through Step 1 to 3 from our first blog post if you have never built a skill before. Follow-on when you are finishing up Step 4 there.)

 

Change the switch-case in the Run method in run.csx file to:

 

            switch (activity.GetActivityType())
            {
                case ActivityTypes.Message:
                    var client = new ConnectorClient(new Uri(activity.ServiceUrl));
                    var reply = activity.CreateReply();
                    reply.Text = "Hello World! Now playing a long running audio stream.";

                    AudioCard audioCard = new AudioCard()
                    {
                        Media = new MediaUrl[] { new MediaUrl("http://www.sample-videos.com/audio/mp3/crowd-cheering.mp3") }
                    };
                    
                    reply.Attachments = new List<Attachment>();
                    reply.Attachments.Add(audioCard.ToAttachment());
                    
                    await client.Conversations.ReplyToActivityAsync(reply);
                    
                    break;
                case ActivityTypes.ContactRelationUpdate:
                case ActivityTypes.Typing:
                case ActivityTypes.DeleteUserData:
                case ActivityTypes.Ping:
                default:
                    log.Error($"Unknown activity type ignored: {activity.GetActivityType()}");
                   break;
            }

 

Here, we are leveraging the rich card attachments capability that the Microsoft Bot Framework provides to send an Audio card to the Cortana Channel. The Bot Builder SDK provides several message and card builder classes which can be used to create and send cards. Support for more types of cards is coming soon!

 

An AudioCard can contain a list of media URLs (although each AudioCard is to be used for a single media stream only) and a Title property that the Cortana channel would leverage when playing the audio. To play a list of media URLs you will need to attach multiple Audio Cards to the bot response in the desired order of playing.

 

Please refer to the official documentation for more details on using the Audio Card to stream audio in your Cortana Skill.

 

Save the file and test your Cortana skill. Check out Step 4 & 5 from the first blog post on instructions on how to invoke your skill. 

 

 

You can test your skill on Cortana across Windows, Android and iOS. If you already bought the Harman Kardon Invoke, say "Hey Cortana" to invoke your skill and listen!

 

Hope that helps!

 

Please let us know below if you have any questions. We would also love to hear about specific topics for blogs that you would like to see and we would be happy to oblige! 

 

Have a great day!

2 Comments
Occasional Contributor

In your code block above, I had to change the line: 

reply.Attachments = new List(); 

 

to this:

 reply.Attachments = new List<Attachment>();

 

Microsoft

Thanks @Dwight Goins! Edited.