Ejemplo n.º 1
0
        private async Task ProcessRecognizedCall(SpeechRecognitionEventArgs e)
        {
            using (var activity = Constants.ActivitySource.StartActivity("ProcessRecognizedCall", ActivityKind.Server))
            {
                Logger.Info($"{_logClientId}| Incoming Transmission: {e.Result.Text}");
                var luisJson = Task.Run(() => LuisService.ParseIntent(e.Result.Text)).Result;
                Logger.Debug($"{_logClientId}| LUIS Response: {luisJson}");

                var radioCall = new BaseRadioCall(luisJson);

                activity?.AddTag("Frequency", _frequency);
                activity?.AddTag("BotType", _botType);
                activity?.AddTag("Callsign", _callsign);
                activity?.AddTag("Sender", radioCall.Sender?.Callsign);
                activity?.AddTag("Intent", radioCall.Intent);
                activity?.AddTag("Request", radioCall.Message);

                var response = Controller.ProcessRadioCall(radioCall);
                activity?.AddTag("Response Text", response);

                if (!string.IsNullOrEmpty(response))
                {
                    Logger.Info($"{_logClientId}| Outgoing Transmission: {response}");
                    var audioResponse = await Task.Run(() => Speaker.CreateResponse(
                                                           $"<speak version=\"1.0\" xmlns=\"https://www.w3.org/2001/10/synthesis\" xml:lang=\"en-US\"><voice name =\"{Controller.Voice}\">{response}</voice></speak>"));

                    if (audioResponse == null)
                    {
                        activity?.AddTag("Response", "Failure");
                        activity?.AddEvent(new ActivityEvent("Synthesis Failure"));
                        Logger.Error($"{_logClientId}| Synthesis Failure");
                        using (Constants.ActivitySource.StartActivity("EnqueueResponseAudio", ActivityKind.Producer))
                        {
                            Logger.Trace($"{_logClientId}| Sending Failure Message");
                            Controller.Radio.TransmissionQueue.Enqueue(FailureMessage);
                        }
                    }
                    else
                    {
                        activity?.AddTag("Response", "Success");
                        using (Constants.ActivitySource.StartActivity("EnqueueResponseAudio", ActivityKind.Producer))
                        {
                            Controller.Radio.TransmissionQueue.Enqueue(audioResponse);
                        }
                    }
                }
                else
                {
                    activity?.AddTag("Response", "Ignored");
                    Logger.Info($"{_logClientId}| Radio Call Ignored due to null response for Radio Call Processing");
                }

                if (Controller.Radio.discordTransmissionLogChannelId > 0)
                {
                    LogTransmissionToDiscord(radioCall, response);
                }
            }
        }
        private async Task SendMessage(string message)
        {
            var response =
                $"{_sender.Callsign}, {_airfieldName} ground, {message}";

            var ssmlResponse =
                $"<speak version=\"1.0\" xmlns=\"https://www.w3.org/2001/10/synthesis\" xml:lang=\"en-US\"><voice name =\"{_voice}\">{response}</voice></speak>";

            var audioData = await Speaker.CreateResponse(ssmlResponse);

            if (audioData != null)
            {
                Logger.Info($"Outgoing Transmission: {response}");
                _responseQueue.Enqueue(audioData);
            }
        }
Ejemplo n.º 3
0
        private async Task SendMessage(string message)
        {
            var response = $"{_sender.Callsign}, {message}";

            var ssmlResponse =
                $"<speak version=\"1.0\" xmlns=\"https://www.w3.org/2001/10/synthesis\" xml:lang=\"en-US\"><voice name =\"{_voice}\">{response}</voice></speak>";

            var audioData = await Speaker.CreateResponse(ssmlResponse);

            if (audioData == null)
            {
                Logger.Debug($"{_sender.Id} - {_sender.Callsign}:| First Synthesis failed, trying again");
                audioData = await Task.Run(() => Speaker.CreateResponse(ssmlResponse));
            }

            if (audioData != null)
            {
                Logger.Info($"{_sender.Id} - {_sender.Callsign}: Outgoing Transmission: {response}");
                _responseQueue.Enqueue(audioData);
            }
        }
        private async Task CheckAsync()
        {
            try
            {
                Logger.Debug($"{_sender.Id} - {_sender.Callsign}: Peforming Warning Radius check");

                if (WarningStates.ContainsKey(_sender.Id) == false)
                {
                    WarningStates.TryAdd(_sender.Id, new List <string>());
                }

                _previousId = _sender.Id;
                await GameQuerier.PopulatePilotData(_sender);

                // If the caller does not exist any more or the ID has been reused for a different object
                // then cancel the check.
                if (_sender.Id == null || _sender.Id != _previousId)
                {
                    _sender.Id = "DELETED";
                    Logger.Debug(
                        $"{_sender.Id} - {_sender.Callsign}: Stopping Warning Radius Check. CallerId changed, New: {_sender.Id} , Old: {_previousId}.");
                    Stop();
                    return;
                }

                var contact =
                    await GameQuerier.GetBogeyDope(_sender.Coalition, _sender.Group, _sender.Flight, _sender.Plane);

                if (contact == null)
                {
                    Logger.Debug($"{_sender.Id} - {_sender.Callsign}: No contacts found");
                    return;
                }

                if (contact.Range > _distance)
                {
                    Logger.Debug($"{_sender.Id} - {_sender.Callsign}: Contact {contact.Id} is more than {_distance} miles ({contact.Range})");
                    return;
                }

                if (WarningStates[_sender.Id].Contains(contact.Id))
                {
                    Logger.Debug($"{_sender.Id} - {_sender.Callsign}: Contact {contact.Id} already reported");
                    return;
                }

                Logger.Debug($"{_sender.Id} - {_sender.Callsign}: New contact {contact.Id} at {contact.Range} miles");

                using (var activity =
                           Constants.ActivitySource.StartActivity("WarningRadiusChecker.SendWarning", ActivityKind.Consumer))
                {
                    var response = $"{_sender.Callsign}, {_awacs}, Threat, {BogeyDope.BuildResponse(_sender, contact)}";
                    Logger.Debug($"{_sender.Id} - {_sender.Callsign}: Response: {response}");

                    var ssmlResponse =
                        $"<speak version=\"1.0\" xmlns=\"https://www.w3.org/2001/10/synthesis\" xml:lang=\"en-US\"><voice name =\"{_voice}\">{response}</voice></speak>";

                    // Try twice for timeout reasons
                    var audioData = await Speaker.CreateResponse(ssmlResponse);

                    if (audioData == null)
                    {
                        Logger.Debug($"{_sender.Id} - {_sender.Callsign}:| First Synthesis failed, trying again");
                        audioData = await Task.Run(() => Speaker.CreateResponse(ssmlResponse));
                    }

                    if (audioData != null)
                    {
                        Logger.Info($"{_sender.Id} - {_sender.Callsign}: Outgoing Transmission: {response}");
                        _responseQueue.Enqueue(audioData);
                        WarningStates[_sender.Id].Add(contact.Id);
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error(ex, $"{_sender.Id} - {_sender.Callsign}: Error checking warning radius");
            }
        }