-1

I've integrated my bot with cortana channel and can view the adaptive cards successfully. What I need is to speak out the content of the adaptive card. The speak property when using shows that it is deprecated. Is there a way to speak out the content of my card?

var contentCard = AdaptiveCard(qnaAnswer.title);
 Attachment attachment = new Attachment()
   {
     ContentType = AdaptiveCard.ContentType,
     Content = contentCard
   }; 
      reply.Attachments = new List<Attachment> { attachment };
      await turnContext.SendActivityAsync(reply);

public static AdaptiveCard AdaptiveCard(string subtitle)
 {
   AdaptiveCard card = new AdaptiveCard();           
   card.Body.Add(new AdaptiveTextBlock()
  {
   Text = string.IsNullOrEmpty(subtitle) ? string.Empty : subtitle,                         
   Speak =text ,
  });
return card;
 }

1 Answers1

1

A few things with this code.

First, if you look at the schema for AdaptiveCards, you see speak property only is valid under a card element.

https://adaptivecards.io/explorer/AdaptiveCard.html

So this implies

card.Speak = 'Whatever'

AdaptiveCards is flexible in that you can add properties that should be ignored by the renderer... confusing because if you put in properties with the same names you won't get any errors and/or it appears something doesn't work when expected.

The next issue is that the speak property is in the context of the entire card, not just an element like textblock. If you want to create a mechanism that translates the card elements to speech based on hints attached to those elements, you need to write this yourself.

Finally, adding a Speak property to a card will only work in channels that support speaking AdaptiveCards. Believe it or not, Cortana does NOT do this. You would need to copy the Speak property from the card and then attach it to the activity's speak property for Cortana to say the result. Check out

https://learn.microsoft.com/en-us/cortana/skills/adding-speech

Micromuncher
  • 903
  • 7
  • 19
  • 1
    I'm putting up a V3 C# example https://github.com/microsoft/cortana-skills-samples/tree/master/Consumer/CSharp today... – Micromuncher May 30 '19 at 15:28
  • So is there a way to convert my adaptive card content object to a single string? I did try the way you did in your solution but I was getting the error saying" Cannot cast Adaptivecard object to jobject. Or are you suggesting that I save each adaptive card element content to string and assign the string to speak property of my reply activity? – Elma Sarah Daniel May 31 '19 at 12:43
  • 1
    Check out https://github.com/microsoft/cortana-skills-samples/tree/master/Consumer/CSharp/AdaptiveCardSkill on github. In the card, you will see a speak property that summarizes the card and what the user can say. Automating translation from elements to speech could be tricky; and likely unnatural from speech perspective. (It might sound a lot like accessibility readers.) I suggest you summarize the card inputs and invocation expectations - as that way it can sound like natural language. – Micromuncher May 31 '19 at 15:28
  • Also, some time today we'll have updated documentation here https://learn.microsoft.com/en-us/cortana/skills/adaptive-cards – Micromuncher May 31 '19 at 15:29
  • Thanks.. Much awaited solution – Elma Sarah Daniel May 31 '19 at 16:55