/// <summary> /// Initializes a new instance of the <see cref="SignalDetectionHelper"/> class. /// </summary> public SignalDetectionHelper(IAgentSessionManager agentSessionManager) { this.agentSessionManager = agentSessionManager; this.logger = LogRouter.GetClassLogger(); this.keywordResponseLock = new object(); this.kwsPerformanceLogger = new KwsPerformanceLogger(); }
/// <summary> /// Initializes a new instance of the <see cref="DialogManager{TInputType}"/> class. /// </summary> /// <param name="dialogBackend"> The dialog backend for the manager to use. </param> /// <param name="keywordRegistration"> The keyword registration with the current keyword file information.</param> /// <param name="dialogAudioInput"> The input audio provider. </param> /// <param name="agentSessionManager"> The manager that provides the instance of agent session wrapper. </param> /// <param name="dialogAudioOutput"> The dialog audio output sink to use. </param> public DialogManager( IDialogBackend <TInputType> dialogBackend, IKeywordRegistration keywordRegistration, IDialogAudioInputProvider <TInputType> dialogAudioInput, IAgentSessionManager agentSessionManager, IDialogAudioOutputAdapter dialogAudioOutput = null) { Contract.Requires(dialogBackend != null); Contract.Requires(agentSessionManager != null); this.logger = LogRouter.GetClassLogger(); this.dialogBackend = dialogBackend; this.dialogBackend.SessionStarted += (id) => this.logger.Log($"DialogManager: Session start: {id}"); this.dialogBackend.SessionStopped += (id) => this.logger.Log($"DialogManager: Session stop: {id}"); this.dialogBackend.KeywordRecognizing += this.OnKeywordRecognizing; this.dialogBackend.KeywordRecognized += this.OnKeywordRecognized; this.dialogBackend.SpeechRecognizing += this.OnSpeechRecognizing; this.dialogBackend.SpeechRecognized += async(text) => await this.OnSpeechRecognizedAsync(text); this.dialogBackend.DialogResponseReceived += this.OnActivityReceived; this.dialogBackend.ErrorReceived += async(errorInformation) => await this.OnErrorReceivedAsync(errorInformation); this.dialogAudioInput = dialogAudioInput; this.keywordRegistration = keywordRegistration; this.agentSessionManager = agentSessionManager; this.agentSessionManager.SignalDetected += (sender, args) => this.HandleSignalDetection(args); this.InitializeSignalDetectionHelper(); _ = this.InitializeAsync(dialogAudioOutput); }
public static async Task<DialogManager<List<byte>>> CreateMockManagerAsync( IDialogBackend<List<byte>> backend, IKeywordRegistration keywordRegistration, IAgentSessionManager agentSessionManager) { var dialogManager = new DialogManager<List<byte>>(backend, keywordRegistration, new AgentAudioInputProvider(), agentSessionManager); await dialogManager.InitializeAsync(); return dialogManager; }
/// <summary> /// Initializes a new instance of the <see cref="MainPage"/> class. /// </summary> public MainPage() { this.logger = LogRouter.GetClassLogger(); this.InitializeComponent(); this.app = App.Current as App; this.app.HasReachedForeground = true; this.services = this.app.Services; this.dialogManager = this.services.GetRequiredService <IDialogManager>(); this.keywordRegistration = this.services.GetRequiredService <IKeywordRegistration>(); this.agentSessionManager = this.services.GetRequiredService <IAgentSessionManager>(); this.informationLogs = new HashSet <TextBlock>(); this.errorLogs = new HashSet <TextBlock>(); this.noiseLogs = new HashSet <TextBlock>(); // Ensure that we restore the full view (not the compact mode) upon foreground launch _ = this.UpdateViewStateAsync(); // Ensure we have microphone permissions and that we pop a consent dialog if the user // hasn't already given an explicit yes/no. _ = Task.Run(async() => { var control = await AudioCaptureControl.GetInstanceAsync(); await control.MicrophoneCapability.RequestAccessAsync(); }); // Kick off the registration and/or retrieval of the 1st-stage keyword information _ = this.DoKeywordSetupAsync(); // Populate the drop-down list for TTS audio output formats and select the current choice var supportedFormats = DirectLineSpeechAudio.SupportedOutputFormats; foreach (var entry in supportedFormats) { this.OutputFormatComboBox.Items.Add(entry.Label); } this.OutputFormatComboBox.SelectedItem = this.OutputFormatComboBox.Items.FirstOrDefault(item => item.ToString() == LocalSettingsHelper.OutputFormat.Label); // Wire a few pieces of UI handling that aren't trivially handled by XAML bindings this.AddUIHandlersAsync(); // Ensure consistency between a few dependent controls and their settings this.UpdateUIBasedOnToggles(); this.Conversations = new ObservableCollection <Conversation>(); this.ChatHistoryListView.ContainerContentChanging += this.OnChatHistoryListViewContainerChanging; }
/// <summary> /// Initializes a new instance of the <see cref="App"/> class. /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { LogRouter.Initialize(); this.logger = LogRouter.GetClassLogger(); this.logger.Log("Constructor: app launched"); this.Suspending += this.OnSuspending; MVARegistrationHelpers.UnlockLimitedAccessFeature(); this.CopyConfigAndAssignValues().GetAwaiter(); var keywordRegistration = new KeywordRegistration( "Contoso", "{C0F1842F-D389-44D1-8420-A32A63B35568}", "1033", "MICROSOFT_KWSGRAPH_V1", "ms-appx:///MVAKeywords/Contoso.bin", new Version(1, 0, 0, 0), "ms-appx:///SDKKeywords/Contoso.table"); this.agentSessionManager = new AgentSessionManager(); this.dialogManager = new DialogManager <List <byte> >( new DirectLineSpeechDialogBackend(), keywordRegistration, new AgentAudioInputProvider(), this.agentSessionManager, new MediaPlayerDialogAudioOutputAdapter()); var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton(this.dialogManager); serviceCollection.AddSingleton <IKeywordRegistration>(keywordRegistration); serviceCollection.AddSingleton(this.agentSessionManager); this.Services = serviceCollection.BuildServiceProvider(); CoreApplication.Exiting += async(object sender, object args) => { this.logger.Log($"Exiting!"); await this.dialogManager.FinishConversationAsync(); var session = await this.agentSessionManager.GetSessionAsync(); session?.Dispose(); this.logger.Log("Exited"); }; this.InitializeSignalDetection(); this.InitializeComponent(); }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { this.InitializeComponent(); this.Suspending += OnSuspending; Task.Run(async() => await LocalSettingsHelper.InitializeAsync()).Wait(); MVARegistrationHelpers.UnlockLimitedAccessFeature(); LogRouter.Initialize(); this.keywordRegistration = new KeywordRegistration(new Version(1, 0, 0, 0)); this.agentSessionManager = new AgentSessionManager(); //var _ = this.UpdateSessionAsync(); _ = this.DoKeywordSetupAsync(); MVARegistrationHelpers.IsBackgroundTaskRegistered = true; }
/// <summary> /// Initializes a new instance of the <see cref="App"/> class. /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { LogRouter.Initialize(); this.logger = LogRouter.GetClassLogger(); this.logger.Log("Constructor: app launched"); Task.Run(async() => await LocalSettingsHelper.InitializeAsync()).Wait(); this.Suspending += this.OnSuspending; MVARegistrationHelpers.UnlockLimitedAccessFeature(); var keywordRegistration = new KeywordRegistration( new Version(1, 0, 0, 0)); this.agentSessionManager = new AgentSessionManager(); this.dialogManager = new DialogManager <List <byte> >( new DirectLineSpeechDialogBackend(), keywordRegistration, new AgentAudioInputProvider(), this.agentSessionManager, new MediaPlayerDialogAudioOutputAdapter()); var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton(this.dialogManager); serviceCollection.AddSingleton <IKeywordRegistration>(keywordRegistration); serviceCollection.AddSingleton(this.agentSessionManager); this.Services = serviceCollection.BuildServiceProvider(); CoreApplication.Exiting += async(object sender, object args) => { this.logger.Log($"Exiting!"); await this.dialogManager.FinishConversationAsync(); var session = await this.agentSessionManager.GetSessionAsync(); session?.Dispose(); this.logger.Log("Exited"); }; this.InitializeSignalDetection(); this.InitializeComponent(); }
/// <summary> /// Initializes the singleton application object. This is the first line of authored code /// executed, and as such is the logical equivalent of main() or WinMain(). /// </summary> public App() { this.InitializeComponent(); this.Suspending += OnSuspending; MVARegistrationHelpers.UnlockLimitedAccessFeature(); LogRouter.Initialize(); this.keywordRegistration = new KeywordRegistration( "Contoso", "{C0F1842F-D389-44D1-8420-A32A63B35568}", "1033", "MICROSOFT_KWSGRAPH_V1", "ms-appx:///MVAKeywords/Contoso.bin", new Version(1, 0, 0, 0), "ms-appx:///SDKKeywords/Contoso.table"); this.agentSessionManager = new AgentSessionManager(); //var _ = this.UpdateSessionAsync(); _ = this.DoKeywordSetupAsync(); MVARegistrationHelpers.IsBackgroundTaskRegistered = true; }
public async Task TestMethodSetup() { MVARegistrationHelpers.UnlockLimitedAccessFeature(); this.speechRecognizingEvents = new List <string>(); this.speechRecognizedEvents = new List <string>(); this.signalRejectedEvents = new List <string>(); this.signalConfirmedEvents = new List <string>(); this.keywordRecognizingEvents = new List <string>(); this.keywordRecognizedEvents = new List <string>(); this.dialogResponseReceivedEvents = new List <DialogResponse>(); this.speechRecognizingEventReceived = new AutoResetEvent(false); this.speechRecognizedEventReceived = new AutoResetEvent(false); this.dialogResponseReceivedEventReceived = new AutoResetEvent(false); this.keywordRecognizingEventReceived = new AutoResetEvent(false); this.keywordRecognizedEventReceived = new AutoResetEvent(false); this.signalRejectedEventReceived = new AutoResetEvent(false); this.signalConfirmedEventReceived = new AutoResetEvent(false); this.mockBackend = new MockDialogBackend(); this.mockKeywordRegistration = new MockKeywordRegistration(); this.mockAgentSessionManager = new MockAgentSessionManager(); this.dialogManager = await DialogManagerShim.CreateMockManagerAsync(this.mockBackend, this.mockKeywordRegistration, this.mockAgentSessionManager); this.dialogManager.SpeechRecognizing += (s, e) => { this.speechRecognizingEvents.Add(e); this.speechRecognizingEventReceived.Set(); }; this.dialogManager.SpeechRecognized += (s, e) => { this.speechRecognizedEvents.Add(e); this.speechRecognizedEventReceived.Set(); }; this.dialogManager.DialogStateChanged += (before, after) => { if (before == ConversationalAgentState.Inactive && after == ConversationalAgentState.Listening) { // Shouldn't have received anything yet; just started Assert.IsTrue(this.speechRecognizingEvents.Count == 0); Assert.IsTrue(this.speechRecognizedEvents.Count == 0); Assert.IsTrue(this.dialogResponseReceivedEvents.Count == 0); } else if (before == ConversationalAgentState.Listening && after == ConversationalAgentState.Working) { // Transition should happen to working (and block!) BEFORE we get the recognized event Assert.IsTrue(this.speechRecognizingEvents.Count != 0); Assert.IsTrue(this.speechRecognizedEvents.Count == 0); Assert.IsTrue(this.dialogResponseReceivedEvents.Count == 0); } else if (before == ConversationalAgentState.Working && after == ConversationalAgentState.Inactive) { Assert.IsTrue(this.dialogResponseReceivedEvents.Count != 0); } else if (before == ConversationalAgentState.Inactive && after == ConversationalAgentState.Inactive) { Debug.WriteLine($"Weird transition: Inactive to Inactive"); } else if (before == ConversationalAgentState.Inactive && after == ConversationalAgentState.Detecting) { Debug.WriteLine($"Transition from inactive to detecting"); } else if (before == ConversationalAgentState.Detecting && after == ConversationalAgentState.Inactive) { Debug.WriteLine($"Transition from detecting to inactive"); } else if (before == ConversationalAgentState.Listening && after == ConversationalAgentState.Detecting) { Debug.WriteLine($"Transition from listening To detecting"); Assert.IsTrue(this.signalConfirmedEvents.Count == 0); } else if (before == ConversationalAgentState.Listening && after == ConversationalAgentState.Listening) { Debug.WriteLine($"Transition from listenting to listening"); Assert.IsTrue(this.signalConfirmedEvents.Count != 0); Assert.IsTrue(this.keywordRecognizedEvents.Count != 0); } else if (before == ConversationalAgentState.Detecting && after == ConversationalAgentState.Listening) { Debug.WriteLine($"Transition from detecting to listening"); } else if (before == ConversationalAgentState.Listening && after == ConversationalAgentState.Inactive) { Debug.WriteLine($"Transition from listening to inactive"); } else { Assert.Fail($"Unexpected state transition: {before.ToString()} to {after.ToString()}"); } }; this.dialogManager.DialogResponseReceived += (s, e) => { this.dialogResponseReceivedEvents.Add(e); this.dialogResponseReceivedEventReceived.Set(); }; this.dialogManager.SignalRejected += (e) => { this.signalRejectedEvents.Add(e.ToString()); this.signalRejectedEventReceived.Set(); }; this.dialogManager.SignalConfirmed += (e) => { this.signalConfirmedEvents.Add(e.ToString()); this.keywordRecognizingEvents.Add(e.ToString()); this.keywordRecognizedEvents.Add(e.ToString()); this.signalConfirmedEventReceived.Set(); this.keywordRecognizingEventReceived.Set(); this.keywordRecognizedEventReceived.Set(); }; }