BotFramework-WebChat icon indicating copy to clipboard operation
BotFramework-WebChat copied to clipboard

Adaptive Card - Speak tag

Open Kumar3010 opened this issue 6 years ago • 10 comments

speak tag is not working when set in the content of the json schema of an adaptive card. ~~also we have a scenario where a drop down has to be selected and click on submit. if user just says submit, action is being submitted but the value from the drop down is going as null.~~ any thoughts. the sample adaptive card is as follows:- image

Kumar3010 avatar Apr 13 '20 07:04 Kumar3010

@Kumar3010,

First, for the "drop down" question, can you please submit that as a separate issue. I'm going to strike out the text in your question, for clarity.

As for the adaptive card speak issue, can you please post the code you are using for the (1) adaptive card, (2) how you are sending the adaptive card in your bot, and (3) how you are implementing speech in your Web Chat code? Is this "webSpeechPonyfillFactory", Direct Line Speech, or some other method?

stevkan avatar Apr 16 '20 00:04 stevkan

On behalf of @kumar3010 am updating the example

Adaptive card for speak is :

{ "type": "AdaptiveCard", "version": "1.0", "speak":"<select_timezone>", "body": [ { } ] }

In the dialog replacing the value of <select_timezone> as

StringBuilder stringBuilderJson = new StringBuilder(adaptiveCardPath); stringBuilderJson.Replace("<select_timezone>", _responseManager.GetResponse(HourGlassResponses.SelectTimeZone).Text);

returning response as

var response = MessageFactory.Attachment(attachment, ssml: card.Speak, inputHint: InputHints.ExpectingInput); response.ChannelData = new { speak = true }; await stepContext.Context.SendActivityAsync(response);

and speech in web chat is done using custom speech service

saikiran521 avatar Apr 17 '20 06:04 saikiran521

@saikiran521, @Kumar3010 Can you please tell me which custom speech service you are using or provide the code used for that? Some of the services have different limitations, so it will be useful to know how this is being instantiated.

stevkan avatar Apr 21 '20 20:04 stevkan

@stevkan we are using Microsoft custom speech service and the code is as below :

window.WebChat.renderWebChat({ directLine: window.WebChat.createDirectLine({ token: 'toren' }), userID: id, username: id, locale: 'en-US', styleOptions: styleOptions, store: store, selectVoice: (voices, activity) => global_voiceModel == "BenjaminRUS" ? voices.find(({ name }) => /BenjaminRUS/iu.test(name)) : voices.find(({ name }) => /JessaRUS/iu.test(name)), webSpeechPonyfillFactory: createPonyfillFactory() }, document.getElementById('webchat')); document.querySelector('#webchat > *').focus();

function createPonyfillFactory() { const speechServicesPonyfillFactory = window.WebChat.createCognitiveServicesSpeechServicesPonyfillFactory({ authorizationToken: user.voiceToken, region: 'northeurope', });

return (options) => { const speech = speechServicesPonyfillFactory(options);

return {
  SpeechGrammarList: speech.SpeechGrammarList,
  SpeechRecognition: speech.SpeechRecognition,

  speechSynthesis: global_enableSpeech ? speech.speechSynthesis : null,
  SpeechSynthesisUtterance: global_enableSpeech ? speech.SpeechSynthesisUtterance : null
};

} }

saikiran521 avatar Apr 22 '20 06:04 saikiran521

@saikiran521, can you please try adapting the below code to yours? I was unable to effectively use the code you supplied, however I am able to get speech from the adaptive card when using the below implementation.

In my adaptive card, I have included the "speak" property which is then replaced before being wrapped into an attachment and passed to sendActivityAsync().

static Attachment CreateAdaptiveCardAttachment(string filePath)
{
    var adaptiveCardJson = File.ReadAllText(filePath);
    adaptiveCardJson = adaptiveCardJson.Replace("What shall I do for you?!", "Who are you and what do you want?!");
    var adaptiveCardAttachment = new Attachment()
    {
        ContentType = "application/vnd.microsoft.card.adaptive",
        Content = JsonConvert.DeserializeObject(adaptiveCardJson),
    };
    return adaptiveCardAttachment;
}

var cardAttachment = CreateAdaptiveCardAttachment(card);

await turnContext.SendActivityAsync(MessageFactory.Attachment(cardAttachment, inputHint: InputHints.ExpectingInput), cancellationToken);

stevkan avatar Apr 23 '20 18:04 stevkan

@stevkan - thank you for your response we will try and get back to you. for the other issue i will raise another ticket.

thanks, Kumar

Kumar3010 avatar Apr 25 '20 02:04 Kumar3010

@stevkan -could you please post your adaptive card json. wanted to look at the json.

Kumar3010 avatar Apr 27 '20 06:04 Kumar3010

@Kumar3010, I'm actually using the 07.using-adaptive-cards sample from the BotBuilder-Samples repo, specifically the "SolitaireCard.json" adaptive card. I added the "speak" property into the card (see below). The above code I included within the OnMessageActivityAsync activity handler found inside "AdaptiveCardsBot.cs".

{
  "$schema": "http://adaptivecards.io/schemas/adaptive-card.json",
  "type": "AdaptiveCard",
  "version": "1.0",
  "backgroundImage": "https://download-ssl.msgamestudios.com/content/mgs/ce/production/SolitaireWin10/dev/adapative_card_assets/v1/card_background.png",
  "speak": "How can I help you?",
  "body": [
    {
      "type": "ColumnSet",
      "columns": [
        {
          "type": "Column",
          "width": 1,
          "items": [
            {
              "type": "Image",
              "url": "https://download-ssl.msgamestudios.com/content/mgs/ce/production/SolitaireWin10/dev/adapative_card_assets/v1/tile_spider.png",
              "size": "stretch"
            }
          ]
        },
        {
          "type": "Column",
          "width": 1,
          "items": [
            {
              "type": "TextBlock",
              "text": "Click here to play another game of Spider in Microsoft Solitaire Collection!",
              "color": "light",
              "weight": "bolder",
              "wrap": true,
              "size": "default",
              "horizontalAlignment": "center"
            }
          ]
        }
      ]
    }
  ]
}

stevkan avatar Apr 27 '20 19:04 stevkan

Closing this issue due to lack of activity. If the issue persists, please feel free to reopen.

stevkan avatar May 05 '20 07:05 stevkan

How can I change the voice of the bot? With this code that works well for me but I want to change the voice DIRECT LINE SPEECH

Web Chat