1

how can i get list of avalible sound devices? I mean something as in that image.

enter image description here

I want it in combobox. I mean only:

  • Microphone
  • Stereo Mix
  • Line In
  • ..and more..

But must it really be that because the system changes the name of the device according to language localization system, and that's what I need.

For example, in my langueage is Microphone called Mikrofon and Stereo Mix = Směšovač stereo

enter image description here

AND I NEED GET THIS NAMES OF DEVICES, nothing other

Can make somebody example code?

  • In C++ it is [How to enumerate audio endpoint (IMMDevice) properties on your system](http://blogs.msdn.com/b/matthew_van_eerde/archive/2011/06/13/how-to-enumerate-audio-endpoint-immdevice-properties-on-your-system.aspx). It does more, but it starts with enumeration of devices themselves. – Roman R. Apr 29 '15 at 07:14
  • I have almost completed project in C# and I miss only this portion, it is possible in C# ? Thanks – John Majlstounn Apr 29 '15 at 07:16
  • 1
    possible duplicate of [How to enumerate audio out devices in c#](http://stackoverflow.com/questions/1525320/how-to-enumerate-audio-out-devices-in-c-sharp) – Abhishek Apr 29 '15 at 07:17
  • NO! I do not want information about the sound card but I need a list of equipment for the recording in a language that the user has set in their windows. – John Majlstounn Apr 29 '15 at 07:30

3 Answers3

3

This is do what I need..

    [DllImport("winmm.dll", SetLastError = true)]
    static extern uint waveInGetNumDevs();

    [DllImport("winmm.dll", SetLastError = true, CharSet = CharSet.Auto)]
    public static extern uint waveInGetDevCaps(uint hwo, ref WAVEOUTCAPS pwoc, uint cbwoc);

    [StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
    public struct WAVEOUTCAPS
    {
        public ushort wMid;
        public ushort wPid;
        public uint vDriverVersion;
        [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 64)]
        public string szPname;
        public uint dwFormats;
        public ushort wChannels;
        public ushort wReserved1;
        public uint dwSupport;
    }

    public static string[] GetSoundDevices()
    {
        uint devices = waveInGetNumDevs();
        string[] result = new string[devices];
        WAVEOUTCAPS caps = new WAVEOUTCAPS();
        using (StreamWriter sw = new StreamWriter("appdata/audio/name"))
        {
            for (uint i = 0; i < devices; i++)
            {
                waveInGetDevCaps(i, ref caps, (uint)Marshal.SizeOf(caps));
                result[i] = caps.szPname;
                sw.WriteLine(caps.szPname);
            }
            return result;
        }
    }

.. BUT each line is shortened and I can not write it all.

enter image description here

How to modify the code that listed the names of the whole?

Thanks!

2

use this it worked for me

using NAudio.CoreAudioApi;

MMDeviceEnumerator names = new MMDeviceEnumerator();
var devices = names.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active);            
foreach (var device in devices)
    MessageBox.Show(device.friendlyName);
Ahmad
  • 770
  • 9
  • 21
1

Following code should help you getting the list of audio devices,

ManagementObjectSearcher objSearcher = new ManagementObjectSearcher(
           "SELECT * FROM Win32_SoundDevice");

    ManagementObjectCollection objCollection = objSearcher.Get();

    foreach (ManagementObject obj in objCollection)
    {
        foreach (PropertyData property in obj.Properties)
        {
            Console.Out.WriteLine(String.Format("{0}:{1}", property.Name, property.Value));
        }
    }

Now, you can enumerate on the list using for-each.

Edited

Output will be something like this,

Availability:
Caption:USB Audio Device
ConfigManagerErrorCode:0
ConfigManagerUserConfig:False
CreationClassName:Win32_SoundDevice
Description:USB Audio Device
DeviceID:USB\VID_047F&PID_0CA1&MI_00\6&2C037688&0&0000
PNPDeviceID:USB\VID_047F&PID_0CA1&MI_00\6&2C037688&0&0000
PowerManagementCapabilities:
PowerManagementSupported:False
ProductName:USB Audio Device
Status:OK
StatusInfo:3
SystemCreationClassName:Win32_ComputerSystem
SystemName:
Availability:
Caption:Realtek AC'97 Audio for VIA (R) Audio Controller
ConfigManagerErrorCode:0
ConfigManagerUserConfig:False
CreationClassName:Win32_SoundDevice
Description:Realtek AC'97 Audio for VIA (R) Audio Controller
DeviceID:PCI\VEN_1106&DEV_3059&SUBSYS_09011558&REV_60\3&61AAA01&1&8D

Take Caption value from the list. It is simple text parsing problem ;)

Abhishek
  • 6,912
  • 14
  • 59
  • 85
  • Thnak you, but this isn't it. It show me many information about my sound card. I need simple list of capture devices, only names as in image (Microphone, Line In, Stereo Mix.......) – John Majlstounn Apr 29 '15 at 07:23
  • I want not names like USB Audio Devices or Realtek Hight Definition Audio, it are names of sound cards.. I need names of Inputs :'( thank you – John Majlstounn Apr 29 '15 at 07:46
  • http://stackoverflow.com/questions/2208722/how-to-get-friendly-device-name-from-dev-broadcast-deviceinterface-and-device-in should help you in getting user-friendly name :) – Abhishek Apr 29 '15 at 07:48
  • i added code from this topic to my program, but I can not get out string result (i mean that user-friendly names of inputs) .. ehm, yes, i am beginner, you can help me again? :) thanks – John Majlstounn Apr 29 '15 at 12:01
  • What are you getting as result? – Abhishek Apr 29 '15 at 12:24