How to list audio card IDs from terminal

I am developing a script which deals with sound recording.

As user potentially can have multiple sound cards attached, I would like to give him/her a chance to select desired one. The software I use for actual recording asks for numeric "Device ID".

Is there any way to retreive list of Device IDs along with soundcards' names from command line (terminal)?


Solution 1:

system_profiler is the tool in mac OS to show hw or sw configuraion.

Get the datatye you want to look for using --listDataTypes.

$ system_profiler -listDataTypes | grep Audio
SPAudioDataType

Then fire the command,

$ system_profiler SPAudioDataType
Audio:

    Intel High Definition Audio:

      Audio ID: 128

        Headphone:

          Connection: Combination Output

        Speaker:

          Connection: Internal

        External Microphone / iPhone Headset:

          Connection: Combination Output

        Internal Microphone:

          Connection: Internal

        S/PDIF Optical Digital Audio Output:

          Connection: Combination Output

        HDMI / DisplayPort Output:

          Connection: Display

    Devices:

        Built-in Microphone:

          Default Input Device: Yes
          Input Channels: 2
          Manufacturer: Apple Inc.
          Current SampleRate: 44100
          Transport: Built-in

        Built-in Output:

          Default Output Device: Yes
          Default System Output Device: Yes
          Manufacturer: Apple Inc.
          Output Channels: 2
          Current SampleRate: 44100
          Transport: Built-in

Solution 2:

I have found out that typing system_profiler SPAudioDataType -xml does the job and lists all necessary information. It is solved :)