@edkimmel/expo-audio-stream 0.3.3 → 0.4.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/android/src/main/java/expo/modules/audiostream/Constants.kt +0 -2
- package/android/src/main/java/expo/modules/audiostream/ExpoPlayAudioStreamModule.kt +3 -61
- package/build/events.d.ts +0 -6
- package/build/events.d.ts.map +1 -1
- package/build/events.js +0 -5
- package/build/events.js.map +1 -1
- package/build/index.d.ts +4 -52
- package/build/index.d.ts.map +1 -1
- package/build/index.js +4 -86
- package/build/index.js.map +1 -1
- package/build/types.d.ts +0 -29
- package/build/types.d.ts.map +1 -1
- package/build/types.js.map +1 -1
- package/ios/AudioUtils.swift +0 -7
- package/ios/ExpoPlayAudioStreamModule.swift +8 -138
- package/ios/SharedAudioEngine.swift +90 -60
- package/ios/SoundConfig.swift +2 -36
- package/package.json +1 -1
- package/src/events.ts +0 -12
- package/src/index.ts +2 -102
- package/src/types.ts +0 -35
- package/android/src/main/java/expo/modules/audiostream/AudioPlaybackManager.kt +0 -651
- package/android/src/main/java/expo/modules/audiostream/SoundConfig.kt +0 -46
- package/ios/SoundPlayer.swift +0 -408
- package/ios/SoundPlayerDelegate.swift +0 -7
package/src/events.ts
CHANGED
|
@@ -23,10 +23,6 @@ export interface AudioEventPayload {
|
|
|
23
23
|
frequencyBands?: { low: number; mid: number; high: number };
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
-
export type SoundChunkPlayedEventPayload = {
|
|
27
|
-
isFinal: boolean;
|
|
28
|
-
};
|
|
29
|
-
|
|
30
26
|
export const DeviceReconnectedReasons = {
|
|
31
27
|
newDeviceAvailable: "newDeviceAvailable",
|
|
32
28
|
oldDeviceUnavailable: "oldDeviceUnavailable",
|
|
@@ -42,8 +38,6 @@ export type DeviceReconnectedEventPayload = {
|
|
|
42
38
|
|
|
43
39
|
export const AudioEvents = {
|
|
44
40
|
AudioData: "AudioData",
|
|
45
|
-
SoundChunkPlayed: "SoundChunkPlayed",
|
|
46
|
-
SoundStarted: "SoundStarted",
|
|
47
41
|
DeviceReconnected: "DeviceReconnected",
|
|
48
42
|
};
|
|
49
43
|
|
|
@@ -53,12 +47,6 @@ export function addAudioEventListener(
|
|
|
53
47
|
return (emitter as any).addListener("AudioData", listener);
|
|
54
48
|
}
|
|
55
49
|
|
|
56
|
-
export function addSoundChunkPlayedListener(
|
|
57
|
-
listener: (event: SoundChunkPlayedEventPayload) => Promise<void>
|
|
58
|
-
): EventSubscription {
|
|
59
|
-
return (emitter as any).addListener("SoundChunkPlayed", listener);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
50
|
export function subscribeToEvent<T extends unknown>(
|
|
63
51
|
eventName: string,
|
|
64
52
|
listener: (event: T | undefined) => Promise<void>
|
package/src/index.ts
CHANGED
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
AudioRecording,
|
|
9
9
|
RecordingConfig,
|
|
10
10
|
StartRecordingResult,
|
|
11
|
-
SoundConfig,
|
|
12
11
|
PlaybackMode,
|
|
13
12
|
Encoding,
|
|
14
13
|
EncodingTypes,
|
|
@@ -31,82 +30,21 @@ import {
|
|
|
31
30
|
|
|
32
31
|
import {
|
|
33
32
|
addAudioEventListener,
|
|
34
|
-
addSoundChunkPlayedListener,
|
|
35
33
|
AudioEventPayload,
|
|
36
|
-
SoundChunkPlayedEventPayload,
|
|
37
34
|
AudioEvents,
|
|
38
35
|
subscribeToEvent,
|
|
39
36
|
DeviceReconnectedReason,
|
|
40
37
|
DeviceReconnectedEventPayload,
|
|
41
38
|
} from "./events";
|
|
42
39
|
|
|
43
|
-
const SuspendSoundEventTurnId = "suspend-sound-events";
|
|
44
|
-
|
|
45
40
|
export class ExpoPlayAudioStream {
|
|
46
41
|
/**
|
|
47
42
|
* Destroys the audio stream module, cleaning up all resources.
|
|
48
43
|
* This should be called when the module is no longer needed.
|
|
49
44
|
* It will reset all internal state and release audio resources.
|
|
50
45
|
*/
|
|
51
|
-
static destroy() {
|
|
52
|
-
ExpoPlayAudioStreamModule.destroy();
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* @deprecated Use the `Pipeline` class for more efficient audio streaming with better error handling and telemetry.
|
|
57
|
-
* Plays a sound.
|
|
58
|
-
* @param {string} audio - The audio to play.
|
|
59
|
-
* @param {string} turnId - The turn ID.
|
|
60
|
-
* @param {string} [encoding] - The encoding format of the audio data ('pcm_f32le' or 'pcm_s16le').
|
|
61
|
-
* @returns {Promise<void>}
|
|
62
|
-
* @throws {Error} If the sound fails to play.
|
|
63
|
-
*/
|
|
64
|
-
static async playSound(
|
|
65
|
-
audio: string,
|
|
66
|
-
turnId: string,
|
|
67
|
-
encoding?: Encoding
|
|
68
|
-
): Promise<void> {
|
|
69
|
-
try {
|
|
70
|
-
await ExpoPlayAudioStreamModule.playSound(
|
|
71
|
-
audio,
|
|
72
|
-
turnId,
|
|
73
|
-
encoding ?? EncodingTypes.PCM_S16LE
|
|
74
|
-
);
|
|
75
|
-
} catch (error) {
|
|
76
|
-
console.error(error);
|
|
77
|
-
throw new Error(`Failed to enqueue audio: ${error}`);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* @deprecated Use the `Pipeline` class for more efficient audio streaming with better error handling and telemetry.
|
|
83
|
-
* Stops the currently playing sound.
|
|
84
|
-
* @returns {Promise<void>}
|
|
85
|
-
* @throws {Error} If the sound fails to stop.
|
|
86
|
-
*/
|
|
87
|
-
static async stopSound(): Promise<void> {
|
|
88
|
-
try {
|
|
89
|
-
await ExpoPlayAudioStreamModule.stopSound();
|
|
90
|
-
} catch (error) {
|
|
91
|
-
console.error(error);
|
|
92
|
-
throw new Error(`Failed to stop enqueued audio: ${error}`);
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* @deprecated Use the `Pipeline` class for more efficient audio streaming with better error handling and telemetry.
|
|
98
|
-
* Clears the sound queue by turn ID.
|
|
99
|
-
* @param {string} turnId - The turn ID.
|
|
100
|
-
* @returns {Promise<void>}
|
|
101
|
-
* @throws {Error} If the sound queue fails to clear.
|
|
102
|
-
*/
|
|
103
|
-
static async clearSoundQueueByTurnId(turnId: string): Promise<void> {
|
|
104
|
-
try {
|
|
105
|
-
await ExpoPlayAudioStreamModule.clearSoundQueueByTurnId(turnId);
|
|
106
|
-
} catch (error) {
|
|
107
|
-
console.error(error);
|
|
108
|
-
throw new Error(`Failed to clear sound queue: ${error}`);
|
|
109
|
-
}
|
|
46
|
+
static async destroy() {
|
|
47
|
+
await ExpoPlayAudioStreamModule.destroy();
|
|
110
48
|
}
|
|
111
49
|
|
|
112
50
|
/**
|
|
@@ -181,15 +119,7 @@ export class ExpoPlayAudioStream {
|
|
|
181
119
|
/**
|
|
182
120
|
* Subscribes to audio events emitted during recording/streaming.
|
|
183
121
|
* @param onMicrophoneStream - Callback function that will be called when audio data is received.
|
|
184
|
-
* The callback receives an AudioDataEvent containing:
|
|
185
|
-
* - data: Base64 encoded audio data at original sample rate
|
|
186
|
-
* - data16kHz: Optional base64 encoded audio data resampled to 16kHz
|
|
187
|
-
* - position: Current position in the audio stream
|
|
188
|
-
* - fileUri: URI of the recording file
|
|
189
|
-
* - eventDataSize: Size of the current audio data chunk
|
|
190
|
-
* - totalSize: Total size of recorded audio so far
|
|
191
122
|
* @returns {Subscription} A subscription object that can be used to unsubscribe from the events
|
|
192
|
-
* @throws {Error} If encoded audio data is missing from the event
|
|
193
123
|
*/
|
|
194
124
|
static subscribeToAudioEvents(
|
|
195
125
|
onMicrophoneStream: (event: AudioDataEvent) => Promise<void>
|
|
@@ -213,18 +143,6 @@ export class ExpoPlayAudioStream {
|
|
|
213
143
|
});
|
|
214
144
|
}
|
|
215
145
|
|
|
216
|
-
/**
|
|
217
|
-
* Subscribes to events emitted when a sound chunk has finished playing.
|
|
218
|
-
* @param onSoundChunkPlayed - Callback function that will be called when a sound chunk is played.
|
|
219
|
-
* The callback receives a SoundChunkPlayedEventPayload indicating if this was the final chunk.
|
|
220
|
-
* @returns {Subscription} A subscription object that can be used to unsubscribe from the events.
|
|
221
|
-
*/
|
|
222
|
-
static subscribeToSoundChunkPlayed(
|
|
223
|
-
onSoundChunkPlayed: (event: SoundChunkPlayedEventPayload) => Promise<void>
|
|
224
|
-
): Subscription {
|
|
225
|
-
return addSoundChunkPlayedListener(onSoundChunkPlayed);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
146
|
/**
|
|
229
147
|
* Subscribes to events emitted by the audio stream module, for advanced use cases.
|
|
230
148
|
* @param eventName - The name of the event to subscribe to.
|
|
@@ -238,21 +156,6 @@ export class ExpoPlayAudioStream {
|
|
|
238
156
|
return subscribeToEvent(eventName, onEvent);
|
|
239
157
|
}
|
|
240
158
|
|
|
241
|
-
/**
|
|
242
|
-
* Sets the sound player configuration.
|
|
243
|
-
* @param {SoundConfig} config - Configuration options for the sound player.
|
|
244
|
-
* @returns {Promise<void>}
|
|
245
|
-
* @throws {Error} If the configuration fails to update.
|
|
246
|
-
*/
|
|
247
|
-
static async setSoundConfig(config: SoundConfig): Promise<void> {
|
|
248
|
-
try {
|
|
249
|
-
await ExpoPlayAudioStreamModule.setSoundConfig(config);
|
|
250
|
-
} catch (error) {
|
|
251
|
-
console.error(error);
|
|
252
|
-
throw new Error(`Failed to set sound configuration: ${error}`);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
|
|
256
159
|
/**
|
|
257
160
|
* Prompts the user to select the microphone mode.
|
|
258
161
|
* @returns {Promise<void>}
|
|
@@ -308,15 +211,12 @@ export class ExpoPlayAudioStream {
|
|
|
308
211
|
|
|
309
212
|
export {
|
|
310
213
|
AudioDataEvent,
|
|
311
|
-
SoundChunkPlayedEventPayload,
|
|
312
214
|
DeviceReconnectedReason,
|
|
313
215
|
DeviceReconnectedEventPayload,
|
|
314
216
|
AudioRecording,
|
|
315
217
|
RecordingConfig,
|
|
316
218
|
StartRecordingResult,
|
|
317
219
|
AudioEvents,
|
|
318
|
-
SuspendSoundEventTurnId,
|
|
319
|
-
SoundConfig,
|
|
320
220
|
PlaybackMode,
|
|
321
221
|
Encoding,
|
|
322
222
|
EncodingTypes,
|
package/src/types.ts
CHANGED
|
@@ -16,41 +16,6 @@ export const PlaybackModes = {
|
|
|
16
16
|
export type PlaybackMode =
|
|
17
17
|
(typeof PlaybackModes)[keyof typeof PlaybackModes];
|
|
18
18
|
|
|
19
|
-
/**
|
|
20
|
-
* Configuration for audio playback settings
|
|
21
|
-
*/
|
|
22
|
-
export interface SoundConfig {
|
|
23
|
-
/**
|
|
24
|
-
* The sample rate for audio playback in Hz
|
|
25
|
-
*/
|
|
26
|
-
sampleRate?: SampleRate;
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* The playback mode (regular, voiceProcessing, or conversation)
|
|
30
|
-
*/
|
|
31
|
-
playbackMode?: PlaybackMode;
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* When true, resets to default configuration regardless of other parameters
|
|
35
|
-
*/
|
|
36
|
-
useDefault?: boolean;
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* Enable jitter buffering for audio streams
|
|
40
|
-
*/
|
|
41
|
-
enableBuffering?: boolean;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* Automatically enable buffering based on network conditions
|
|
45
|
-
*/
|
|
46
|
-
autoBuffer?: boolean;
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Configuration for the jitter buffer when enableBuffering is true
|
|
50
|
-
*/
|
|
51
|
-
bufferConfig?: Partial<IAudioBufferConfig>;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
19
|
/**
|
|
55
20
|
* Configuration for buffered audio streaming
|
|
56
21
|
*/
|