native-recorder-nodejs 1.0.1
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/CMakeLists.txt +110 -0
- package/README.md +380 -0
- package/dist/bindings.d.ts +2 -0
- package/dist/bindings.js +31 -0
- package/dist/index.d.ts +104 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +110 -0
- package/dist/index.js.map +1 -0
- package/dist/recorder.d.ts +56 -0
- package/dist/recorder.d.ts.map +1 -0
- package/dist/recorder.js +343 -0
- package/dist/recorder.js.map +1 -0
- package/dist/types.d.ts +108 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +49 -0
- package/dist/types.js.map +1 -0
- package/native/AudioController.cpp +233 -0
- package/native/AudioController.h +26 -0
- package/native/AudioEngine.h +75 -0
- package/native/Factory.cpp +18 -0
- package/native/mac/AVFEngine.h +24 -0
- package/native/mac/AVFEngine.mm +274 -0
- package/native/mac/SCKAudioCapture.h +13 -0
- package/native/mac/SCKAudioCapture.mm +213 -0
- package/native/main.cpp +9 -0
- package/native/win/WASAPIEngine.cpp +449 -0
- package/native/win/WASAPIEngine.h +44 -0
- package/package.json +74 -0
- package/prebuilds/native-audio-recorder-v0.1.0-napi-v8-darwin-arm64.tar.gz +0 -0
- package/prebuilds/native-recorder-nodejs-v1.0.0-napi-v8-darwin-arm64.tar.gz +0 -0
- package/src/bindings.ts +39 -0
- package/src/index.ts +206 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.nativeBindings = exports.AudioRecorder = exports.SYSTEM_AUDIO_DEVICE_ID = void 0;
|
|
7
|
+
const bindings_1 = __importDefault(require("./bindings"));
|
|
8
|
+
const events_1 = require("events");
|
|
9
|
+
/**
|
|
10
|
+
* Special device ID for system-wide audio capture (macOS)
|
|
11
|
+
*/
|
|
12
|
+
exports.SYSTEM_AUDIO_DEVICE_ID = "system";
|
|
13
|
+
const native = bindings_1.default;
|
|
14
|
+
class AudioRecorder extends events_1.EventEmitter {
|
|
15
|
+
constructor() {
|
|
16
|
+
super();
|
|
17
|
+
this.isRecording = false;
|
|
18
|
+
this.controller = new native.AudioController();
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Starts the recording session.
|
|
22
|
+
* @param config Configuration object with deviceType and deviceId (both required)
|
|
23
|
+
*/
|
|
24
|
+
async start(config) {
|
|
25
|
+
if (this.isRecording) {
|
|
26
|
+
throw new Error("Already recording");
|
|
27
|
+
}
|
|
28
|
+
// Validate config
|
|
29
|
+
if (!config.deviceType || !config.deviceId) {
|
|
30
|
+
throw new Error("Both deviceType and deviceId are required");
|
|
31
|
+
}
|
|
32
|
+
if (config.deviceType !== "input" && config.deviceType !== "output") {
|
|
33
|
+
throw new Error("deviceType must be 'input' or 'output'");
|
|
34
|
+
}
|
|
35
|
+
return new Promise((resolve, reject) => {
|
|
36
|
+
try {
|
|
37
|
+
this.controller.start(config, (error, data) => {
|
|
38
|
+
if (error) {
|
|
39
|
+
this.emit("error", error);
|
|
40
|
+
}
|
|
41
|
+
else if (data) {
|
|
42
|
+
this.emit("data", data);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
this.isRecording = true;
|
|
46
|
+
resolve();
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
reject(error);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
async stop() {
|
|
54
|
+
if (!this.isRecording) {
|
|
55
|
+
return;
|
|
56
|
+
}
|
|
57
|
+
return new Promise((resolve, reject) => {
|
|
58
|
+
try {
|
|
59
|
+
this.controller.stop();
|
|
60
|
+
this.isRecording = false;
|
|
61
|
+
resolve();
|
|
62
|
+
}
|
|
63
|
+
catch (error) {
|
|
64
|
+
reject(error);
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Lists available audio devices.
|
|
70
|
+
* @param type Optional filter by device type
|
|
71
|
+
* @returns Array of AudioDevice objects (all with valid id values)
|
|
72
|
+
*/
|
|
73
|
+
static getDevices(type) {
|
|
74
|
+
const devices = native.AudioController.getDevices();
|
|
75
|
+
if (type) {
|
|
76
|
+
return devices.filter((d) => d.type === type);
|
|
77
|
+
}
|
|
78
|
+
return devices;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Gets the audio format of a specific device.
|
|
82
|
+
* @param deviceId The device ID to query
|
|
83
|
+
* @returns AudioFormat object
|
|
84
|
+
*/
|
|
85
|
+
static getDeviceFormat(deviceId) {
|
|
86
|
+
return native.AudioController.getDeviceFormat(deviceId);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Checks the current permission status for audio recording.
|
|
90
|
+
* On Windows, always returns { mic: true, system: true } as no explicit permissions are required.
|
|
91
|
+
* On macOS, checks actual permission status for microphone and screen recording.
|
|
92
|
+
* @returns PermissionStatus object with mic and system boolean fields
|
|
93
|
+
*/
|
|
94
|
+
static checkPermission() {
|
|
95
|
+
return native.AudioController.checkPermission();
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Requests permission for the specified type.
|
|
99
|
+
* On Windows, always returns true as no explicit permissions are required.
|
|
100
|
+
* On macOS, prompts the user to grant the requested permission.
|
|
101
|
+
* @param type The permission type to request: 'mic' for microphone, 'system' for system audio
|
|
102
|
+
* @returns true if permission was granted, false otherwise
|
|
103
|
+
*/
|
|
104
|
+
static requestPermission(type) {
|
|
105
|
+
return native.AudioController.requestPermission(type);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.AudioRecorder = AudioRecorder;
|
|
109
|
+
// Export raw bindings for testing if needed
|
|
110
|
+
exports.nativeBindings = bindings_1.default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/typescript/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,+BAA+B;AAC/B,0CAAwB;AACxB,6CAA2B;AAE3B,iCAAiC;AACjC,uCAAiD;AAAxC,mGAAA,QAAQ,OAAW"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { Result, PermissionStatus, AudioDevice, RecordingOptions, RecordingState, AudioSDKError, AudioDeviceType, RecordingStreamEvent } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Main Audio SDK Recorder class
|
|
4
|
+
*/
|
|
5
|
+
export declare class Recorder {
|
|
6
|
+
private state;
|
|
7
|
+
private currentController?;
|
|
8
|
+
private recorderId?;
|
|
9
|
+
/**
|
|
10
|
+
* Private constructor that prevents direct instantiation of the Recorder class.
|
|
11
|
+
*
|
|
12
|
+
* Use the static `Recorder.create()` method instead to create instances.
|
|
13
|
+
*
|
|
14
|
+
* @deprecated This constructor should not be called directly. Use Recorder.create() instead.
|
|
15
|
+
* @private
|
|
16
|
+
*/
|
|
17
|
+
constructor(internal?: boolean);
|
|
18
|
+
/**
|
|
19
|
+
* Factory method to create a new Recorder instance
|
|
20
|
+
*/
|
|
21
|
+
static create(): Promise<Recorder>;
|
|
22
|
+
private initializeNative;
|
|
23
|
+
/**
|
|
24
|
+
* Check current permissions without requesting them
|
|
25
|
+
*/
|
|
26
|
+
checkPermissions(): Promise<Result<PermissionStatus>>;
|
|
27
|
+
/**
|
|
28
|
+
* Get list of available audio devices
|
|
29
|
+
*/
|
|
30
|
+
getAudioDevices(type?: AudioDeviceType): Promise<Result<AudioDevice[]>>;
|
|
31
|
+
/**
|
|
32
|
+
* Start recording with async generator pattern
|
|
33
|
+
*/
|
|
34
|
+
startRecording(options: RecordingOptions): Promise<Result<AsyncGenerator<RecordingStreamEvent>, AudioSDKError>>;
|
|
35
|
+
/**
|
|
36
|
+
* Private method to create the recording generator
|
|
37
|
+
*/
|
|
38
|
+
private createRecordingGenerator;
|
|
39
|
+
/**
|
|
40
|
+
* Stop current recording
|
|
41
|
+
*/
|
|
42
|
+
stopRecording(): Promise<Result<void>>;
|
|
43
|
+
/**
|
|
44
|
+
* Get current recording state
|
|
45
|
+
*/
|
|
46
|
+
getState(): RecordingState;
|
|
47
|
+
/**
|
|
48
|
+
* Clean up resources
|
|
49
|
+
*/
|
|
50
|
+
private cleanup;
|
|
51
|
+
/**
|
|
52
|
+
* Dispose of the recorder and free native resources
|
|
53
|
+
*/
|
|
54
|
+
dispose(): Promise<void>;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=recorder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recorder.d.ts","sourceRoot":"","sources":["../src/typescript/recorder.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,MAAM,EACN,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAEhB,cAAc,EACd,aAAa,EAEb,eAAe,EACf,oBAAoB,EACrB,MAAM,SAAS,CAAC;AAejB;;GAEG;AACH,qBAAa,QAAQ;IACnB,OAAO,CAAC,KAAK,CAAuC;IACpD,OAAO,CAAC,iBAAiB,CAAC,CAAkB;IAC5C,OAAO,CAAC,UAAU,CAAC,CAAS;IAE5B;;;;;;;OAOG;gBACS,QAAQ,UAAQ;IAQ5B;;OAEG;WACU,MAAM,IAAI,OAAO,CAAC,QAAQ,CAAC;YAM1B,gBAAgB;IAY9B;;OAEG;IACG,gBAAgB,IAAI,OAAO,CAAC,MAAM,CAAC,gBAAgB,CAAC,CAAC;IAqC3D;;OAEG;IACG,eAAe,CACnB,IAAI,CAAC,EAAE,eAAe,GACrB,OAAO,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CAAC;IAkEjC;;OAEG;IACG,cAAc,CAClB,OAAO,EAAE,gBAAgB,GACxB,OAAO,CAAC,MAAM,CAAC,cAAc,CAAC,oBAAoB,CAAC,EAAE,aAAa,CAAC,CAAC;IA4EvE;;OAEG;YACY,wBAAwB;IAoEvC;;OAEG;IACG,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IAsD5C;;OAEG;IACH,QAAQ,IAAI,cAAc;IAI1B;;OAEG;YACW,OAAO;IAarB;;OAEG;IACG,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAY/B"}
|
package/dist/recorder.js
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.Recorder = void 0;
|
|
37
|
+
const types_1 = require("./types");
|
|
38
|
+
const path = __importStar(require("path"));
|
|
39
|
+
// import nativeAddon from "../../build/Release/audio_sdk_native.node";
|
|
40
|
+
// Import the native addon with correct path resolution
|
|
41
|
+
const nativeAddon = require(path.join(__dirname, "../..", "build", "Release", "audio_sdk_native.node"));
|
|
42
|
+
/**
|
|
43
|
+
* Main Audio SDK Recorder class
|
|
44
|
+
*/
|
|
45
|
+
class Recorder {
|
|
46
|
+
/**
|
|
47
|
+
* Private constructor that prevents direct instantiation of the Recorder class.
|
|
48
|
+
*
|
|
49
|
+
* Use the static `Recorder.create()` method instead to create instances.
|
|
50
|
+
*
|
|
51
|
+
* @deprecated This constructor should not be called directly. Use Recorder.create() instead.
|
|
52
|
+
* @private
|
|
53
|
+
*/
|
|
54
|
+
constructor(internal = false) {
|
|
55
|
+
this.state = types_1.RecordingState.IDLE;
|
|
56
|
+
if (!internal) {
|
|
57
|
+
console.error("Do not instantiate Recorder directly, use Recorder.create() instead");
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Factory method to create a new Recorder instance
|
|
62
|
+
*/
|
|
63
|
+
static async create() {
|
|
64
|
+
const recorder = new Recorder(true);
|
|
65
|
+
await recorder.initializeNative();
|
|
66
|
+
return recorder;
|
|
67
|
+
}
|
|
68
|
+
async initializeNative() {
|
|
69
|
+
const result = nativeAddon.createRecorder();
|
|
70
|
+
if (!result.success) {
|
|
71
|
+
throw new types_1.AudioSDKError(types_1.AudioSDKErrorType.INITIALIZATION_FAILED, "Failed to initialize native recorder", result.error);
|
|
72
|
+
}
|
|
73
|
+
this.recorderId = result.value;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Check current permissions without requesting them
|
|
77
|
+
*/
|
|
78
|
+
async checkPermissions() {
|
|
79
|
+
if (!this.recorderId) {
|
|
80
|
+
return {
|
|
81
|
+
success: false,
|
|
82
|
+
error: new types_1.AudioSDKError(types_1.AudioSDKErrorType.INITIALIZATION_FAILED, "Recorder not initialized"),
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
try {
|
|
86
|
+
const result = nativeAddon.checkPermissions(this.recorderId);
|
|
87
|
+
if (result.success) {
|
|
88
|
+
return { success: true, value: result.value };
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
return {
|
|
92
|
+
success: false,
|
|
93
|
+
error: new types_1.AudioSDKError(types_1.AudioSDKErrorType.PERMISSION_DENIED, result.error.message, result.error),
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
return {
|
|
99
|
+
success: false,
|
|
100
|
+
error: new types_1.AudioSDKError(types_1.AudioSDKErrorType.PERMISSION_DENIED, "Failed to check permissions", error),
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Get list of available audio devices
|
|
106
|
+
*/
|
|
107
|
+
async getAudioDevices(type) {
|
|
108
|
+
if (!this.recorderId) {
|
|
109
|
+
return {
|
|
110
|
+
success: false,
|
|
111
|
+
error: new types_1.AudioSDKError(types_1.AudioSDKErrorType.INITIALIZATION_FAILED, "Recorder not initialized"),
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
const devices = [];
|
|
116
|
+
const deviceTypes = type !== undefined
|
|
117
|
+
? [type]
|
|
118
|
+
: [
|
|
119
|
+
types_1.AudioDeviceType.MICROPHONE,
|
|
120
|
+
types_1.AudioDeviceType.SYSTEM_AUDIO,
|
|
121
|
+
types_1.AudioDeviceType.APPLICATION,
|
|
122
|
+
];
|
|
123
|
+
for (const deviceType of deviceTypes) {
|
|
124
|
+
const countResult = nativeAddon.getDeviceCount(this.recorderId, deviceType);
|
|
125
|
+
if (!countResult.success) {
|
|
126
|
+
console.warn(`Failed to get device count for type ${deviceType}: ${countResult.error.message}`);
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
const count = countResult.value;
|
|
130
|
+
for (let i = 0; i < count; i++) {
|
|
131
|
+
const deviceResult = nativeAddon.getDeviceInfo(this.recorderId, deviceType, i);
|
|
132
|
+
if (deviceResult.success) {
|
|
133
|
+
devices.push({
|
|
134
|
+
id: deviceResult.value.id,
|
|
135
|
+
name: deviceResult.value.name,
|
|
136
|
+
type: deviceResult.value.type,
|
|
137
|
+
isDefault: deviceResult.value.isDefault,
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
return { success: true, value: devices };
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
return {
|
|
146
|
+
success: false,
|
|
147
|
+
error: new types_1.AudioSDKError(types_1.AudioSDKErrorType.DEVICE_NOT_FOUND, "Failed to enumerate audio devices", error),
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Start recording with async generator pattern
|
|
153
|
+
*/
|
|
154
|
+
async startRecording(options) {
|
|
155
|
+
if (this.state !== types_1.RecordingState.IDLE) {
|
|
156
|
+
return {
|
|
157
|
+
success: false,
|
|
158
|
+
error: new types_1.AudioSDKError(types_1.AudioSDKErrorType.RECORDING_FAILED, `Cannot start recording in ${this.state} state`),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
if (!this.recorderId) {
|
|
162
|
+
return {
|
|
163
|
+
success: false,
|
|
164
|
+
error: new types_1.AudioSDKError(types_1.AudioSDKErrorType.INITIALIZATION_FAILED, "Recorder not initialized"),
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
try {
|
|
168
|
+
// Convert options to native format
|
|
169
|
+
const nativeOptions = {
|
|
170
|
+
deviceType: options.deviceType,
|
|
171
|
+
deviceId: options.deviceId,
|
|
172
|
+
format: options.format || {
|
|
173
|
+
sampleRate: 44100,
|
|
174
|
+
channels: 2,
|
|
175
|
+
bitDepth: 16,
|
|
176
|
+
},
|
|
177
|
+
application: options.application,
|
|
178
|
+
};
|
|
179
|
+
// Initialize native recording
|
|
180
|
+
const initResult = nativeAddon.startRecording(this.recorderId, nativeOptions);
|
|
181
|
+
if (!initResult.success) {
|
|
182
|
+
this.state = types_1.RecordingState.ERROR;
|
|
183
|
+
return {
|
|
184
|
+
success: false,
|
|
185
|
+
error: new types_1.AudioSDKError(types_1.AudioSDKErrorType.INITIALIZATION_FAILED, initResult.error.message, initResult.error),
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
this.state = types_1.RecordingState.RECORDING;
|
|
189
|
+
// Create abort controller for clean cancellation
|
|
190
|
+
this.currentController = new AbortController();
|
|
191
|
+
// Create the async generator
|
|
192
|
+
const generator = this.createRecordingGenerator();
|
|
193
|
+
return {
|
|
194
|
+
success: true,
|
|
195
|
+
value: generator,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
this.state = types_1.RecordingState.ERROR;
|
|
200
|
+
return {
|
|
201
|
+
success: false,
|
|
202
|
+
error: new types_1.AudioSDKError(types_1.AudioSDKErrorType.INITIALIZATION_FAILED, "Failed to initialize recording", error),
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Private method to create the recording generator
|
|
208
|
+
*/
|
|
209
|
+
async *createRecordingGenerator() {
|
|
210
|
+
try {
|
|
211
|
+
// Start audio stream
|
|
212
|
+
while (!this.currentController?.signal.aborted &&
|
|
213
|
+
this.state === types_1.RecordingState.RECORDING) {
|
|
214
|
+
try {
|
|
215
|
+
// Check if still recording
|
|
216
|
+
const statusResult = nativeAddon.isRecording(this.recorderId);
|
|
217
|
+
if (!statusResult.success || !statusResult.value) {
|
|
218
|
+
break;
|
|
219
|
+
}
|
|
220
|
+
const chunkResult = nativeAddon.getAudioChunk(this.recorderId);
|
|
221
|
+
if (chunkResult.success) {
|
|
222
|
+
yield {
|
|
223
|
+
type: "chunk",
|
|
224
|
+
data: {
|
|
225
|
+
data: chunkResult.value.data,
|
|
226
|
+
timestamp: chunkResult.value.timestamp,
|
|
227
|
+
format: chunkResult.value.format,
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
}
|
|
231
|
+
else {
|
|
232
|
+
this.state = types_1.RecordingState.ERROR;
|
|
233
|
+
yield {
|
|
234
|
+
type: "error",
|
|
235
|
+
error: new types_1.AudioSDKError(types_1.AudioSDKErrorType.RECORDING_FAILED, chunkResult.error.message, chunkResult.error),
|
|
236
|
+
};
|
|
237
|
+
break;
|
|
238
|
+
}
|
|
239
|
+
// Small delay to prevent busy waiting
|
|
240
|
+
await new Promise((resolve) => setTimeout(resolve, 10));
|
|
241
|
+
}
|
|
242
|
+
catch (error) {
|
|
243
|
+
this.state = types_1.RecordingState.ERROR;
|
|
244
|
+
yield {
|
|
245
|
+
type: "error",
|
|
246
|
+
error: new types_1.AudioSDKError(types_1.AudioSDKErrorType.RECORDING_FAILED, "Error during recording", error),
|
|
247
|
+
};
|
|
248
|
+
break;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
catch (error) {
|
|
253
|
+
this.state = types_1.RecordingState.ERROR;
|
|
254
|
+
yield {
|
|
255
|
+
type: "error",
|
|
256
|
+
error: new types_1.AudioSDKError(types_1.AudioSDKErrorType.INITIALIZATION_FAILED, "Failed to initialize recording", error),
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
finally {
|
|
260
|
+
await this.cleanup();
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Stop current recording
|
|
265
|
+
*/
|
|
266
|
+
async stopRecording() {
|
|
267
|
+
if (this.state !== types_1.RecordingState.RECORDING) {
|
|
268
|
+
return {
|
|
269
|
+
success: false,
|
|
270
|
+
error: new types_1.AudioSDKError(types_1.AudioSDKErrorType.RECORDING_FAILED, `Cannot stop recording in ${this.state} state`),
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
if (!this.recorderId) {
|
|
274
|
+
return {
|
|
275
|
+
success: false,
|
|
276
|
+
error: new types_1.AudioSDKError(types_1.AudioSDKErrorType.INITIALIZATION_FAILED, "Recorder not initialized"),
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
try {
|
|
280
|
+
if (this.currentController) {
|
|
281
|
+
this.currentController.abort();
|
|
282
|
+
}
|
|
283
|
+
const result = nativeAddon.stopRecording(this.recorderId);
|
|
284
|
+
if (result.success) {
|
|
285
|
+
this.state = types_1.RecordingState.STOPPED;
|
|
286
|
+
return { success: true, value: undefined };
|
|
287
|
+
}
|
|
288
|
+
else {
|
|
289
|
+
this.state = types_1.RecordingState.ERROR;
|
|
290
|
+
return {
|
|
291
|
+
success: false,
|
|
292
|
+
error: new types_1.AudioSDKError(types_1.AudioSDKErrorType.RECORDING_FAILED, result.error.message, result.error),
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
catch (error) {
|
|
297
|
+
this.state = types_1.RecordingState.ERROR;
|
|
298
|
+
return {
|
|
299
|
+
success: false,
|
|
300
|
+
error: new types_1.AudioSDKError(types_1.AudioSDKErrorType.RECORDING_FAILED, "Failed to stop recording", error),
|
|
301
|
+
};
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
/**
|
|
305
|
+
* Get current recording state
|
|
306
|
+
*/
|
|
307
|
+
getState() {
|
|
308
|
+
return this.state;
|
|
309
|
+
}
|
|
310
|
+
/**
|
|
311
|
+
* Clean up resources
|
|
312
|
+
*/
|
|
313
|
+
async cleanup() {
|
|
314
|
+
try {
|
|
315
|
+
if (this.state === types_1.RecordingState.RECORDING && this.recorderId) {
|
|
316
|
+
nativeAddon.stopRecording(this.recorderId);
|
|
317
|
+
}
|
|
318
|
+
this.state = types_1.RecordingState.IDLE;
|
|
319
|
+
this.currentController = undefined;
|
|
320
|
+
}
|
|
321
|
+
catch (error) {
|
|
322
|
+
// Log error but don't throw in cleanup
|
|
323
|
+
console.error("Error during cleanup:", error);
|
|
324
|
+
}
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Dispose of the recorder and free native resources
|
|
328
|
+
*/
|
|
329
|
+
async dispose() {
|
|
330
|
+
await this.cleanup();
|
|
331
|
+
if (this.recorderId) {
|
|
332
|
+
try {
|
|
333
|
+
nativeAddon.destroyRecorder(this.recorderId);
|
|
334
|
+
}
|
|
335
|
+
catch (error) {
|
|
336
|
+
console.error("Error destroying native recorder:", error);
|
|
337
|
+
}
|
|
338
|
+
this.recorderId = undefined;
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
exports.Recorder = Recorder;
|
|
343
|
+
//# sourceMappingURL=recorder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"recorder.js","sourceRoot":"","sources":["../src/typescript/recorder.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,mCAWiB;AAEjB,2CAA6B;AAE7B,uEAAuE;AAEvE,uDAAuD;AACvD,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,IAAI,CACnC,SAAS,EACT,OAAO,EACP,OAAO,EACP,SAAS,EACT,uBAAuB,CACxB,CAAC,CAAC;AAEH;;GAEG;AACH,MAAa,QAAQ;IAKnB;;;;;;;OAOG;IACH,YAAY,QAAQ,GAAG,KAAK;QAZpB,UAAK,GAAmB,sBAAc,CAAC,IAAI,CAAC;QAalD,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,OAAO,CAAC,KAAK,CACX,qEAAqE,CACtE,CAAC;QACJ,CAAC;IACH,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,MAA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AC5D,CAAC;YACD,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC9B,CAAC;IACH,CAAC;CACF;AAhZD,4BAgZC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Result type for error handling - Either success with value or failure with error
|
|
3
|
+
*/
|
|
4
|
+
export type Result<T, E = Error> = {
|
|
5
|
+
success: true;
|
|
6
|
+
value: T;
|
|
7
|
+
} | {
|
|
8
|
+
success: false;
|
|
9
|
+
error: E;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Audio device types
|
|
13
|
+
*/
|
|
14
|
+
export declare enum AudioDeviceType {
|
|
15
|
+
MICROPHONE = 0,
|
|
16
|
+
SYSTEM_AUDIO = 1,
|
|
17
|
+
APPLICATION = 2
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Audio format configuration
|
|
21
|
+
*/
|
|
22
|
+
export interface AudioFormat {
|
|
23
|
+
sampleRate: number;
|
|
24
|
+
channels: number;
|
|
25
|
+
bitDepth: 16 | 24 | 32;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Audio device information
|
|
29
|
+
*/
|
|
30
|
+
export interface AudioDevice {
|
|
31
|
+
id: string;
|
|
32
|
+
name: string;
|
|
33
|
+
type: AudioDeviceType;
|
|
34
|
+
isDefault: boolean;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Application information for application-specific recording
|
|
38
|
+
*/
|
|
39
|
+
export interface ApplicationInfo {
|
|
40
|
+
pid: number;
|
|
41
|
+
name: string;
|
|
42
|
+
bundleId?: string;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Recording options
|
|
46
|
+
*/
|
|
47
|
+
export interface RecordingOptions {
|
|
48
|
+
deviceType: AudioDeviceType;
|
|
49
|
+
deviceId: string;
|
|
50
|
+
format?: AudioFormat;
|
|
51
|
+
application?: ApplicationInfo;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Audio chunk data
|
|
55
|
+
*/
|
|
56
|
+
export interface AudioChunk {
|
|
57
|
+
data: Buffer;
|
|
58
|
+
timestamp: number;
|
|
59
|
+
format: AudioFormat;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Permission types
|
|
63
|
+
*/
|
|
64
|
+
export interface PermissionStatus {
|
|
65
|
+
microphone: boolean;
|
|
66
|
+
systemAudio: boolean;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Error types
|
|
70
|
+
*/
|
|
71
|
+
export declare enum AudioSDKErrorType {
|
|
72
|
+
PERMISSION_DENIED = "PERMISSION_DENIED",
|
|
73
|
+
DEVICE_NOT_FOUND = "DEVICE_NOT_FOUND",
|
|
74
|
+
DEVICE_BUSY = "DEVICE_BUSY",
|
|
75
|
+
INITIALIZATION_FAILED = "INITIALIZATION_FAILED",
|
|
76
|
+
RECORDING_FAILED = "RECORDING_FAILED",
|
|
77
|
+
INVALID_FORMAT = "INVALID_FORMAT",
|
|
78
|
+
PLATFORM_NOT_SUPPORTED = "PLATFORM_NOT_SUPPORTED"
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Custom error class for Audio SDK
|
|
82
|
+
*/
|
|
83
|
+
export declare class AudioSDKError extends Error {
|
|
84
|
+
type: AudioSDKErrorType;
|
|
85
|
+
details?: any | undefined;
|
|
86
|
+
constructor(type: AudioSDKErrorType, message: string, details?: any | undefined);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Recording state
|
|
90
|
+
*/
|
|
91
|
+
export declare enum RecordingState {
|
|
92
|
+
IDLE = "idle",
|
|
93
|
+
RECORDING = "recording",
|
|
94
|
+
PAUSED = "paused",
|
|
95
|
+
STOPPED = "stopped",
|
|
96
|
+
ERROR = "error"
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Recording stream event types
|
|
100
|
+
*/
|
|
101
|
+
export type RecordingStreamEvent = {
|
|
102
|
+
type: "chunk";
|
|
103
|
+
data: AudioChunk;
|
|
104
|
+
} | {
|
|
105
|
+
type: "error";
|
|
106
|
+
error: AudioSDKError;
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/typescript/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,IAC3B;IAAE,OAAO,EAAE,IAAI,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAC3B;IAAE,OAAO,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,CAAC,CAAA;CAAE,CAAC;AAEjC;;GAEG;AACH,oBAAY,eAAe;IACzB,UAAU,IAAI;IACd,YAAY,IAAI;IAChB,WAAW,IAAI;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,EAAE,GAAG,EAAE,GAAG,EAAE,CAAC;CACxB;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,eAAe,CAAC;IACtB,SAAS,EAAE,OAAO,CAAC;CACpB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B,UAAU,EAAE,eAAe,CAAC;IAC5B,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,WAAW,CAAC,EAAE,eAAe,CAAC;CAC/B;AAED;;GAEG;AACH,MAAM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