From 67f5e6cc53407ed0a2c2ac2ef86dfc2c8ccc782e Mon Sep 17 00:00:00 2001 From: Sebastian Hildebrandt Date: Mon, 25 Jan 2021 21:39:25 +0100 Subject: [PATCH] audio type --- README.md | 2 ++ docs/audio.html | 22 +++++++++++++++++++++- lib/audio.js | 25 +++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 973135e..522683e 100644 --- a/README.md +++ b/README.md @@ -497,6 +497,8 @@ I also created a nice little command line tool called [mmon][mmon-github-url] (m | | [0].revision | X | | | | | revision | | | [0].driver | X | | | | | driver | | | [0].default | | | X | X | | is default | +| | [0].channel | X | | X | | | channel e.g. USB, HDMI, ... | +| | [0].type | X | | X | X | | type e.g. Speaker | | | [0].in | | | X | X | | is input channel | | | [0].out | | | X | X | | is output channel | | | [0].interfaceType | X | | X | X | | interface type (PCIe, USB, HDMI, ...) | diff --git a/docs/audio.html b/docs/audio.html index d3b91ee..0d47432 100644 --- a/docs/audio.html +++ b/docs/audio.html @@ -136,6 +136,26 @@ is default + + + [0].channel + X + + X + + + channel e.g. HDMI, USB, ... + + + + [0].type + X + + X + X + + type e.g. Speaker + [0].in @@ -263,4 +283,4 @@ si.audio().then(data => console.log(data)); - + \ No newline at end of file diff --git a/lib/audio.js b/lib/audio.js index cbc1157..610199b 100644 --- a/lib/audio.js +++ b/lib/audio.js @@ -28,6 +28,27 @@ const _openbsd = (_platform === 'openbsd'); const _netbsd = (_platform === 'netbsd'); const _sunos = (_platform === 'sunos'); +function parseAudioType(str, input, output) { + let result = ''; + + if (str.indexOf('speak') >= 0) { result = 'Speaker'; } + if (str.indexOf('laut') >= 0) { result = 'Speaker'; } + if (str.indexOf('loud') >= 0) { result = 'Speaker'; } + if (str.indexOf('head') >= 0) { result = 'Headset'; } + if (str.indexOf('mic') >= 0) { result = 'Microphone'; } + if (str.indexOf('mikr') >= 0) { result = 'Microphone'; } + if (str.indexOf('phone') >= 0) { result = 'Phone'; } + if (str.indexOf('controll') >= 0) { result = 'Controller'; } + + if (!result && output) { + result = 'Speaker'; + } else if (!result && input) { + result = 'Microphone'; + } + return result; +} + + function getLinuxAudioPci() { let cmd = 'lspci -v 2>/dev/null'; let result = []; @@ -62,6 +83,7 @@ function parseLinuxAudioPciMM(lines, audioPCI) { result.driver = pciMatch && pciMatch.length === 1 && pciMatch[0].driver ? pciMatch[0].driver : ''; result.default = null; result.channel = 'PCIe'; + result.type = parseAudioType(result.name, null, null); result.in = null; result.out = null; result.status = 'online'; @@ -93,6 +115,7 @@ function parseDarwinAudio(audioObject, id) { result.driver = null; result.default = !!(audioObject.coreaudio_default_audio_input_device || '') || !!(audioObject.coreaudio_default_audio_output_device || ''); result.channel = parseDarwinChannel(channelStr); + result.type = parseAudioType(result.name, !!(audioObject.coreaudio_device_input || ''), !!(audioObject.coreaudio_device_output || '')); result.in = !!(audioObject.coreaudio_device_input || ''); result.out = !!(audioObject.coreaudio_device_output || ''); result.status = 'online'; @@ -111,6 +134,8 @@ function parseWindowsAudio(lines) { result.revision = null; result.driver = null; result.default = null; + result.channel = null; + result.type = parseAudioType(result.name, null, null); result.in = null; result.out = null; result.status = status;