@idealyst/audio 1.2.48 → 1.2.50
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/package.json +1 -1
- package/src/recording/Recorder.native.ts +36 -46
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@idealyst/audio",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.50",
|
|
4
4
|
"description": "Unified cross-platform audio for React and React Native - recording, playback, and PCM streaming",
|
|
5
5
|
"documentation": "https://github.com/IdealystIO/idealyst-framework/tree/main/packages/audio#readme",
|
|
6
6
|
"readme": "README.md",
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Native Recorder
|
|
3
3
|
*
|
|
4
|
-
* Uses react-native-audio-api for recording on React Native.
|
|
4
|
+
* Uses react-native-audio-api AudioRecorder for recording on React Native.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import {
|
|
8
|
-
|
|
8
|
+
AudioRecorder,
|
|
9
9
|
AudioManager,
|
|
10
10
|
} from 'react-native-audio-api';
|
|
11
11
|
import type {
|
|
@@ -26,7 +26,6 @@ import {
|
|
|
26
26
|
DEFAULT_AUDIO_LEVEL,
|
|
27
27
|
DEFAULT_RECORDER_STATUS,
|
|
28
28
|
DEFAULT_LEVEL_UPDATE_INTERVAL,
|
|
29
|
-
DEFAULT_BUFFER_SIZE,
|
|
30
29
|
} from '../constants';
|
|
31
30
|
import {
|
|
32
31
|
createAudioError,
|
|
@@ -38,8 +37,7 @@ import {
|
|
|
38
37
|
|
|
39
38
|
export class NativeRecorder implements IRecorder {
|
|
40
39
|
private audioContext: IAudioContext;
|
|
41
|
-
private
|
|
42
|
-
private scriptProcessorNode: any = null;
|
|
40
|
+
private audioRecorder: AudioRecorder | null = null;
|
|
43
41
|
|
|
44
42
|
private config: AudioConfig = DEFAULT_AUDIO_CONFIG;
|
|
45
43
|
private _status: RecorderStatus = { ...DEFAULT_RECORDER_STATUS };
|
|
@@ -101,40 +99,37 @@ export class NativeRecorder implements IRecorder {
|
|
|
101
99
|
this.updateState('starting');
|
|
102
100
|
this.config = mergeConfig(configOverride, DEFAULT_AUDIO_CONFIG);
|
|
103
101
|
|
|
104
|
-
// Ensure audio context is initialized
|
|
102
|
+
// Ensure audio context is initialized (for audio session management)
|
|
105
103
|
if (!this.audioContext.isInitialized) {
|
|
106
104
|
await this.audioContext.initialize();
|
|
107
105
|
}
|
|
108
106
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
107
|
+
// Create AudioRecorder from react-native-audio-api
|
|
108
|
+
this.audioRecorder = new AudioRecorder();
|
|
109
|
+
|
|
110
|
+
// Set up audio data callback with config options
|
|
111
|
+
this.audioRecorder.onAudioReady(
|
|
112
|
+
{
|
|
113
|
+
sampleRate: this.config.sampleRate,
|
|
114
|
+
bufferLength: 4096,
|
|
115
|
+
channelCount: this.config.channels,
|
|
116
|
+
},
|
|
117
|
+
(event) => {
|
|
118
|
+
if (this._status.state !== 'recording') return;
|
|
119
|
+
|
|
120
|
+
// Get audio data from the event buffer
|
|
121
|
+
const float32Samples = event.buffer.getChannelData(0);
|
|
122
|
+
this.handleAudioData(new Float32Array(float32Samples));
|
|
123
|
+
}
|
|
125
124
|
);
|
|
126
125
|
|
|
127
|
-
//
|
|
128
|
-
this.
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
const inputData = event.inputBuffer.getChannelData(0);
|
|
132
|
-
this.handleAudioData(new Float32Array(inputData));
|
|
133
|
-
};
|
|
126
|
+
// Set up error callback
|
|
127
|
+
this.audioRecorder.onError((error) => {
|
|
128
|
+
this.handleError(createAudioError('RECORDING_ERROR', error.message || 'Recording error'));
|
|
129
|
+
});
|
|
134
130
|
|
|
135
|
-
//
|
|
136
|
-
this.
|
|
137
|
-
this.scriptProcessorNode.connect(ctx.destination);
|
|
131
|
+
// Start recording
|
|
132
|
+
this.audioRecorder.start();
|
|
138
133
|
|
|
139
134
|
// Start level metering
|
|
140
135
|
this.startLevelMetering();
|
|
@@ -165,9 +160,8 @@ export class NativeRecorder implements IRecorder {
|
|
|
165
160
|
return;
|
|
166
161
|
}
|
|
167
162
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
this.scriptProcessorNode.disconnect();
|
|
163
|
+
if (this.audioRecorder) {
|
|
164
|
+
this.audioRecorder.pause();
|
|
171
165
|
}
|
|
172
166
|
this.updateState('paused');
|
|
173
167
|
}
|
|
@@ -177,9 +171,8 @@ export class NativeRecorder implements IRecorder {
|
|
|
177
171
|
return;
|
|
178
172
|
}
|
|
179
173
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
this.scriptProcessorNode.connect(ctx.destination);
|
|
174
|
+
if (this.audioRecorder) {
|
|
175
|
+
this.audioRecorder.resume();
|
|
183
176
|
}
|
|
184
177
|
this.updateState('recording');
|
|
185
178
|
}
|
|
@@ -282,14 +275,11 @@ export class NativeRecorder implements IRecorder {
|
|
|
282
275
|
this.levelIntervalId = null;
|
|
283
276
|
}
|
|
284
277
|
|
|
285
|
-
if (this.
|
|
286
|
-
this.
|
|
287
|
-
this.
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
if (this.mediaStreamNode) {
|
|
291
|
-
this.mediaStreamNode.disconnect();
|
|
292
|
-
this.mediaStreamNode = null;
|
|
278
|
+
if (this.audioRecorder) {
|
|
279
|
+
this.audioRecorder.clearOnAudioReady();
|
|
280
|
+
this.audioRecorder.clearOnError();
|
|
281
|
+
this.audioRecorder.stop();
|
|
282
|
+
this.audioRecorder = null;
|
|
293
283
|
}
|
|
294
284
|
}
|
|
295
285
|
|