/// <summary> /// Get audio devices list. /// </summary> /// <returns></returns> private IList <MMDevice> GetRecorders() { var deviceEnumerator = new MMDeviceEnumerator(); var devices = deviceEnumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active).ToList(); return(devices); }
private void LoadAudioDevices() { List <Tuple <string, string> > audioDevices = new List <Tuple <string, string> >(); audioDevices.Add(new Tuple <string, string>("Default", "")); try { MMDeviceEnumerator sndDevEnum = new MMDeviceEnumerator(); MMDeviceCollection audioCollection = sndDevEnum.EnumerateAudioEndPoints(EDataFlow.eRender, EDeviceState.DEVICE_STATEMASK_ALL); // Try to add each audio endpoint to our collection for (int i = 0; i < audioCollection.Count; ++i) { MMDevice device = audioCollection[i]; audioDevices.Add(new Tuple <string, string>(device.FriendlyName, device.ID)); } } catch (Exception) { } // Setup the display cmbAudio.Items.Clear(); cmbAudio.DisplayMember = "Item1"; cmbAudio.ValueMember = "Item2"; cmbAudio.DataSource = audioDevices; cmbAudio.SelectedValue = Properties.Settings.Default.AudioDevice; }
private static IEnumerable <string> GetWasapiOutputDevices() { MMDeviceEnumerator em = new MMDeviceEnumerator(); var something = em.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active); return(something.Select(x => x.FriendlyName)); }
/// <summary> /// Gets WASAPI Audio device. /// </summary> /// <param name="dataFlow">Audio data flow.</param> /// <param name="deviceRole">Audio device role.</param> /// <returns>Audio device list.</returns> private static AudioDevice[] GetWASAPIAudioDevices(AudioDataFlow dataFlow, AudioDeviceRole deviceRole = AudioDeviceRole.Multimedia) { var devices = new List <AudioDevice>(); var mmde = new MMDeviceEnumerator(); var role = deviceRole switch { AudioDeviceRole.Console => Role.Console, AudioDeviceRole.Multimedia => Role.Multimedia, AudioDeviceRole.Communications => Role.Communications, _ => Role.Multimedia, }; if (dataFlow.HasFlag(AudioDataFlow.Render)) { try { var device = mmde.GetDefaultAudioEndpoint(NAudio.CoreAudioApi.DataFlow.Render, role); devices.Add(GetAudioDeviceFromMMDevice(device, AudioDataFlow.Render)); } catch (Exception) { } foreach (var item in mmde.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Render, DeviceState.Active)) { devices.Add(GetAudioDeviceFromMMDevice(item, AudioDataFlow.Render)); } } return(devices.ToArray()); }
public String[] SearchDevices() { micDevices = new List <MMDevice>(); List <String> device_names = new List <String>(); MMDeviceEnumerator DevEnum = new MMDeviceEnumerator(); MMDeviceCollection devices = DevEnum.EnumerateAudioEndPoints(EDataFlow.eCapture, EDeviceState.DEVICE_STATE_ACTIVE); //tbMaster.Value = (int)(device.AudioEndpointVolume.MasterVolumeLevelScalar * 100); //device.AudioEndpointVolume.OnVolumeNotification += new AudioEndpointVolumeNotificationDelegate(AudioEndpointVolume_OnVolumeNotification); for (int i = 0; i < devices.Count; i++) { MMDevice deviceAt = devices[i]; if (deviceAt.FriendlyName.ToLower() == "microphone") { this.micDevices.Add(deviceAt); device_names.Add(deviceAt.ID); } } //if (this.micDevice == null) // throw new InvalidOperationException("Microphone not found by MicMute Library!"); return(device_names.ToArray()); }
/// <summary> /// Get the playback device in the set state /// </summary> /// <returns></returns> public MMDeviceCollection GetPlaybackDevices() { using (var enumerator = new MMDeviceEnumerator()) { return(enumerator.EnumerateAudioEndPoints(DataFlow.Render, _state)); } }
private void PopulateDevices() { var enumerator = new MMDeviceEnumerator(); DeviceBox.ItemsSource = enumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active); DeviceBox.SelectedIndex = 0; }
private List <AudioSession> GetSessions() { List <AudioSession> controls = new List <AudioSession>(); MMDeviceEnumerator deviceEnumerator = new MMDeviceEnumerator(); MMDeviceCollection deviceCollection = deviceEnumerator.EnumerateAudioEndPoints(EDataFlow.eRender, EDeviceState.DEVICE_STATE_ACTIVE); string devName; for (int i = 0; i < deviceCollection.Count; i++) { MMDevice device = deviceCollection[i]; devName = device.FriendlyName; for (int j = 0; j < device.AudioSessionManager.Sessions.Count; j++) { AudioSessionControl session = device.AudioSessionManager.Sessions[j]; Process p; try { p = Process.GetProcessById((int)session.ProcessID); } catch { p = Process.GetProcesses()[0]; } if (p.ProcessName == _processName) { controls.Add(new AudioSession(session, devName)); } } } return(controls); }
/// <summary> /// /// </summary> /// <param name="stateInfo"></param> private void Initialize(object stateInfo) { _stopping = false; bool success = false; try { _deviceEnumerator.RegisterEndpointNotificationCallback(this); success = true; } catch { } if (!success) { _deviceEnumerator = new MMDeviceEnumerator(); _deviceEnumerator.RegisterEndpointNotificationCallback(this); } foreach (var device in _deviceEnumerator.EnumerateAudioEndPoints(DataFlow.All, DeviceState.Active)) { OnDeviceAdded(device); } foreach (var device in _devices.Values) { if (device.IsDefault) { OnDefaultDeviceChanged(device); } } _synchronizationContext.Post(o => ServiceStarted?.Invoke(this), null); }
void makeLayout() { // OUTPUT SELECT outputSelect = new ComboBox(); outputSelect.Location = new Point(5, 5); outputSelect.Size = new Size(300, 20); outputSelect.SelectedIndexChanged += initAudio; this.Controls.Add(outputSelect); // GONEOMETER goniometer = new Goniometer(); goniometer.Location = new Point(5, 30); goniometer.Size = new Size(400, 400); goniometer.Font = font; this.Controls.Add(goniometer); // QPPM qppm = new QPPM(); qppm.Location = new Point(410, 30); qppm.Size = new Size(100, 400); qppm.Font = font; this.Controls.Add(qppm); // CORRELATION METER correlation = new Correlation(); correlation.Location = new Point(5, 435); correlation.Size = new Size(505, 35); correlation.Font = font; this.Controls.Add(correlation); // DEBUG LABEL lblDebug = new Label(); lblDebug.Location = new Point(10, 40); lblDebug.Size = new Size(200, 20); lblDebug.Font = font; this.Controls.Add(lblDebug); // GET AUDIO OUTPUTS if (outputs.Count > 0) { outputs.Clear(); } MMDeviceEnumerator enumerator = new MMDeviceEnumerator(); int i = 0; foreach (MMDevice wasapi in enumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active)) { Console.WriteLine($"{wasapi.ID} {wasapi.DataFlow} {wasapi.FriendlyName} {wasapi.DeviceFriendlyName} {wasapi.State}"); outputs.Add(i, wasapi); outputSelect.Items.Add(wasapi.FriendlyName); i++; } if (outputs.Count > 0) { outputSelect.SelectedIndex = 0; } }
public static List <MMDevice> GetRenderDevices() { var deviceEnum = new MMDeviceEnumerator(); var devices = deviceEnum.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active).ToList(); return(devices); }
/// <summary> /// Populates the combo boxe with the input devices (mic, etc.) /// </summary> private void populateInputDevices() { MMDeviceEnumerator deviceEnum = new MMDeviceEnumerator(); MMDeviceCollection deviceCol = deviceEnum.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active); Collection <MMDevice> devices = new Collection <MMDevice>(); foreach (MMDevice device in deviceCol) { devices.Add(device); } //Give each item in the list of devices a name and a value. Add it to the combobox. foreach (var item in devices) { ComboboxItem cbItem = new ComboboxItem(); string productName = item.FriendlyName; int index = item.FriendlyName.IndexOf("("); if (index > 0) { productName = productName.Substring(0, index); } cbItem.Text = productName; cbItem.Value = item; cbInputDevices.Items.Add(cbItem); } }
private MMDevice GetDevice(AppSettings.Capture.Device device) { if (string.IsNullOrWhiteSpace(device.Name)) { _logger.LogWarning("Device configuration missing a name. This will be ignored."); return(null); } var dataFlow = "Output".Equals(device.Direction, StringComparison.OrdinalIgnoreCase) ? DataFlow.Render : DataFlow.Capture; if ("default".Equals(device.Name, StringComparison.OrdinalIgnoreCase)) { return(_deviceEnumerator.GetDefaultAudioEndpoint(dataFlow, Role.Console)); } var mmDevice = _deviceEnumerator .EnumerateAudioEndPoints(dataFlow, DeviceState.Active) .FirstOrDefault(d => d.FriendlyName?.IndexOf(device.Name, StringComparison.OrdinalIgnoreCase) >= 0); if (mmDevice is null) { _logger.LogWarning($"Device name '{device.Name}' did not match any devices. This will be ignored."); } return(mmDevice); }
private void btnConnect_Click(object sender, EventArgs e) { try { // Initialize client with server ip and port and connect tcpServer = new TcpClient(); tcpServer.Connect(IPAddress.Parse(txtIpAddress.Text), 1986); blConnected = true; btnDisconnect.Visible = true; btnConnect.Visible = false; strClientName = txtClientName.Text.ToString(); // Output server stream to send data to cient swClientSender = new StreamWriter(tcpServer.GetStream()); swClientSender.WriteLine(strClientName); swClientSender.Flush(); // Start a new thread to continuously receive messages from server trdReceiveMessaging = new Thread(new ThreadStart(ReceiveMessage)); trdReceiveMessaging.Start(); // Retreive all the available microphone and audio sensors var dmEnumerator = new MMDeviceEnumerator(); var dmDevice = dmEnumerator.EnumerateAudioEndPoints(DataFlow.All, DeviceState.Active); cbxAudioSource.Items.AddRange(dmDevice.ToArray()); // Update the windows form log after starting the connection txtLog.AppendText("Waiting to connect...\r\n"); } catch { } }
private void FishBotForm1_Load(object sender, EventArgs e) { MMDeviceEnumerator enumerator = new MMDeviceEnumerator(); var devices = enumerator.EnumerateAudioEndPoints(DataFlow.All, DeviceState.Active); processList.Items.AddRange(devices.ToArray()); }
public List <string> GetAudioDevicesInput() { var deviceEnumerator = new MMDeviceEnumerator(); var fullDeviceNames = deviceEnumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active).Select(x => x.FriendlyName); return(new List <string>(fullDeviceNames)); }
public static WaveOutDevice[] GetDevices() { MMDeviceEnumerator enumerator = new MMDeviceEnumerator(); var devices = new WaveOutDevice[WaveOut.DeviceCount]; for (int i = 0; i < devices.Length; ++i) { // MSDN: // If the value specified by the uDeviceID parameter is a device identifier, // it can vary from zero to one less than the number of devices present. devices[i] = new WaveOutDevice(i); foreach (MMDevice device in enumerator.EnumerateAudioEndPoints(DataFlow.All, DeviceState.All)) { try { if (device.FriendlyName.StartsWith(devices[i].Capabilities.ProductName)) { devices[i].ProductName = device.FriendlyName; break; } } catch (COMException ex) { Debug.WriteLine(ex); } } } return(devices); }
public AudioRecordForm(string recordingFolder) { outputFolder = recordingFolder; Directory.CreateDirectory(outputFolder); InitializeComponent(); Disposed += OnRecordingPanelDisposed; inputDevices = deviceEnum.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active); if (inputDevices.Count < 1) { MessageBox.Show($"There are no Audio Input devices available!", "Delete", MessageBoxButtons.OK, MessageBoxIcon.Warning); this.Close(); } inputDevice = inputDevices[0]; buttonStartRecording.Enabled = false; buttonStopRecording.Enabled = false; buttonPlay.Enabled = false; LoadFiles(outputFolder); comboBoxVoiceSelector.DataSource = inputDevices.ToList(); comboBoxVoiceSelector.DisplayMember = "FriendlyName"; comboBoxVoiceSelector.SelectedIndex = 0; }
public override List <Device> ListDevices() { var devices = new List <Device> { new Device { ID = null, Name = strings.deviceDefault, } }; using (var deviceEnumerator = new MMDeviceEnumerator()) { foreach (var device in deviceEnumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active)) { devices.Add(new Device { ID = device.ID, Name = device.FriendlyName, }); } } return(devices); }
private void GetAudioOutputs() { if (outputs.Count > 0) { outputs.Clear(); } MMDeviceEnumerator enumerator = new MMDeviceEnumerator(); int i = 0; foreach (MMDevice wasapi in enumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active)) { Logger.WriteLine($"{wasapi.ID} {wasapi.DataFlow} {wasapi.FriendlyName} {wasapi.DeviceFriendlyName} {wasapi.State}"); outputs.Add(i, wasapi); audioOutputSelector.Items.Add(wasapi.FriendlyName); i++; } if (outputs.Count > outputDevice) { audioOutputSelector.SelectedIndex = outputDevice; } else if (outputs.Count > 0) { audioOutputSelector.SelectedIndex = 0; } }
public CoreAudioMicMute() { MMDeviceEnumerator DevEnum = new MMDeviceEnumerator(); MMDeviceCollection devices = DevEnum.EnumerateAudioEndPoints(EDataFlow.eCapture, EDeviceState.DEVICE_STATE_ACTIVE); //tbMaster.Value = (int)(device.AudioEndpointVolume.MasterVolumeLevelScalar * 100); //device.AudioEndpointVolume.OnVolumeNotification += new AudioEndpointVolumeNotificationDelegate(AudioEndpointVolume_OnVolumeNotification); for (int i = 0; i < devices.Count; i++) { MMDevice deviceAt = devices[i]; //deviceAt.State if (deviceAt.FriendlyName.ToLower() == "microphone") { this.micDevices.Add(deviceAt); } } if (this.micDevices.Count == 0) { throw new InvalidOperationException("Microphone not found by MicMute Library!"); } }
/// <summary> /// Get the recording device in the set state /// </summary> /// <returns></returns> public MMDeviceCollection GetRecordingDevices() { using (var enumerator = new MMDeviceEnumerator()) { return(enumerator.EnumerateAudioEndPoints(DataFlow.Capture, _state)); } }
private void Audio_Load(object sender, EventArgs e) { capture.DataAvailable += waveIn_DataAvailable; targetPanel = panelFrom; MMDeviceEnumerator enumerator = new MMDeviceEnumerator(); MMDeviceCollection audioDevices = enumerator.EnumerateAudioEndPoints(DataFlow.All, DeviceState.Active); devices.Items.AddRange(audioDevices.ToArray()); devices.SelectedItem = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); targetDevice = devices.SelectedItem as MMDevice; chart1.ChartAreas[0].AxisX.Minimum = 0; chart1.ChartAreas[0].AxisX.Maximum = Mathf.Clamp(1 / multiplier, 0.1f, 1); chart1.ChartAreas[0].AxisY.Minimum = 0; chart1.ChartAreas[0].AxisY.Maximum = 1; chart1.ChartAreas[0].AxisX.LabelStyle.ForeColor = Color.Black; chart1.ChartAreas[0].AxisY.LabelStyle.ForeColor = Color.Black; chart1.ChartAreas[0].AxisX.MajorGrid.Enabled = false; chart1.ChartAreas[0].AxisX.MinorGrid.Enabled = false; chart1.ChartAreas[0].AxisY.MajorGrid.Enabled = false; chart1.ChartAreas[0].AxisY.MinorGrid.Enabled = false; chart1.ChartAreas[0].AxisX.MajorTickMark.Enabled = false; chart1.ChartAreas[0].AxisY.MajorTickMark.Enabled = false; chart1.ChartAreas[0].AxisX.MinorTickMark.Enabled = false; chart1.ChartAreas[0].AxisY.MinorTickMark.Enabled = false; chart1.ChartAreas[0].AxisX.LabelStyle.Interval = 0.2; chart1.ChartAreas[0].AxisY.LabelStyle.Interval = 0.2; chart1.ChartAreas[0].BackColor = Color.White; chart1.Series[0].Color = Color.Black; chart1.Series[0]["PieLabelStyle"] = "Disabled"; }
public static MMDevice MapWasapiInputDevice(string inputDevice) { MMDeviceEnumerator em = new MMDeviceEnumerator(); var something = em.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active); return(something.First(x => x.FriendlyName == inputDevice)); }
/// <summary> /// Get names of audio devices. /// </summary> /// <returns>An array containing names of audio devices.</returns> public static string[] GetDeviceNames() { var enumerator = new MMDeviceEnumerator(); var devices = enumerator.EnumerateAudioEndPoints(DataFlow.All, DeviceState.Active); return(devices.Select(x => x.FriendlyName).ToArray()); }
public void RefreshDevices() { var enumerator = new MMDeviceEnumerator(); InputDevicesComboBox.Items.Clear(); OutputDevicesComboBox.Items.Clear(); int maxWidth = 0; foreach (var device in enumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active)) { maxWidth = Math.Max(maxWidth, TextRenderer.MeasureText(device.DeviceFriendlyName, InputDevicesComboBox.Font).Width); InputDevicesComboBox.Items.Add(device); OutputDevicesComboBox.Items.Add(device); } Console.WriteLine("Max width = {0}", maxWidth); InputDevicesComboBox.DropDownWidth = maxWidth * 2; OutputDevicesComboBox.DropDownWidth = maxWidth * 2; var defaultDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia); var deviceEnum = InputDevicesComboBox.Items.GetEnumerator(); for (int i = 0; i < InputDevicesComboBox.Items.Count; i++) { deviceEnum.MoveNext(); if (((MMDevice)deviceEnum.Current).DeviceFriendlyName == defaultDevice.DeviceFriendlyName) { InputDevicesComboBox.SelectedIndex = i; break; } } }
private void FrmPrincipal_Load(object sender, EventArgs e) { Boolean validaMicrofone = false; MMDeviceEnumerator listDevice = new MMDeviceEnumerator(); var devices = listDevice.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active); foreach (MMDevice device in devices) { if (device.State != DeviceState.NotPresent) { validaMicrofone = true; } } if (!validaMicrofone) { MessageBox.Show("Seu computador não atende as especificações do sistema!\r\n Microfone não localizado!"); this.Close(); } if (!Directory.Exists(@"C:\PEDGRAVACAO\")) { Directory.CreateDirectory(@"C:\PEDGRAVACAO\"); } if (!Directory.Exists(@"C:\PEDGRAVACAO\Audios")) { Directory.CreateDirectory(@"C:\PEDGRAVACAO\Audios"); } if (!Directory.Exists(@"C:\PEDGRAVACAO\Documentos")) { Directory.CreateDirectory(@"C:\PEDGRAVACAO\Documentos"); } ; }
/// <summary> /// Get list of playback devices. /// </summary> /// <returns></returns> private IList <MMDevice> GetPlaybackDevices() { var deviceEnumerator = new MMDeviceEnumerator(); var playbackDevices = deviceEnumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.Active).ToList(); return(playbackDevices); }
static void Main(string[] args) { string match = string.Empty; if (args.Length > 0) { match = args[0].ToLower(); } MMDeviceEnumerator DevEnum = new MMDeviceEnumerator(); MMDeviceCollection devices = DevEnum.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active); foreach (MMDevice deviceAt in devices) { if (string.IsNullOrWhiteSpace(match)) { Console.WriteLine(deviceAt.FriendlyName); continue; } string deviceName = deviceAt.FriendlyName.ToLower(); if (!deviceName.Contains(match) && !deviceName.Equals("all")) { continue; } deviceAt.AudioEndpointVolume.Mute = !deviceAt.AudioEndpointVolume.Mute; } }
public static MMDevice FindDeviceByData(string id = null, string friendlyName = null) { MMDeviceEnumerator enumerator = new MMDeviceEnumerator(); foreach (MMDevice device in enumerator.EnumerateAudioEndPoints(DataFlow.Render, DeviceState.All)) { try { if (device.State == DeviceState.Active) { if (device.ID == id) { return(device); } else if (device.FriendlyName == friendlyName) { return(device); } } } catch { } } return(null); }
public ExclusiveAudioInput() { _devices = new MMDeviceEnumerator(); MMDevice dev = null; if (_devices != null) { foreach (MMDevice device in _devices.EnumerateAudioEndPoints(EDataFlow.eCapture, DeviceState.DEVICE_STATE_ACTIVE)) { dev = device; break; } } if (dev != null) { SelectDevice(dev.Id); } }