Once we receive a message, specifically a speech request message, we need to process it. This message is telling us to use the text to speech engine to repeat vocally what was presented to us as text. We will assume that the validity of the message contents was checked on the sending side.
First, we will set the voice to be male or female, based upon the maleSpeaker flag in the message. We then set the volume and rate, pass in the text of the message, and let the TTS engine play back the audio:
bool ProcessSpeechRequestMessage(SpeechRequestMessage msg)
{
WriteLineInColor("Received Speech Bot Request", ConsoleColor.Red);
WriteLineInColor("Text to speak: " + msg.text, ConsoleColor.Yellow);
voice?.SelectVoiceByHints(msg.maleSpeaker == 1 ? VoiceGender.Male : VoiceGender.Female);
Ensure.Argument(msg.volume).GreaterThanOrEqualTo(0);
Ensure...