//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Executes the start action. </summary> /// /// <param name="host"> The host. This may be null. </param> /// /// <returns> True if it succeeds, false if it fails. </returns> //////////////////////////////////////////////////////////////////////////////////////////////////// public new bool OnStart([CanBeNull] HostControl host) { Host = host; Name = "SpeechBot_" + Environment.MachineName; Start(host); voice.SpeakCompleted += Voice_SpeakCompleted; voice.SpeakStarted += Voice_SpeakStarted; Subscribe(); using (var scope = _container?.BeginLifetimeScope()) { var logger = scope?.Resolve <MSBaseLogger>(); logger?.LogInformation(Name + " Microservice Starting"); } Cache = CacheFactory.Build("SpeechBotCache", settings => settings.WithSystemRuntimeCacheHandle("SpeechBotCache")); const double interval = 60000; _timer = new Timer(interval); _timer.Elapsed += OnTick; _timer.AutoReset = true; _timer.Start(); SpeechRequestMessage msg = new SpeechRequestMessage { rate = 0, maleSpeaker = 0, volume = 50, ID = 1, text = "As to country N and President Z, we believe we’re entering a missile renaissance, said Ian Williams, ", }; msg.text += "an associate director at the Center for Strategic and International Studies, who has been compiling data on missile programs in different countries."; msg.text += " A growing number of countries with ready access to missiles increases regional tensions and makes war more likely, Mr.Williams said. Countries are more apt to use their arsenals if they think their missiles could be targeted."; msg.text += " In addition, many of the missiles being developed by these countries are based on obsolete technologies, which makes them less accurate, increasing the risk to civilians. And there is a risk that missiles could fall into the hands of militias and terrorist groups."; msg.text += " Y'all should buy Bitcoin at $15543. Foreign currency comes in at ? 12435. It might also show, says Mr. Williams, like ? 15533435."; // Bus.Publish(msg, "Speech"); WikipediaSearchMessage wmsg = new WikipediaSearchMessage { maxReturns = 10, searchTerm = "cryptocurrency" }; Bus.Publish(wmsg, "Speech"); return(true); }
//////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> Process the speech request message described by msg. </summary> /// /// <param name="msg"> The message. </param> /// /// <returns> True if it succeeds, false if it fails. </returns> //////////////////////////////////////////////////////////////////////////////////////////////////// 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.Argument(msg.volume).LessThanOrEqualTo(100); Ensure.Argument(msg.rate).GreaterThanOrEqualTo(-10); Ensure.Argument(msg.rate).LessThanOrEqualTo(10); voice.Volume = msg.volume; voice.Rate = msg.rate; PromptBuilder builder = new PromptBuilder(); builder.ClearContent(); builder.StartSentence(); builder.AppendText(msg?.text); builder.EndSentence(); voice.SpeakAsync(builder); return(true); }