truehear-audio-library-node 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +220 -0
- package/binding.gyp +45 -0
- package/dist/domain/audio-device.types.d.ts +240 -0
- package/dist/domain/audio-device.types.d.ts.map +1 -0
- package/dist/domain/audio-device.types.js +13 -0
- package/dist/domain/audio-device.types.js.map +1 -0
- package/dist/index.d.ts +123 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +154 -0
- package/dist/index.js.map +1 -0
- package/include/audio_device_types.h +169 -0
- package/include/ipolicy_config.h +420 -0
- package/include/mmdevice_guids.h +9 -0
- package/include/truehear_audio.h +348 -0
- package/package.json +85 -0
- package/prebuilds/win32-x64/truehear_audio_native.node +0 -0
- package/src/addon.c +612 -0
- package/src/mmdevice_guids.c +8 -0
- package/src/policy_config_guids.c +26 -0
- package/src/truehear_audio_win.c +888 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
/**
|
|
5
|
+
* Create a CommonJS-compatible `require` function inside an ESM module.
|
|
6
|
+
*
|
|
7
|
+
* @remarks
|
|
8
|
+
* This package is authored as ESM (`"type": "module"`), but the native addon
|
|
9
|
+
* loader expects `require()` to resolve the compiled `.node` binary.
|
|
10
|
+
*
|
|
11
|
+
* `createRequire(import.meta.url)` gives us a local `require` function that is
|
|
12
|
+
* safe to use inside this module.
|
|
13
|
+
*/
|
|
14
|
+
const require = createRequire(import.meta.url);
|
|
15
|
+
/**
|
|
16
|
+
* Absolute path to this module file.
|
|
17
|
+
*
|
|
18
|
+
* This is the ESM equivalent of CommonJS `__filename`.
|
|
19
|
+
*/
|
|
20
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
21
|
+
/**
|
|
22
|
+
* Absolute directory path for this module.
|
|
23
|
+
*
|
|
24
|
+
* This is the ESM equivalent of CommonJS `__dirname`.
|
|
25
|
+
*/
|
|
26
|
+
const __dirname = dirname(__filename);
|
|
27
|
+
/**
|
|
28
|
+
* Load the native addon binding from the project root.
|
|
29
|
+
*
|
|
30
|
+
* @remarks
|
|
31
|
+
* At runtime, this file is emitted into the `dist/` directory, so `__dirname`
|
|
32
|
+
* points to `dist/`. The native loader must be pointed at the project root so
|
|
33
|
+
* it can discover:
|
|
34
|
+
*
|
|
35
|
+
* - local development builds in `build/Release`
|
|
36
|
+
* - prebuilt native binaries, if present
|
|
37
|
+
* - any supported fallback resolution paths used by `node-gyp-build`
|
|
38
|
+
*
|
|
39
|
+
* The returned object is typed as {@link NativeAudioBinding} so the public
|
|
40
|
+
* TypeScript surface stays aligned with the native implementation.
|
|
41
|
+
*/
|
|
42
|
+
const native = require("node-gyp-build")(join(__dirname, ".."));
|
|
43
|
+
/**
|
|
44
|
+
* List available audio devices for a given direction.
|
|
45
|
+
*
|
|
46
|
+
* @param type - The device direction to query.
|
|
47
|
+
* @returns The list of devices exposed by the operating system.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import { listDevices } from 'truehear-audio-library-node';
|
|
52
|
+
*
|
|
53
|
+
* const playbackDevices = listDevices('playback');
|
|
54
|
+
* console.log(playbackDevices);
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* const recordingDevices = listDevices('recording');
|
|
60
|
+
* const defaultMic = recordingDevices.find((device) => device.default);
|
|
61
|
+
*
|
|
62
|
+
* if (defaultMic) {
|
|
63
|
+
* console.log(`Default microphone: ${defaultMic.name}`);
|
|
64
|
+
* }
|
|
65
|
+
* ```
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* ```ts
|
|
69
|
+
* for (const device of listDevices('playback')) {
|
|
70
|
+
* console.log(`${device.default ? '[default] ' : ''}${device.name}`);
|
|
71
|
+
* }
|
|
72
|
+
* ```
|
|
73
|
+
*/
|
|
74
|
+
export const listDevices = native.listDevices;
|
|
75
|
+
/**
|
|
76
|
+
* Set the system's default normal audio device.
|
|
77
|
+
*
|
|
78
|
+
* @remarks
|
|
79
|
+
* Use this function to switch the primary device used by standard applications.
|
|
80
|
+
*
|
|
81
|
+
* @param type - The device direction to update.
|
|
82
|
+
* @param deviceId - The native device identifier returned by {@link listDevices}.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* const devices = listDevices('playback');
|
|
87
|
+
* const speakers = devices.find((device) => device.name.includes('Speakers'));
|
|
88
|
+
*
|
|
89
|
+
* if (speakers) {
|
|
90
|
+
* setDefaultDevice('playback', speakers.id);
|
|
91
|
+
* }
|
|
92
|
+
* ```
|
|
93
|
+
*
|
|
94
|
+
* @example
|
|
95
|
+
* ```ts
|
|
96
|
+
* const mics = listDevices('recording');
|
|
97
|
+
* const usbMic = mics.find((device) => device.name.includes('USB'));
|
|
98
|
+
*
|
|
99
|
+
* if (usbMic) {
|
|
100
|
+
* setDefaultDevice('recording', usbMic.id);
|
|
101
|
+
* }
|
|
102
|
+
* ```
|
|
103
|
+
*/
|
|
104
|
+
export const setDefaultDevice = native.setDefaultDevice;
|
|
105
|
+
/**
|
|
106
|
+
* Set the system's default communication audio device.
|
|
107
|
+
*
|
|
108
|
+
* @remarks
|
|
109
|
+
* Communication devices are typically used by calling and conferencing apps
|
|
110
|
+
* such as Teams, Zoom, Discord, and similar voice-capable software.
|
|
111
|
+
*
|
|
112
|
+
* @param type - The device direction to update.
|
|
113
|
+
* @param deviceId - The native device identifier returned by {@link listDevices}.
|
|
114
|
+
*
|
|
115
|
+
* @example
|
|
116
|
+
* ```ts
|
|
117
|
+
* const devices = listDevices('playback');
|
|
118
|
+
* const defaultPlayback = devices.find((device) => device.default);
|
|
119
|
+
*
|
|
120
|
+
* if (defaultPlayback) {
|
|
121
|
+
* setDefaultCommunicationDevice('playback', defaultPlayback.id);
|
|
122
|
+
* }
|
|
123
|
+
* ```
|
|
124
|
+
*
|
|
125
|
+
* @example
|
|
126
|
+
* ```ts
|
|
127
|
+
* const recordingDevices = listDevices('recording');
|
|
128
|
+
* const headsetMic = recordingDevices.find((device) =>
|
|
129
|
+
* device.name.toLowerCase().includes('headset'),
|
|
130
|
+
* );
|
|
131
|
+
*
|
|
132
|
+
* if (headsetMic) {
|
|
133
|
+
* setDefaultCommunicationDevice('recording', headsetMic.id);
|
|
134
|
+
* }
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
export const setDefaultCommunicationDevice = native.setDefaultCommunicationDevice;
|
|
138
|
+
/**
|
|
139
|
+
* Default package export for consumers who prefer object-style access.
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```ts
|
|
143
|
+
* import truehearAudio from 'truehear-audio-library-node';
|
|
144
|
+
*
|
|
145
|
+
* const devices = truehearAudio.listDevices('playback');
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
const truehearAudio = {
|
|
149
|
+
listDevices,
|
|
150
|
+
setDefaultDevice,
|
|
151
|
+
setDefaultCommunicationDevice,
|
|
152
|
+
};
|
|
153
|
+
export default truehearAudio;
|
|
154
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../node/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAmBzC;;;;;;;;;GASG;AACH,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C;;;;GAIG;AACH,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAElD;;;;GAIG;AACH,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC;;;;;;;;;;;;;;GAcG;AACH,MAAM,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC,CACtC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CACA,CAAC;AAExB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,MAAM,CAAC,WAAW,CAAC;AAE9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,MAAM,CAAC,gBAAgB,CAAC;AAExD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,CAAC,MAAM,6BAA6B,GACxC,MAAM,CAAC,6BAA6B,CAAC;AAEvC;;;;;;;;;GASG;AACH,MAAM,aAAa,GAAG;IACpB,WAAW;IACX,gBAAgB;IAChB,6BAA6B;CAC9B,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
#ifndef TRUEHEAR_AUDIO_DEVICE_TYPES_H
|
|
2
|
+
#define TRUEHEAR_AUDIO_DEVICE_TYPES_H
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* Public audio device data types.
|
|
6
|
+
*
|
|
7
|
+
* This header contains only shared type definitions.
|
|
8
|
+
* It does not include Windows COM headers.
|
|
9
|
+
* It does not know about IMMDevice, IPolicyConfig, PipeWire, CoreAudio, etc.
|
|
10
|
+
*
|
|
11
|
+
* Goal:
|
|
12
|
+
*
|
|
13
|
+
* TypeScript API shape
|
|
14
|
+
* ↓
|
|
15
|
+
* Clean C structs
|
|
16
|
+
* ↓
|
|
17
|
+
* Platform-specific implementation fills the structs
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
#ifdef __cplusplus
|
|
22
|
+
extern "C" {
|
|
23
|
+
#endif
|
|
24
|
+
|
|
25
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
26
|
+
/* Audio device type */
|
|
27
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
28
|
+
|
|
29
|
+
/*
|
|
30
|
+
* Playback or recording device.
|
|
31
|
+
*
|
|
32
|
+
*/
|
|
33
|
+
typedef enum TruehearAudioDeviceType {
|
|
34
|
+
/*
|
|
35
|
+
* Output device.
|
|
36
|
+
*
|
|
37
|
+
* Examples:
|
|
38
|
+
* - speakers
|
|
39
|
+
* - headphones
|
|
40
|
+
* - HDMI output
|
|
41
|
+
*/
|
|
42
|
+
TRUEHEAR_AUDIO_DEVICE_TYPE_PLAYBACK = 0,
|
|
43
|
+
|
|
44
|
+
/*
|
|
45
|
+
* Input device.
|
|
46
|
+
*
|
|
47
|
+
* Examples:
|
|
48
|
+
* - microphone
|
|
49
|
+
* - headset microphone
|
|
50
|
+
* - USB audio input
|
|
51
|
+
*/
|
|
52
|
+
TRUEHEAR_AUDIO_DEVICE_TYPE_RECORDING = 1
|
|
53
|
+
} TruehearAudioDeviceType;
|
|
54
|
+
|
|
55
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
56
|
+
/* Audio device info */
|
|
57
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
58
|
+
|
|
59
|
+
/*
|
|
60
|
+
* Information about one audio device.
|
|
61
|
+
*
|
|
62
|
+
* This is the C equivalent of the TypeScript AudioDeviceInfo type.
|
|
63
|
+
*
|
|
64
|
+
* Important memory rule:
|
|
65
|
+
*
|
|
66
|
+
* name, id, and device are pointers.
|
|
67
|
+
*
|
|
68
|
+
* In the library implementation, these strings will usually be allocated by
|
|
69
|
+
* the library and freed by a matching cleanup function later.
|
|
70
|
+
*
|
|
71
|
+
* Callers should treat these strings as read-only.
|
|
72
|
+
*/
|
|
73
|
+
typedef struct TruehearAudioDeviceInfo {
|
|
74
|
+
/*
|
|
75
|
+
* Whether this device is the system default device for its type.
|
|
76
|
+
*
|
|
77
|
+
* For playback devices:
|
|
78
|
+
* system default output device
|
|
79
|
+
*
|
|
80
|
+
* For recording devices:
|
|
81
|
+
* system default input device
|
|
82
|
+
*
|
|
83
|
+
* 0 = false
|
|
84
|
+
* non-zero = true
|
|
85
|
+
*
|
|
86
|
+
* Note:
|
|
87
|
+
* We use int instead of bool because it is simple and stable across C/C++
|
|
88
|
+
* boundaries.
|
|
89
|
+
*/
|
|
90
|
+
int is_default;
|
|
91
|
+
|
|
92
|
+
/*
|
|
93
|
+
* Whether this device is the system default communication device.
|
|
94
|
+
*
|
|
95
|
+
* On Windows this is meaningful:
|
|
96
|
+
* - Teams
|
|
97
|
+
* - Zoom
|
|
98
|
+
* - calls
|
|
99
|
+
* - communication apps
|
|
100
|
+
*
|
|
101
|
+
* On Linux/macOS this may not exist, so the implementation can set this to 0.
|
|
102
|
+
*
|
|
103
|
+
* 0 = false
|
|
104
|
+
* non-zero = true
|
|
105
|
+
*/
|
|
106
|
+
int is_default_communication;
|
|
107
|
+
|
|
108
|
+
/*
|
|
109
|
+
* Playback or recording device.
|
|
110
|
+
*/
|
|
111
|
+
TruehearAudioDeviceType type;
|
|
112
|
+
|
|
113
|
+
/*
|
|
114
|
+
* Friendly display name for UI.
|
|
115
|
+
*
|
|
116
|
+
* Example:
|
|
117
|
+
*
|
|
118
|
+
* "Speakers (Realtek(R) Audio)"
|
|
119
|
+
*/
|
|
120
|
+
char *name;
|
|
121
|
+
|
|
122
|
+
/*
|
|
123
|
+
* Stable identifier used to select/change devices.
|
|
124
|
+
*
|
|
125
|
+
* Platform examples:
|
|
126
|
+
*
|
|
127
|
+
* Windows:
|
|
128
|
+
* IMMDevice endpoint ID string
|
|
129
|
+
*
|
|
130
|
+
* Linux:
|
|
131
|
+
* PipeWire node ID stored as a string
|
|
132
|
+
*
|
|
133
|
+
* macOS:
|
|
134
|
+
* CoreAudio device identifier depending on implementation
|
|
135
|
+
*/
|
|
136
|
+
char *id;
|
|
137
|
+
|
|
138
|
+
} TruehearAudioDeviceInfo;
|
|
139
|
+
|
|
140
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
141
|
+
/* Audio device list */
|
|
142
|
+
/* ---------------------------------------------------------------------------------------------- */
|
|
143
|
+
|
|
144
|
+
/*
|
|
145
|
+
* A list of audio devices returned by the library.
|
|
146
|
+
*
|
|
147
|
+
* This gives us a simple C equivalent of:
|
|
148
|
+
*
|
|
149
|
+
* AudioDeviceInfo[]
|
|
150
|
+
*/
|
|
151
|
+
typedef struct TruehearAudioDeviceInfoList {
|
|
152
|
+
/*
|
|
153
|
+
* Pointer to the first device item.
|
|
154
|
+
*
|
|
155
|
+
* Can be NULL when count is 0.
|
|
156
|
+
*/
|
|
157
|
+
TruehearAudioDeviceInfo *items;
|
|
158
|
+
|
|
159
|
+
/*
|
|
160
|
+
* Number of items in the list.
|
|
161
|
+
*/
|
|
162
|
+
int count;
|
|
163
|
+
} TruehearAudioDeviceInfoList;
|
|
164
|
+
|
|
165
|
+
#ifdef __cplusplus
|
|
166
|
+
}
|
|
167
|
+
#endif
|
|
168
|
+
|
|
169
|
+
#endif /* TRUEHEAR_AUDIO_DEVICE_TYPES_H */
|