4

我正在通过首先使用 FormFlow 构建机器人来构建 Coratana 技能。我使用 LUIS 检测到我的意图和实体,并将这些实体传递给我的 FormFlow 对话框。如果一个或多个 FormFlow 字段未填写,FormFlow 对话框会提示用户填写缺失的信息,但此提示不会语音,仅显示在 cortana 屏幕上。FormFlow 有没有办法说出提示?

在下面显示的屏幕截图中,提示“您需要机场班车吗?” 只是显示而不说话:

在此处输入图像描述

我的 formFlow 定义如下所示:

 [Serializable]
public class HotelsQuery
{
    [Prompt("Please enter your {&}")]
    [Optional]
    public string Destination { get; set; }

    [Prompt("Near which Airport")]
    [Optional]
    public string AirportCode { get; set; }

    [Prompt("Do you need airport shuttle?")]
    public string DoYouNeedAirportShutle { get; set; }
}
4

2 回答 2

6

我不认为 Speak 目前在FormFlow.

作为一种解决方法,您可以做的是添加一个IMessageActivityMapper基本上促进文本自动说话的内容。

namespace Code
{
    using Microsoft.Bot.Builder.Dialogs;
    using Microsoft.Bot.Builder.Dialogs.Internals;
    using Microsoft.Bot.Connector;

    /// <summary>
    /// Activity mapper that automatically populates activity.speak for speech enabled channels.
    /// </summary>
    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))
            {
                message.Speak = message.Text;
            }

            return message;
        }
    }
}

然后要使用它,您需要在Global.asax.cs文件中将其注册为:

 var builder = new ContainerBuilder();

 builder
   .RegisterType<TextToSpeakActivityMapper>()
   .AsImplementedInterfaces()
   .SingleInstance();

 builder.Update(Conversation.Container);
于 2017-06-09T19:12:14.523 回答
2

Ezequiel Jadib 的答案帮助我解决了我的用例所需的问题。如果文本是一个问题,我只是添加了一些额外的行来设置该InputHint字段。ExpectingInput使用此配置,Cortana 会自动收听我的回答,而我不必自己激活麦克风。

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;

        // set InputHint to ExpectingInput if text is a question
        var isQuestion = message.Text?.EndsWith("?");
        if (isQuestion.GetValueOrDefault())
        {
            message.InputHint = InputHints.ExpectingInput;
        }
    }

    return message;
}
于 2017-07-13T17:40:26.540 回答