@siteed/expo-audio-stream 0.2.2 → 0.2.4
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 +5 -33
- package/package.json +1 -1
- package/plugin/build/index.js +4 -1
- package/plugin/src/index.ts +4 -1
package/README.md
CHANGED
|
@@ -37,6 +37,8 @@ Add the plugin to your app.json like so:
|
|
|
37
37
|
}
|
|
38
38
|
```
|
|
39
39
|
|
|
40
|
+
Make sure to run `npx expo prebuild` after adding the plugin to your app.json file.
|
|
41
|
+
|
|
40
42
|
## Usage
|
|
41
43
|
|
|
42
44
|
The `example/` folder contains a fully functional React Native application that demonstrates how to integrate and use the `@siteed/expo-audio-stream` library in a real-world scenario. This sample application includes features such as starting and stopping audio recordings, handling permissions, and processing live audio data.
|
|
@@ -47,7 +49,7 @@ The `example/` folder contains a fully functional React Native application that
|
|
|
47
49
|
import {
|
|
48
50
|
useAudioRecorder,
|
|
49
51
|
AudioStreamResult,
|
|
50
|
-
} from 'expo-audio-stream';
|
|
52
|
+
} from '@siteed/expo-audio-stream';
|
|
51
53
|
|
|
52
54
|
export default function App() {
|
|
53
55
|
const { startRecording, stopRecording, duration, size, isRecording } = useAudioRecorder({
|
|
@@ -92,41 +94,11 @@ export default function App() {
|
|
|
92
94
|
|
|
93
95
|
The library also exposes an `addAudioEventListener` function that provides an `AudioEventPayload` object that you can subscribe to:
|
|
94
96
|
```tsx
|
|
95
|
-
|
|
96
|
-
encoded?: string,
|
|
97
|
-
buffer?: Blob,
|
|
98
|
-
fileUri: string,
|
|
99
|
-
from: number,
|
|
100
|
-
deltaSize: number,
|
|
101
|
-
totalSize: number,
|
|
102
|
-
mimeType: string;
|
|
103
|
-
streamUuid: string,
|
|
104
|
-
};
|
|
97
|
+
import { addAudioEventListener } from '@siteed/expo-audio-stream';
|
|
105
98
|
|
|
106
99
|
useEffect(() => {
|
|
107
100
|
const subscribe = addAudioEventListener(async ({fileUri, deltaSize, totalSize, from, streamUuid, encoded, mimeType, buffer}) => {
|
|
108
|
-
log(`Received audio event:`, {fileUri, deltaSize, totalSize, mimeType, from, streamUuid, encodedLength: encoded?.length})
|
|
109
|
-
if(deltaSize > 0) {
|
|
110
|
-
// Coming from native ( ios / android ) otherwise buffer is set
|
|
111
|
-
if(Platform.OS !== 'web') {
|
|
112
|
-
// Read the audio file as a base64 string for comparison
|
|
113
|
-
try {
|
|
114
|
-
// convert encoded string to binary data
|
|
115
|
-
const binaryData = atob(encoded);
|
|
116
|
-
const content = new Uint8Array(binaryData.length);
|
|
117
|
-
for (let i = 0; i < binaryData.length; i++) {
|
|
118
|
-
content[i] = binaryData.charCodeAt(i);
|
|
119
|
-
}
|
|
120
|
-
const audioBlob = new Blob([content], { type: mimeType });
|
|
121
|
-
console.info(`Received audio blob:`, audioBlob);
|
|
122
|
-
} catch (error) {
|
|
123
|
-
console.error('Error reading audio file:', error);
|
|
124
|
-
}
|
|
125
|
-
} else if(buffer) {
|
|
126
|
-
// Coming from web
|
|
127
|
-
console.info(`Received audio buffer:`, buffer)
|
|
128
|
-
}
|
|
129
|
-
}
|
|
101
|
+
log(`Received audio event:`, {fileUri, deltaSize, totalSize, mimeType, from, streamUuid, encodedLength: encoded?.length, bufferLength: buffer?.length})
|
|
130
102
|
});
|
|
131
103
|
return () => subscribe.remove();
|
|
132
104
|
}, []);
|
package/package.json
CHANGED
package/plugin/build/index.js
CHANGED
|
@@ -2,7 +2,10 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const config_plugins_1 = require("@expo/config-plugins");
|
|
4
4
|
const MICROPHONE_USAGE = "Allow $(PRODUCT_NAME) to access your microphone";
|
|
5
|
-
const withRecordingPermission = (config,
|
|
5
|
+
const withRecordingPermission = (config, existingPerms) => {
|
|
6
|
+
if (!existingPerms) {
|
|
7
|
+
console.warn("No previous permissions provided");
|
|
8
|
+
}
|
|
6
9
|
config = (0, config_plugins_1.withInfoPlist)(config, (config) => {
|
|
7
10
|
config.modResults["NSMicrophoneUsageDescription"] = MICROPHONE_USAGE;
|
|
8
11
|
return config;
|
package/plugin/src/index.ts
CHANGED
|
@@ -9,7 +9,10 @@ const MICROPHONE_USAGE = "Allow $(PRODUCT_NAME) to access your microphone";
|
|
|
9
9
|
|
|
10
10
|
const withRecordingPermission: ConfigPlugin<{
|
|
11
11
|
microphonePermission: string;
|
|
12
|
-
}> = (config,
|
|
12
|
+
}> = (config, existingPerms) => {
|
|
13
|
+
if (!existingPerms) {
|
|
14
|
+
console.warn("No previous permissions provided");
|
|
15
|
+
}
|
|
13
16
|
config = withInfoPlist(config, (config) => {
|
|
14
17
|
config.modResults["NSMicrophoneUsageDescription"] = MICROPHONE_USAGE;
|
|
15
18
|
return config;
|