예제 #1
0
        private void Form1_Load(object sender, EventArgs e)
        {
            Choices commands = new Choices();

            commands.Add(new string[] { "Coucou", "Salut", "mon nom", "ouvre fasmo", "Lance Phasmo", "mets les objets", "ajoute les objets", "partie privée", "Lance une partie privée", "arrête d'écouter", "Command", "Copie le code" });
            GrammarBuilder gBuilder = new GrammarBuilder();

            gBuilder.Culture = new System.Globalization.CultureInfo("fr-FR");
            gBuilder.Append(commands);
            Grammar grammar = new Grammar(gBuilder);

            recEngine.LoadGrammarAsync(grammar);
            recEngine.SetInputToDefaultAudioDevice();
            recEngine.SpeechRecognized += recEngine_SpeechRecognized;

            string screenWidth  = Screen.PrimaryScreen.Bounds.Width.ToString();
            string screenHeight = Screen.PrimaryScreen.Bounds.Height.ToString();

            label1.Text = "Resolution: " + screenWidth + " x " + screenHeight;

            var collection    = new AudioDeviceCollection(AudioDeviceCategory.Capture);
            var defaultDevice = collection.Default;

            foreach (var device in collection)
            {
                //Console.WriteLine(device.ToString());
                label2.Text = $"Micro: {defaultDevice}";
            }
        }
예제 #2
0
        public Capturer(params ICapturingOutput[] capturingOutputs)
        {
            FilterCapturers(capturingOutputs);

            videoCaptureDevices = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            audioCaptureDevices = new AudioDeviceCollection(AudioDeviceCategory.Capture);
        }
예제 #3
0
        public Recorder(Rectangle area, bool recordmicro, bool recordaudio, int framerate, int bitrate, string filepath, string filename)
        {
            _CaptureRegion       = new Rectangle(area.X, area.Y, area.Width, area.Height);
            _RecordingScreen     = true;
            _RecordingMicrophone = recordmicro;
            _RecordingAudio      = recordaudio;
            _FrameRate           = framerate;
            _BitRate             = bitrate;
            _FileName            = filename;
            _FilePath            = filepath;


            _CameraDevices       = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            _CurrentCameraDevice = GetCameraDevice(0);
            _CameraSource        = new VideoCaptureDevice(_CurrentCameraDevice.MonikerString);

            _ScreenSource = new ScreenCaptureStream(_CaptureRegion);

            _AudioDevices       = new AudioDeviceCollection(AudioDeviceCategory.Capture);
            _CurrenrAudioDevice = GetAudioDevice(0);

            _Writer            = new VideoFileWriter();
            _StartTime         = DateTime.MinValue;
            _ScreenTotalFrames = 0;
            _AudioTotalFrames  = 0;
        }
예제 #4
0
        public Encoder(EventHandler<NewFrameEventArgs> NewFrame, EventHandler<AudioSourceErrorEventArgs> AudioSourceError)
        {
            AudioDeviceCollection audioDevices = new AudioDeviceCollection(AudioDeviceCategory.Capture);
            AudioDeviceInfo INfo = null;
            foreach (var item in audioDevices)
            {
                INfo = item;
            }
            // Create capture device
            this.source = new AudioCaptureDevice(INfo.Guid)
            {
                // Listen on 22050 Hz
                DesiredFrameSize = FRAME_SIZE,
                SampleRate = SAMPLE_RATE,

                // We will be reading 16-bit PCM
                Format = SampleFormat.Format16Bit
            };


            // Wire up some events
            source.NewFrame += NewFrame;
            source.AudioSourceError += AudioSourceError;

            // Create buffer for wavechart control
            this.current = new float[source.DesiredFrameSize];

            // Create stream to store file
            this.stream = new MemoryStream();
            this.encoder = new WaveEncoder(stream);
        }
예제 #5
0
        public Encoder(EventHandler <NewFrameEventArgs> NewFrame, EventHandler <AudioSourceErrorEventArgs> AudioSourceError)
        {
            AudioDeviceCollection audioDevices = new AudioDeviceCollection(AudioDeviceCategory.Capture);
            AudioDeviceInfo       INfo         = null;

            foreach (var item in audioDevices)
            {
                INfo = item;
            }
            // Create capture device
            this.source = new AudioCaptureDevice(INfo.Guid)
            {
                // Listen on 22050 Hz
                DesiredFrameSize = FRAME_SIZE,
                SampleRate       = SAMPLE_RATE,

                // We will be reading 16-bit PCM
                Format = SampleFormat.Format16Bit
            };


            // Wire up some events
            source.NewFrame         += NewFrame;
            source.AudioSourceError += AudioSourceError;

            // Create buffer for wavechart control
            this.current = new float[source.DesiredFrameSize];

            // Create stream to store file
            this.stream  = new MemoryStream();
            this.encoder = new WaveEncoder(stream);
        }
예제 #6
0
        public void ListenForCommands(object sender, EventArgs e, bool forCalibration)
        {
            ListOfPowerSpectrum   = new List <double[]>();
            soundsDetectedIndexes = new List <int>();

            var audioDevices = new AudioDeviceCollection(AudioDeviceCategory.Capture).First();

            source = new AudioCaptureDevice(audioDevices)
            {
                // Capture at 22050 Hz
                DesiredFrameSize = 2048,
                SampleRate       = 22050
            };

            source.NewFrame         += source_NewFrame;
            source.AudioSourceError += source_AudioSourceError;



            // Start it!
            Console.WriteLine("Start");
            source.Start();

            if (forCalibration)
            {
                Thread.Sleep(TimeSpan.FromSeconds(10));
                Console.WriteLine("Stop");
                source.Stop();
            }
        }
예제 #7
0
        public Recorder()
        {
            _CaptureRegion       = new Rectangle(0, 0, 480, 360);
            _isRecording         = false;
            _isPausing           = false;
            _RecordingScreen     = false;
            _RecordingCamera     = false;
            _RecordingMicrophone = false;
            _RecordingAudio      = false;
            _FrameRate           = 60;
            _BitRate             = 1200 * 1000;
            _FileName            = "Video.avi";
            _FilePath            = "C:\\";

            _CameraDevices       = new FilterInfoCollection(FilterCategory.VideoInputDevice);
            _CurrentCameraDevice = GetCameraDevice(0);
            _CameraSource        = new VideoCaptureDevice(_CurrentCameraDevice.MonikerString);

            _ScreenSource = new ScreenCaptureStream(_CaptureRegion);

            _AudioDevices       = new AudioDeviceCollection(AudioDeviceCategory.Capture);
            _CurrenrAudioDevice = GetAudioDevice(0);

            _Writer            = new VideoFileWriter();
            _StartTime         = DateTime.MinValue;
            _ScreenTotalFrames = 0;
            _AudioTotalFrames  = 0;
        }
예제 #8
0
        /// <summary>
        /// get Index for list
        /// </summary>
        /// <param name="Guid">device id</param>
        /// <returns>Index from list</returns>
        public int getOutPut(string Guid)
        {
            var collection = new AudioDeviceCollection(AudioDeviceCategory.Output).ToList();

            collection.RemoveAt(0);

            return(collection.FindIndex(device => device.Guid.ToString() == Guid));
        }
예제 #9
0
        /// <summary>
        /// get device id
        /// </summary>
        /// <param name="deviceToPlayOn">Index from list</param>
        /// <returns>device id</returns>
        public string getOutPutGuid(int deviceToPlayOn)
        {
            var collection = new AudioDeviceCollection(AudioDeviceCategory.Output).ToList();

            collection.RemoveAt(0);

            return(collection[deviceToPlayOn].Guid.ToString());
        }
        private void initalizeAudioStuff()
        {
            try
            {
                AudioSource = new AudioCaptureDevice();
                AudioDeviceInfo info = null;
                var             adc  = new AudioDeviceCollection(AudioDeviceCategory.Capture);
                foreach (var ad in adc)
                {
                    string desc = ad.Description;
                    if (desc.IndexOf("Audio") > -1)
                    {
                        info = ad;
                    }
                }
                if (info == null)
                {
                    AudioSource = new AudioCaptureDevice();
                }
                else
                {
                    AudioSource = new AudioCaptureDevice(info);
                }

                //AudioCaptureDevice source = new AudioCaptureDevice();
                AudioSource.DesiredFrameSize = 4096;
                AudioSource.SampleRate       = 44100;
                //int sampleRate = 44100;
                //int sampleRate = 22050;

                AudioSource.NewFrame += AudioSource_NewFrame;
                // AudioSource.Format = SampleFormat.Format64BitIeeeFloat;
                AudioSource.AudioSourceError += AudioSource_AudioSourceError;
                // AudioSource.Start();
                int x = 1;
            }
            catch
            {
            }

            // Create buffer for wavechart control
            current = new float[AudioSource.DesiredFrameSize];

            // Create stream to store file
            stream  = new MemoryStream();
            encoder = new WaveEncoder(stream);

            frames  = 0;
            samples = 0;



            // Start
            AudioSource.Start();
        }
예제 #11
0
        public void enumerate_test()
        {
            var capture = new AudioDeviceCollection(AudioDeviceCategory.Capture);

            Assert.AreEqual(AudioDeviceCategory.Capture, capture.Category);
            Assert.IsNotNull(capture.Default);

            var output = new AudioDeviceCollection(AudioDeviceCategory.Output);

            Assert.AreEqual(AudioDeviceCategory.Output, output.Category);
            Assert.IsNotNull(output.Default);
        }
예제 #12
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            AudioDeviceCollection audioDeviceCollection = new AudioDeviceCollection(AudioDeviceCategory.Capture);

            foreach (AudioDeviceInfo current in audioDeviceCollection)
            {
                devicesListBox.Items.Add(current);
            }
            if (devicesListBox.Items.Count == 0)
            {
                devicesListBox.Items.Add("No local capture devices");
                devicesListBox.Enabled = false;
            }
            devicesListBox.SelectedIndex = 0;
        }
예제 #13
0
        private void Form1_Load(object sender, EventArgs e)
        {
            // Initialize Tray Icon
            trayIcon = new NotifyIcon()
            {
                Icon        = this.Icon,
                ContextMenu = new ContextMenu(new MenuItem[] {
                    new MenuItem("Show Application", TrawShowApplication),
                    new MenuItem("Exit", TrayExit)
                }),
                Visible = true
            };

            string comPort = AutodetectArduinoPort();

            if (comPort == null)
            {
                labelPortStatus.Text = "Serial Port Status: ARDUINO NOT FOUND";
            }
            else
            {
                labelPortStatus.Text = "Serial Port Status: OPEN on " + comPort;
                serialPort.PortName  = comPort;
                serialPort.Open();

                timeRemaining = minimumTimeBetweenUpdates;

                //Set up audio
                var audioDevices = new AudioDeviceCollection(AudioDeviceCategory.Capture);

                foreach (AudioDeviceInfo device in audioDevices)
                {
                    comboBoxMicrophoneSource.Items.Add(device);
                }

                if (comboBoxMicrophoneSource.Items.Count == 0)
                {
                    comboBoxMicrophoneSource.Items.Add("No local capture devices");
                    comboBoxMicrophoneSource.Enabled = false;
                }

                comboBoxMicrophoneSource.SelectedIndex = 0;

                groupBoxLightMode.Enabled  = true;
                groupBoxFanControl.Enabled = true;
            }
        }
예제 #14
0
        void MainFormLoad(object sender, EventArgs e)
        {
            // enumerate audio devices and add all devices to combo
            var audioDevices = new AudioDeviceCollection(AudioDeviceCategory.Capture);

            foreach (AudioDeviceInfo device in audioDevices)
            {
                comboBox1.Items.Add(device);
            }

            if (comboBox1.Items.Count == 0)
            {
                comboBox1.Items.Add("No local capture devices");
                comboBox1.Enabled = false;
            }

            comboBox1.SelectedIndex = 0;
        }
예제 #15
0
        // マイク、スピーカ情報の取得
        public void getAudioInfo()
        {
            try
            {
                audioDevices = new AudioDeviceCollection(AudioDeviceCategory.Capture);
                comboBox2.Items.Clear();

                //if (audioDevices.Count == 0)
                //    throw new ApplicationException();

                foreach (AudioDeviceInfo device in audioDevices)
                {
                    comboBox2.Items.Add(device);
                    comboBox2.SelectedIndex = 0;
                    AudioDeviceExist        = true;
                }
            }
            catch (ApplicationException)
            {
                AudioDeviceExist = false;
                comboBox2.Items.Add("No InputAudio Devices");
            }

            try
            {
                outputAudioDevices = new AudioDeviceCollection(AudioDeviceCategory.Output);
                comboBox5.Items.Clear();

                //if (audioDevices.Count == 0)
                //    throw new ApplicationException();

                foreach (AudioDeviceInfo device in outputAudioDevices)
                {
                    comboBox5.Items.Add(device);
                    comboBox5.SelectedIndex = 0;
                    OutputAudioDeviceExist  = true;
                }
            }
            catch (ApplicationException)
            {
                OutputAudioDeviceExist = false;
                comboBox5.Items.Add("No OutputAudio Devices");
            }
        }
예제 #16
0
		public static AudioDeviceCollection InputDevices()
		{
			AudioDeviceCollection c=new AudioDeviceCollection();
			for(int i=0;i<waveInGetNumDevs();i++)
			{
				WAVEINCAPSA a=new WAVEINCAPSA();
				waveInGetDevCapsA(i,ref a,System.Runtime.InteropServices.Marshal.SizeOf(typeof(WAVEINCAPSA)));
				AudioDevice b=new AudioDevice();
				b.dwFormats=a.dwFormats;
				b.szPname=a.szPname;
				b.wPid=a.wPid;
				b.wMid=a.wMid;
				b.vDriverVersion=a.vDriverVersion;
				b.wChannels=a.wChannels;
				b.wReserved1=a.wReserved1;
				c.Add(b);
			}
			return c;
		}
        private static void AddDeviceCommands(AudioDeviceManager manager, ContextMenuStrip strip, AudioDeviceKind kind, bool condition, string noDeviceText)
        {
            if (condition)
            {
                strip.AddSeparatorIfNeeded();

                AudioDeviceCollection devices = GetDevices(manager, kind);
                if (devices.Count == 0)
                {
                    strip.AddCommand(new DisabledCommand(noDeviceText));
                }
                else
                {
                    AddCommand(manager, strip, devices, AudioDeviceState.Active);
                    AddCommand(manager, strip, devices, AudioDeviceState.Unplugged);
                    AddCommand(manager, strip, devices, AudioDeviceState.Disabled);
                    AddCommand(manager, strip, devices, AudioDeviceState.NotPresent);
                }
            }
        }
예제 #18
0
        public static AudioDeviceCollection InputDevices()
        {
            AudioDeviceCollection c = new AudioDeviceCollection();

            for (int i = 0; i < waveInGetNumDevs(); i++)
            {
                WAVEINCAPSA a = new WAVEINCAPSA();
                waveInGetDevCapsA(i, ref a, System.Runtime.InteropServices.Marshal.SizeOf(typeof(WAVEINCAPSA)));
                AudioDevice b = new AudioDevice();
                b.dwFormats      = a.dwFormats;
                b.szPname        = a.szPname;
                b.wPid           = a.wPid;
                b.wMid           = a.wMid;
                b.vDriverVersion = a.vDriverVersion;
                b.wChannels      = a.wChannels;
                b.wReserved1     = a.wReserved1;
                c.Add(b);
            }
            return(c);
        }
예제 #19
0
        static void Main(string[] args)
        {
            List <Device>       videoCaptureDevices = new List <Device>();
            List <StudioDevice> audioOutputs        = new List <StudioDevice>();
            List <StudioDevice> audioInputs         = new List <StudioDevice>();

            DsDevice[] videoDevices = DirectShowLib.DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
            foreach (DsDevice dev in videoDevices)
            {
                string id = PrepareVideoId(dev);

                videoCaptureDevices.Add(new Device {
                    category = "video", name = dev.Name, path = dev.DevicePath, id = id
                });
            }

            // Load audio devices and set the correct selected ones
            var inputDevices = new AudioDeviceCollection(AudioDeviceCategory.Capture);

            audioInputs = inputDevices
                          .Where(IsSelectableDevice)
                          .Select(device =>
                                  new StudioDevice
            {
                Id   = $"{{0.0.1.00000000}}.{{{device.Guid}}}",
                Name = device.Description
            }).ToList();

            var outputDevices = new AudioDeviceCollection(AudioDeviceCategory.Output);

            audioOutputs = outputDevices
                           .Where(IsSelectableDevice)
                           .Select(device =>
                                   new StudioDevice
            {
                Id   = $"{{0.0.0.00000000}}.{{{device.Guid}}}",
                Name = device.Description
            }).ToList();

            generateJson(videoCaptureDevices, audioInputs, audioOutputs);
        }
예제 #20
0
        /// <summary>
        /// get a list of all device
        /// </summary>
        /// <returns>list device</returns>
        public List <deviceName> getOutPutList()
        {
            var collection = new AudioDeviceCollection(AudioDeviceCategory.Output);

            List <deviceName> deviceList = new List <deviceName>();

            bool first = true;

            foreach (var device in collection)
            {
                if (first)
                {
                    first = false;
                    continue;
                }


                deviceList.Add(new deviceName(device.Guid.ToString(), device.ToString()));
            }
            return(deviceList);
        }
예제 #21
0
        public void SetRecorder(Guid?guid = null)
        {
            Guid?deviceGUID = guid;
            var  capture    = new AudioDeviceCollection(AudioDeviceCategory.Capture);

            foreach (var d in capture)
            {
                //Console.WriteLine($"{d.Guid}: {d.Description}");
                if (d.Description.IndexOf("Audio") != -1)
                {
                    deviceGUID = d.Guid;
                    break;
                }
            }
            Guid _guid = deviceGUID ?? throw new Exception("Guid of capture devise is not set");

            _microphone            = new AudioCaptureDevice(_guid);
            _microphone.SampleRate = 44100;
            _microphone.Channels   = 2;
            _microphone.Format     = SampleFormat.Format32BitIeeeFloat;
            _microphone.NewFrame  += source_NewFrame;
        }
예제 #22
0
        private void init(IntPtr controlHandle, EventHandler<AudioOutputErrorEventArgs> AudioOutputError, EventHandler<PlayFrameEventArgs> FramePlayingStarted, EventHandler<NewFrameRequestedEventArgs> NewFrameRequested, EventHandler Stopped)
        {
            AudioDeviceCollection audioDevices = new AudioDeviceCollection(AudioDeviceCategory.Output);
            AudioDeviceInfo INfo = null;
            foreach (var item in audioDevices)
            {
                INfo = item;
            }
            // Here we can create the output audio device that will be playing the recording
            this.output = new AudioOutputDevice(INfo.Guid, controlHandle, decoder.SampleRate, decoder.Channels);

            // Wire up some events
            output.FramePlayingStarted += FramePlayingStarted;
            output.NewFrameRequested += NewFrameRequested;
            output.Stopped += Stopped;
            output.AudioOutputError += AudioOutputError;

            this.frames = this.decoder.Frames;
            this.samples = this.decoder.Samples;

            this.wholeSignal = getWholeSignal();
        }
예제 #23
0
        private void init(IntPtr controlHandle, EventHandler <AudioOutputErrorEventArgs> AudioOutputError, EventHandler <PlayFrameEventArgs> FramePlayingStarted, EventHandler <NewFrameRequestedEventArgs> NewFrameRequested, EventHandler Stopped)
        {
            AudioDeviceCollection audioDevices = new AudioDeviceCollection(AudioDeviceCategory.Output);
            AudioDeviceInfo       INfo         = null;

            foreach (var item in audioDevices)
            {
                INfo = item;
            }
            // Here we can create the output audio device that will be playing the recording
            this.output = new AudioOutputDevice(INfo.Guid, controlHandle, decoder.SampleRate, decoder.Channels);

            // Wire up some events
            output.FramePlayingStarted += FramePlayingStarted;
            output.NewFrameRequested   += NewFrameRequested;
            output.Stopped             += Stopped;
            output.AudioOutputError    += AudioOutputError;

            this.frames  = this.decoder.Frames;
            this.samples = this.decoder.Samples;

            this.wholeSignal = getWholeSignal();
        }
예제 #24
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // Configure the wave chart to display the FFT
            chart1.AddWaveform("fft", Color.Black, 1, false);

            // Enumerate audio devices and add all devices to combo
            AudioDeviceCollection audioDevices = new AudioDeviceCollection(AudioDeviceCategory.Capture);

            foreach (AudioDeviceInfo device in audioDevices)
            {
                comboBox1.Items.Add(device);
            }

            // Set a message if there is none
            if (comboBox1.Items.Count == 0)
            {
                comboBox1.Items.Add("No local capture devices");
                comboBox1.Enabled = false;
            }

            comboBox1.SelectedIndex = 0;
        }
        private static void AddCommand(AudioDeviceManager manager, ContextMenuStrip strip, AudioDeviceCollection devices, AudioDeviceState state)
        {
            foreach (AudioDevice device in devices.Where(d => d.State == state))
            {
                ToolStripDropDown dropDown = strip.AddNestedCommand(new AudioDeviceCommand(manager, device));

                if (device.State == AudioDeviceState.Active)
                {
                    dropDown.AddCommand(new SetAsDefaultMultimediaDeviceCommand(manager, device));
                    dropDown.AddCommand(new SetAsDefaultCommunicationDeviceCommand(manager, device));
                }
            }
        }
예제 #26
0
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            // Configure the wave chart to display the FFT
            chart1.AddWaveform("fft", Color.Black, 1, false);

            // Enumerate audio devices and add all devices to combo
            AudioDeviceCollection audioDevices = new AudioDeviceCollection(AudioDeviceCategory.Capture);

            foreach (AudioDeviceInfo device in audioDevices)
                comboBox1.Items.Add(device);

            // Set a message if there is none
            if (comboBox1.Items.Count == 0)
            {
                comboBox1.Items.Add("No local capture devices");
                comboBox1.Enabled = false;
            }

            comboBox1.SelectedIndex = 0;
        }
        public void ListenForCommands(object sender, EventArgs e, bool forCalibration)
        {
            ListOfPowerSpectrum = new List<double[]>();
            soundsDetectedIndexes = new List<int>();

            var audioDevices = new AudioDeviceCollection(AudioDeviceCategory.Capture).First();

            source = new AudioCaptureDevice(audioDevices)
            {
                // Capture at 22050 Hz
                DesiredFrameSize = 2048,
                SampleRate = 22050
            };

            source.NewFrame += source_NewFrame;
            source.AudioSourceError += source_AudioSourceError;

            // Start it!
            Console.WriteLine("Start");
            source.Start();

            if (forCalibration)
            {
                Thread.Sleep(TimeSpan.FromSeconds(10));
                Console.WriteLine("Stop");
                source.Stop();
            }
        }
예제 #28
0
        void MainFormLoad(object sender, EventArgs e)
        {
            // enumerate audio devices and add all devices to combo
            AudioDeviceCollection audioDevices = new AudioDeviceCollection(AudioDeviceCategory.Capture);

            foreach (AudioDeviceInfo device in audioDevices)
            {
                comboBox1.Items.Add(device);
            }

            if (comboBox1.Items.Count == 0)
            {
                comboBox1.Items.Add("No local capture devices");
                comboBox1.Enabled = false;
            }

            comboBox1.SelectedIndex = 0;
        }