public static void Stop(SpeechHelper.SpeechToTextCallbackDelegate del)
        {
            // trace the operation
            TraceHelper.AddMessage("Stopping Speech");

            // save the delegate passed in
            speechToTextDelegate = del;

            // stop recording and start recognizing
            _recognizer.stopRecording();

            // update the speech state
            speechStateDelegate.DynamicInvoke(SpeechHelper.SpeechState.Recognizing, "Stopped recording");
        }
        public static void Stop(SpeechHelper.SpeechToTextCallbackDelegate del)
        {
            // get the last chunk of speech
            int len = mic.GetData(speechBuffer);

            // stop listening
            mic.Stop();

            // remove the mic eventhandler
            mic.BufferReady            -= MicBufferReady;
            initializedBufferReadyEvent = false;

            // trace the operation
            TraceHelper.AddMessage(String.Format("Final Frame: {0} bytes of speech", len));

            // create a properly sized copy of the last buffer
            byte[] speechChunk = new byte[len];
            Array.Copy(speechBuffer, speechChunk, len);

            // add the last speech buffer to the folder
            speechBufferList.Add(speechChunk);

            // if the encode flag is set, encode the chunk before sending it
            if (encode)
            {
                // do this on a background thread because it is CPU-intensive
                ThreadPool.QueueUserWorkItem(delegate
                {
                    // create a new mutex object for this frame
                    AutoResetEvent bufferMutex = new AutoResetEvent(false);
                    bufferMutexList.Add(bufferMutex);

                    // encode the frame
                    TraceHelper.AddMessage(String.Format("Final Frame: About to encode speech"));
                    byte[] encodedBuf = EncodeSpeech(speechChunk, speechChunk.Length);
                    TraceHelper.AddMessage(String.Format("Final Frame: Encoded down to {0} bytes", encodedBuf.Length));

                    // wait until the previous frame has been sent
                    int frameIndex = bufferMutexList.Count - 1;
                    if (frameIndex > 0)
                    {
                        bufferMutexList[frameIndex - 1].WaitOne();
                    }

                    // send the last frame and retrieve the response
                    TraceHelper.AddMessage(String.Format("Sending Final Frame: {0} bytes", encodedBuf.Length));
                    NetworkHelper.EndSpeech(encodedBuf, encodedBuf.Length, del, new NetworkDelegate(NetworkCallback));

                    // repeat the sentence back to the user
                    PlaybackSpeech();
                });
            }
            else
            {
                // send the operation immediately
                TraceHelper.AddMessage(String.Format("Sending Final Frame: {0} bytes", speechChunk.Length));
                NetworkHelper.EndSpeech(speechChunk, speechChunk.Length, del, new NetworkDelegate(NetworkCallback));

                // play back the speech immediately
                PlaybackSpeech();
            }
        }