botframework-sdk icon indicating copy to clipboard operation
botframework-sdk copied to clipboard

Json FormFlow speech not working in Cortana

Open SwetalinaGitHub opened this issue 8 years ago • 2 comments

Bot Info

  • SDK Platform: .Net
  • SDK Version: 3.1.3.0
  • Active Channels: Cortana
  • Deployment Environment: Azure Bot Service, Azure App Service, Cortana

Issue Description

Speech is not working for Form-flow json enum options in Cortana channel. Added below code to convert text to speech , and this class is called in Global.asax.cs file. This converts json dialogs to speech if there is no enum. But it is not working if we have enum or button options.

public sealed class TexttoSpeech: IMessageActivityMapper { public IMessageActivity Map(IMessageActivity message) { // only set the speak if it is not set by the developer. var channelCapability = new ChannelCapability(Address.FromActivity(message));

        if (channelCapability.SupportsSpeak() && string.IsNullOrEmpty(message.Speak))
        {
            message.Speak = message.Text;                
        }
        return message;
    }
}

Code Example

"properties": { "printLocation": { "Prompt": { "Patterns": [ "Do you want to print at office or facility? Or do you want to print from home or another remote location outside the office? {||}" ] }, "type": [ "string", null ], "enum": [ "Office", "Home" ] },

Reproduction Steps

1. 2. 3.

Expected Behavior

Speech shall work for the message even if we have enum/buttons.

Actual Results

If we have enum, the entire message is displaying but speech is not working. If we remove the enum, then speech is working. Our requirement is getting speech along with enum buttons being displayed.

SwetalinaGitHub avatar Apr 05 '18 09:04 SwetalinaGitHub

What you could try is this: Try updating the Conversation container with this:

  Conversation.UpdateContainer(
            builder =>
            {
                builder
                   .RegisterType<TextToSpeakActivityMapper>()
                   .AsImplementedInterfaces()
                   .SingleInstance();
            });

And use this class to map Text to Speak.

public sealed class TextToSpeakActivityMapper : IMessageActivityMapper
    {
        public IMessageActivity Map(IMessageActivity message)
        {
            // only set the speak if it is not set by the developer.
            var channelCapability = new ChannelCapability(Address.FromActivity(message));

            if (channelCapability.SupportsSpeak() && string.IsNullOrEmpty(message.Speak))
            {
                if (string.IsNullOrEmpty(message.Text))
                {
                    var attachment = message.Attachments[0].Content as Microsoft.Bot.Connector.HeroCard;
                    if (attachment != null)
                        message.Speak = attachment.Text;
                }
                else
                    message.Speak = message.Text;
            }

            return message;
        }
    }

nodeomega avatar Apr 12 '18 00:04 nodeomega

Closing this issue as there has been no reply for an extended period. If this issue persists, feel free to open a new support request. Thank you.

nodeomega avatar Apr 18 '18 22:04 nodeomega