Exemple #1
0
        /// <summary>
        /// Say, log and send websocket events for the message
        /// </summary>
        /// <param name="message"></param>
        /// <param name="voice"></param>
        private async void BroadcastDetails(string message, string voice = null, bool useBuiltInTTS = false)
        {
            if (useBuiltInTTS)
            {
                await _misty.SpeakAsync(message, true, null);

                return;
            }
            try
            {
                _misty.SkillLogger.Log(message);
                _misty.PublishMessage(message, null);

                if (!string.IsNullOrWhiteSpace(voice))
                {
                    _azureCognitive.CurrentSpeakingVoice = voice;
                }

                var audioData = await _azureCognitive.TextToSpeechFile(message);

                if (audioData == null || audioData.Count() == 0)
                {
                    //Azure failed, use onboard TTS
                    await _misty.SpeakAsync(message, true, null);
                }
                else
                {
                    await _misty.SaveAudioAsync("TTSFile.wav", audioData, true, true);
                }
            }
            catch (Exception ex)
            {
                _misty.SkillLogger.Log("Failed to speak and broadcast details.", ex);
            }
        }