internal static SpeechEvent TryCreateSpeechEvent(ISpEventSource sapiEventSource, bool additionalSapiFeatures, SpeechAudioFormatInfo audioFormat) { SpeechEvent result = null; uint pulFetched; if (additionalSapiFeatures) { SPEVENTEX pEventArray; ((ISpEventSource2)sapiEventSource).GetEventsEx(1u, out pEventArray, out pulFetched); if (pulFetched == 1) { result = new SpeechEvent(pEventArray); } } else { SPEVENT pEventArray2; sapiEventSource.GetEvents(1u, out pEventArray2, out pulFetched); if (pulFetched == 1) { result = new SpeechEvent(pEventArray2, audioFormat); } } return(result); }
// This tries to get an event from the ISpEventSource. // If there are no events queued then null is returned. // Otherwise a new SpeechEvent is created and returned. internal static SpeechEvent TryCreateSpeechEvent(ISpEventSource sapiEventSource, bool additionalSapiFeatures, SpeechAudioFormatInfo audioFormat) { uint fetched; SpeechEvent speechEvent = null; if (additionalSapiFeatures) { SPEVENTEX sapiEventEx; ((ISpEventSource2)sapiEventSource).GetEventsEx(1, out sapiEventEx, out fetched); if (fetched == 1) { speechEvent = new SpeechEvent(sapiEventEx); } } else { SPEVENT sapiEvent; sapiEventSource.GetEvents(1, out sapiEvent, out fetched); if (fetched == 1) { speechEvent = new SpeechEvent(sapiEvent, audioFormat); } } return(speechEvent); }
internal EventNotify(ISpEventSource sapiEventSource, IAsyncDispatch dispatcher, bool additionalSapiFeatures) { _sapiEventSourceReference = new WeakReference(sapiEventSource); _dispatcher = dispatcher; _additionalSapiFeatures = additionalSapiFeatures; _notifySink = new SpNotifySink(this); sapiEventSource.SetNotifySink(_notifySink); }
internal EventNotify(ISpEventSource sapiEventSource, IAsyncDispatch dispatcher, bool additionalSapiFeatures) { // Remember event source _sapiEventSourceReference = new WeakReference(sapiEventSource); _dispatcher = dispatcher; _additionalSapiFeatures = additionalSapiFeatures; // Start listening to events from sapiEventSource. _notifySink = new SpNotifySink(this); sapiEventSource.SetNotifySink(_notifySink); }
internal void Dispose() { lock (this) { if (_sapiEventSourceReference != null) { ISpEventSource spEventSource = (ISpEventSource)_sapiEventSourceReference.Target; if (spEventSource != null) { spEventSource.SetNotifySink(null); _notifySink = null; } } _sapiEventSourceReference = null; } }
// Finalizer is not required since ISpEventSource and AsyncOperation both implement appropriate finalizers. internal void Dispose() { lock (this) { // Since we are explicitly calling Dispose(), sapiEventSource (RCW) will normally be alive. // If Dispose() is called from a finalizer this may not be the case so check for null. if (_sapiEventSourceReference != null) { ISpEventSource sapiEventSource = (ISpEventSource)_sapiEventSourceReference.Target; if (sapiEventSource != null) { // Stop listening to events from sapiEventSource. sapiEventSource.SetNotifySink(null); _notifySink = null; } } _sapiEventSourceReference = null; } }
internal void SendNotification(object ignored) { lock (this) { if (_sapiEventSourceReference != null) { ISpEventSource spEventSource = (ISpEventSource)_sapiEventSourceReference.Target; if (spEventSource != null) { List <SpeechEvent> list = new List <SpeechEvent>(); SpeechEvent item; while ((item = SpeechEvent.TryCreateSpeechEvent(spEventSource, _additionalSapiFeatures, _audioFormat)) != null) { list.Add(item); } _dispatcher.Post(list.ToArray()); } } } }
internal void SendNotification(object ignored) { lock (this) { // Call dispatchEventDelegate for each SAPI event currently queued. if (_sapiEventSourceReference != null) { ISpEventSource sapiEventSource = (ISpEventSource)_sapiEventSourceReference.Target; if (sapiEventSource != null) { List <SpeechEvent> speechEvents = new(); SpeechEvent speechEvent; while (null != (speechEvent = SpeechEvent.TryCreateSpeechEvent(sapiEventSource, _additionalSapiFeatures, _audioFormat))) { speechEvents.Add(speechEvent); } _dispatcher.Post(speechEvents.ToArray()); } } } }