Ejemplo n.º 1
0
        public void Start(AudioVideoFlow flow, LyncServer server)
        {
            _flow   = flow;
            _server = server;

            Recorder recorder = new Recorder();

            recorder.AttachFlow(_flow);
            WmaFileSink sink = new WmaFileSink("voice_input.wma");

            recorder.SetSink(sink);
            recorder.Start();

            var        wmafileReader = new WMAFileReader("voice_input.wma");
            WaveStream waveStream    = WaveFormatConversionStream.CreatePcmStream(wmafileReader);
            int        reader        = 0;

            byte[] buffer = new byte[4096];
            var    header = GetWaveHeader(waveStream.WaveFormat);

            _speech.SendMessage(new ArraySegment <byte>(header, 0, header.Length));

            while ((reader = waveStream.Read(buffer, 0, buffer.Length)) != 0)
            {
                AudioDataAvailable(new ArraySegment <byte>(buffer, 0, buffer.Length));
                Thread.Sleep(10);
            }
        }
Ejemplo n.º 2
0
        public void Run()
        {
            // Create AudioVideoFlow
            AudioVideoFlowHelper audioVideoFlowHelper = new AudioVideoFlowHelper();

            _audioVideoFlow = audioVideoFlowHelper.CreateAudioVideoFlow(
                null,
                audioVideoFlow_StateChanged);

            //Load readme file as the source
            Console.WriteLine();
            Console.Write("Please enter the destination wma file => ");
            string filename = Console.ReadLine();

            //setup a recorder to record the audio received from the remote side by attaching it to the AudioVideoFlow
            Recorder recorder = new Recorder();

            recorder.AttachFlow(_audioVideoFlow);

            //Subscribe to the recorder's state changed event
            recorder.StateChanged += new EventHandler <RecorderStateChangedEventArgs>(recorder_StateChanged);

            //Subscribe to voice activity changed event
            recorder.VoiceActivityChanged += new EventHandler <VoiceActivityChangedEventArgs>(recorder_VoiceActivityChanged);

            //Create the sink and give it to the recorder so the recorder knows where to record to
            WmaFileSink sink = new WmaFileSink(filename);

            recorder.SetSink(sink);

            //Start to record
            recorder.Start();
            Console.WriteLine("\r\nRecording for 10 seconds.");

            //Wait for 9 seconds to allow recording up to 10 seconds
            Thread.Sleep(10000);

            //Pauses recorder
            recorder.Pause();
            Console.WriteLine("\r\nPausing for 2 seconds.");

            //Wait 2 seconds
            Thread.Sleep(2000);

            //Resume recording from where we paused the recorder previously
            recorder.Start();
            Console.WriteLine("\r\nResume recording for 5 seconds.");

            //Wait 5 seconds
            Thread.Sleep(5000);

            //Stop the recording
            recorder.Stop();
            Console.WriteLine("\r\nRecording stopped.");

            //Detach the recorder from the AudioVideoFlow
            recorder.DetachFlow();

            // Shutdown the platform
            ShutdownPlatform();

            //Wait for shutdown to occur.
            _waitForShutdownEventCompleted.WaitOne();
        }