Пример #1
0
    private void ConvertTextToSpeech(Activity message)
    {
        Activity initialMessage = message;

        try
        {
            if (message.Type == ActivityTypes.Message)
            {
                if (string.IsNullOrEmpty(message.Speak))
                {
                    if (string.IsNullOrEmpty(message.Text))
                    {
                        if (message.Attachments[0].Content is HeroCard attachment)
                        {
                            message.Speak = TextToSpeechHelper.ConvertTextToSpeechText(attachment.Text);
                        }
                    }
                    else
                    {
                        message.Speak = TextToSpeechHelper.ConvertTextToSpeechText(message.Text);
                    }

                    message.Speak = message.Speak.Trim();

                    if (ignoreList.Where(i => message.Speak.ToLower().StartsWith(i.ToLower())).Count() != 0)
                    {
                        message.Speak = null;
                        ignoredSpeak  = true;
                    }
                }
                else if (string.IsNullOrWhiteSpace(message.Speak))
                {
                    message.Speak = null;
                }

                if ((!string.IsNullOrEmpty(message.Speak) && (message.Speak.EndsWith("?") || message.Speak.StartsWith("Is this correct?"))) ||
                    (!string.IsNullOrEmpty(message.Text) && message.Text.EndsWith("?")))
                {
                    message.InputHint = InputHints.ExpectingInput;
                }

                // IOs won't work with expecting input
                if (message.Recipient.Name.EndsWith(":ios"))
                {
                    message.InputHint = InputHints.AcceptingInput;
                }
            }
        }
        catch (Exception)
        {
            message = initialMessage;
        }
    }
Пример #2
0
    private void ConvertTextToSpeech(Activity message)
    {
        Activity initialMessage = message;

        try
        {
            if (message.Type == ActivityTypes.Message)
            {
                bool ignoredSpeak = false;
                if (string.IsNullOrEmpty(message.Speak))
                {
                    if (string.IsNullOrEmpty(message.Text))
                    {
                        if (message.Attachments[0].Content is HeroCard attachment)
                        {
                            message.Speak = TextToSpeechHelper.ConvertTextToSpeechText(attachment.Text);
                        }
                    }
                    else
                    {
                        message.Speak = TextToSpeechHelper.ConvertTextToSpeechText(message.Text);
                    }

                    message.Speak = message.Speak.Trim();

                    if (ignoreList.Where(i => message.Speak.ToLower().StartsWith(i.ToLower())).Count() != 0)
                    {
                        message.Speak = null;
                        ignoredSpeak  = true;
                    }
                }
                else if (string.IsNullOrWhiteSpace(message.Speak))
                {
                    message.Speak = " ";
                }

                if ((!string.IsNullOrEmpty(message.Speak) && (message.Speak.EndsWith("?") || message.Speak.StartsWith("Is this correct?"))) ||
                    (!string.IsNullOrEmpty(message.Text) && message.Text.EndsWith("?")) ||
                    ignoredSpeak)
                {
                    message.InputHint = InputHints.ExpectingInput;
                }

                // IOs won't work with expecting input
                if (message.Recipient.Name.EndsWith(":ios"))
                {
                    message.InputHint = InputHints.AcceptingInput;
                }
            }

            // Logic needed to increase speech speed.
            // if (!string.IsNullOrEmpty(message.Speak))
            // {
            //    message.Speak = @"<speak version='1.0' " + "xmlns='http://www.w3.org/2001/10/synthesis' xml:lang='en-GB'><prosody rate=\"1.5\">" + message.Speak + "</prosody></speak>";
            // }
        }
        catch (Exception)
        {
            message = initialMessage;
        }
    }