/// <summary> /// Initializes new instance of WitMic /// </summary> /// <param name="witPipedStream">Stream to write audio to</param> /// <param name="detectSpeechStop">Voice activity detection feature</param> public WitMic(WitPipedStream witPipedStream, bool detectSpeechStop) { this.witPipedStream = witPipedStream; this.detectSpeechStop = detectSpeechStop; microphone = Microphone.Default; if (microphone == null) { WitLog.Log("Did you enabled ID_CAP_MICROPHONE in WMAppManifest.xml?"); return; } witDetectTalking = new WitVadWrapper(8.0, 16000, 60); microphone.BufferDuration = TimeSpan.FromMilliseconds(100); speech = new byte[microphone.GetSampleSizeInBytes(microphone.BufferDuration)]; microphone.BufferReady += microphone_BufferReady; updateTimer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(1) }; updateTimer.Tick += (s, e) => { FrameworkDispatcher.Update(); }; }
/// <summary> /// Stops a voice recording /// </summary> public void StopRecording() { if (microphone != null && IsRecording) { microphone.Stop(); microphone.BufferReady -= microphone_BufferReady; updateTimer.Stop(); witDetectTalking.Clean(); witDetectTalking = null; witPipedStream.InputCompleted(); } }