Exemplo n.º 1
0
        /// <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();
            };
        }
Exemplo n.º 2
0
        /// <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();
            };
        }
Exemplo n.º 3
0
        /// <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();
            }
        }
Exemplo n.º 4
0
        /// <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();
            }
        }