@siteed/expo-audio-stream 1.0.3 → 1.1.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/README.md +26 -175
- package/android/src/main/java/net/siteed/audiostream/AudioProcessor.kt +47 -7
- package/android/src/main/java/net/siteed/audiostream/AudioRecorderManager.kt +1 -0
- package/android/src/main/java/net/siteed/audiostream/Constants.kt +5 -0
- package/android/src/main/java/net/siteed/audiostream/ExpoAudioStreamModule.kt +12 -3
- package/build/index.js +8 -7
- package/ios/AudioProcessor.swift +7 -5
- package/ios/AudioStreamManager.swift +1 -0
- package/ios/ExpoAudioStream.podspec +1 -1
- package/ios/ExpoAudioStreamModule.swift +36 -0
- package/ios/RecordingResult.swift +1 -0
- package/package.json +95 -65
- package/src/AudioAnalysis/AudioAnalysis.types.ts +59 -60
- package/src/AudioAnalysis/extractAudioAnalysis.ts +132 -121
- package/src/AudioAnalysis/extractWaveform.ts +18 -18
- package/src/AudioRecorder.provider.tsx +53 -53
- package/src/ExpoAudioStream.native.ts +2 -2
- package/src/ExpoAudioStream.types.ts +59 -53
- package/src/ExpoAudioStream.web.ts +231 -205
- package/src/ExpoAudioStreamModule.ts +22 -15
- package/src/WebRecorder.web.ts +407 -390
- package/src/constants.ts +11 -11
- package/src/events.ts +27 -13
- package/src/index.ts +17 -15
- package/src/logger.ts +15 -19
- package/src/useAudioRecorder.tsx +394 -389
- package/src/utils/BlobFix.ts +550 -0
- package/src/utils/concatenateBuffers.ts +24 -0
- package/src/utils/convertPCMToFloat32.ts +72 -45
- package/src/utils/encodingToBitDepth.ts +14 -14
- package/src/utils/getWavFileInfo.ts +106 -99
- package/src/utils/writeWavHeader.ts +50 -45
- package/src/workers/InlineFeaturesExtractor.web.tsx +296 -286
- package/src/workers/inlineAudioWebWorker.web.tsx +230 -222
- package/.eslintrc.js +0 -2
- package/.size-limit.json +0 -6
- package/android/.gradle/8.1.1/checksums/checksums.lock +0 -0
- package/android/.gradle/8.1.1/dependencies-accessors/dependencies-accessors.lock +0 -0
- package/android/.gradle/8.1.1/dependencies-accessors/gc.properties +0 -0
- package/android/.gradle/8.1.1/fileChanges/last-build.bin +0 -0
- package/android/.gradle/8.1.1/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/8.1.1/gc.properties +0 -0
- package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
- package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/app.plugin.js +0 -1
- package/build/AudioAnalysis/AudioAnalysis.types.d.ts +0 -76
- package/build/AudioAnalysis/AudioAnalysis.types.d.ts.map +0 -1
- package/build/AudioAnalysis/AudioAnalysis.types.js +0 -3
- package/build/AudioAnalysis/AudioAnalysis.types.js.map +0 -1
- package/build/AudioAnalysis/extractAudioAnalysis.d.ts +0 -4
- package/build/AudioAnalysis/extractAudioAnalysis.d.ts.map +0 -1
- package/build/AudioAnalysis/extractAudioAnalysis.js +0 -101
- package/build/AudioAnalysis/extractAudioAnalysis.js.map +0 -1
- package/build/AudioAnalysis/extractWaveform.d.ts +0 -8
- package/build/AudioAnalysis/extractWaveform.d.ts.map +0 -1
- package/build/AudioAnalysis/extractWaveform.js +0 -14
- package/build/AudioAnalysis/extractWaveform.js.map +0 -1
- package/build/AudioRecorder.provider.d.ts +0 -23
- package/build/AudioRecorder.provider.d.ts.map +0 -1
- package/build/AudioRecorder.provider.js +0 -36
- package/build/AudioRecorder.provider.js.map +0 -1
- package/build/ExpoAudioStream.native.d.ts +0 -3
- package/build/ExpoAudioStream.native.d.ts.map +0 -1
- package/build/ExpoAudioStream.native.js +0 -6
- package/build/ExpoAudioStream.native.js.map +0 -1
- package/build/ExpoAudioStream.types.d.ts +0 -60
- package/build/ExpoAudioStream.types.d.ts.map +0 -1
- package/build/ExpoAudioStream.types.js +0 -2
- package/build/ExpoAudioStream.types.js.map +0 -1
- package/build/ExpoAudioStream.web.d.ts +0 -42
- package/build/ExpoAudioStream.web.d.ts.map +0 -1
- package/build/ExpoAudioStream.web.js +0 -185
- package/build/ExpoAudioStream.web.js.map +0 -1
- package/build/ExpoAudioStreamModule.d.ts +0 -3
- package/build/ExpoAudioStreamModule.d.ts.map +0 -1
- package/build/ExpoAudioStreamModule.js +0 -18
- package/build/ExpoAudioStreamModule.js.map +0 -1
- package/build/WebRecorder.web.d.ts +0 -51
- package/build/WebRecorder.web.d.ts.map +0 -1
- package/build/WebRecorder.web.js +0 -288
- package/build/WebRecorder.web.js.map +0 -1
- package/build/constants.d.ts +0 -11
- package/build/constants.d.ts.map +0 -1
- package/build/constants.js +0 -14
- package/build/constants.js.map +0 -1
- package/build/events.d.ts +0 -6
- package/build/events.d.ts.map +0 -1
- package/build/events.js +0 -15
- package/build/events.js.map +0 -1
- package/build/index.d.ts +0 -10
- package/build/index.d.ts.map +0 -1
- package/build/index.js.map +0 -1
- package/build/logger.d.ts +0 -9
- package/build/logger.d.ts.map +0 -1
- package/build/logger.js +0 -17
- package/build/logger.js.map +0 -1
- package/build/useAudioRecorder.d.ts +0 -37
- package/build/useAudioRecorder.d.ts.map +0 -1
- package/build/useAudioRecorder.js +0 -271
- package/build/useAudioRecorder.js.map +0 -1
- package/build/utils/convertPCMToFloat32.d.ts +0 -11
- package/build/utils/convertPCMToFloat32.d.ts.map +0 -1
- package/build/utils/convertPCMToFloat32.js +0 -41
- package/build/utils/convertPCMToFloat32.js.map +0 -1
- package/build/utils/encodingToBitDepth.d.ts +0 -5
- package/build/utils/encodingToBitDepth.d.ts.map +0 -1
- package/build/utils/encodingToBitDepth.js +0 -13
- package/build/utils/encodingToBitDepth.js.map +0 -1
- package/build/utils/getWavFileInfo.d.ts +0 -25
- package/build/utils/getWavFileInfo.d.ts.map +0 -1
- package/build/utils/getWavFileInfo.js +0 -89
- package/build/utils/getWavFileInfo.js.map +0 -1
- package/build/utils/writeWavHeader.d.ts +0 -9
- package/build/utils/writeWavHeader.d.ts.map +0 -1
- package/build/utils/writeWavHeader.js +0 -41
- package/build/utils/writeWavHeader.js.map +0 -1
- package/build/workers/InlineFeaturesExtractor.web.d.ts +0 -2
- package/build/workers/InlineFeaturesExtractor.web.d.ts.map +0 -1
- package/build/workers/InlineFeaturesExtractor.web.js +0 -303
- package/build/workers/InlineFeaturesExtractor.web.js.map +0 -1
- package/build/workers/inlineAudioWebWorker.web.d.ts +0 -2
- package/build/workers/inlineAudioWebWorker.web.d.ts.map +0 -1
- package/build/workers/inlineAudioWebWorker.web.js +0 -243
- package/build/workers/inlineAudioWebWorker.web.js.map +0 -1
- package/expo-module.config.json +0 -18
- package/plugin/build/index.d.ts +0 -5
- package/plugin/build/index.js +0 -28
- package/plugin/src/index.ts +0 -53
- package/plugin/tsconfig.json +0 -14
- package/publish.sh +0 -8
- package/tsconfig.json +0 -9
|
@@ -4,82 +4,81 @@
|
|
|
4
4
|
* Represents various audio features extracted from an audio signal.
|
|
5
5
|
*/
|
|
6
6
|
export interface AudioFeatures {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
7
|
+
energy: number // The infinite integral of the squared signal, representing the overall energy of the audio.
|
|
8
|
+
mfcc: number[] // Mel-frequency cepstral coefficients, describing the short-term power spectrum of a sound.
|
|
9
|
+
rms: number // Root mean square value, indicating the amplitude of the audio signal.
|
|
10
|
+
minAmplitude: number // Minimum amplitude value in the audio signal.
|
|
11
|
+
maxAmplitude: number // Maximum amplitude value in the audio signal.
|
|
12
|
+
zcr: number // Zero-crossing rate, indicating the rate at which the signal changes sign.
|
|
13
|
+
spectralCentroid: number // The center of mass of the spectrum, indicating the brightness of the sound.
|
|
14
|
+
spectralFlatness: number // Measure of the flatness of the spectrum, indicating how noise-like the signal is.
|
|
15
|
+
spectralRolloff: number // The frequency below which a specified percentage (usually 85%) of the total spectral energy lies.
|
|
16
|
+
spectralBandwidth: number // The width of the spectrum, indicating the range of frequencies present.
|
|
17
|
+
chromagram: number[] // Chromagram, representing the 12 different pitch classes of the audio.
|
|
18
|
+
tempo: number // Estimated tempo of the audio signal, measured in beats per minute (BPM).
|
|
19
|
+
hnr: number // Harmonics-to-noise ratio, indicating the proportion of harmonics to noise in the audio signal.
|
|
20
20
|
}
|
|
21
21
|
|
|
22
22
|
/**
|
|
23
23
|
* Options to specify which audio features to extract.
|
|
24
24
|
*/
|
|
25
25
|
export interface AudioFeaturesOptions {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
26
|
+
energy?: boolean
|
|
27
|
+
mfcc?: boolean
|
|
28
|
+
rms?: boolean
|
|
29
|
+
zcr?: boolean
|
|
30
|
+
spectralCentroid?: boolean
|
|
31
|
+
spectralFlatness?: boolean
|
|
32
|
+
spectralRolloff?: boolean
|
|
33
|
+
spectralBandwidth?: boolean
|
|
34
|
+
chromagram?: boolean
|
|
35
|
+
tempo?: boolean
|
|
36
|
+
hnr?: boolean
|
|
37
37
|
}
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* Represents a single data point in the audio analysis.
|
|
41
41
|
*/
|
|
42
42
|
export interface DataPoint {
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
43
|
+
id: number
|
|
44
|
+
amplitude: number
|
|
45
|
+
activeSpeech?: boolean
|
|
46
|
+
dB?: number
|
|
47
|
+
silent?: boolean
|
|
48
|
+
features?: AudioFeatures
|
|
49
|
+
startTime?: number
|
|
50
|
+
endTime?: number
|
|
51
|
+
// start / end position in bytes
|
|
52
|
+
startPosition?: number
|
|
53
|
+
endPosition?: number
|
|
54
|
+
// number of audio samples for this point (samples size depends on bit depth)
|
|
55
|
+
samples?: number
|
|
56
|
+
// TODO: speaker detection
|
|
57
|
+
speaker?: number
|
|
58
58
|
}
|
|
59
59
|
|
|
60
|
+
export type AmplitudeAlgorithm = 'peak' | 'rms'
|
|
61
|
+
|
|
60
62
|
/**
|
|
61
63
|
* Represents the complete data from the audio analysis.
|
|
62
64
|
*/
|
|
63
|
-
export interface
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
65
|
+
export interface AudioAnalysis {
|
|
66
|
+
pointsPerSecond: number // How many consolidated value per second
|
|
67
|
+
durationMs: number // Duration of the audio in milliseconds
|
|
68
|
+
bitDepth: number // Bit depth of the audio
|
|
69
|
+
samples: number // Size of the audio in bytes
|
|
70
|
+
numberOfChannels: number // Number of audio channels
|
|
71
|
+
sampleRate: number // Sample rate of the audio
|
|
72
|
+
dataPoints: DataPoint[] // Array of data points from the analysis.
|
|
73
|
+
amplitudeAlgorithm: AmplitudeAlgorithm // Algorithm used to calculate amplitude values.
|
|
74
|
+
amplitudeRange: {
|
|
75
|
+
min: number
|
|
76
|
+
max: number
|
|
77
|
+
}
|
|
78
|
+
// TODO: speaker detection
|
|
79
|
+
speakerChanges?: {
|
|
80
|
+
timestamp: number // Timestamp of the speaker change in milliseconds.
|
|
81
|
+
speaker: number // Speaker identifier.
|
|
82
|
+
}[]
|
|
80
83
|
}
|
|
81
84
|
|
|
82
|
-
export interface AudioAnalysisEventPayload {
|
|
83
|
-
analysis: AudioAnalysisData;
|
|
84
|
-
visualizationDuration: number;
|
|
85
|
-
}
|
|
@@ -1,136 +1,147 @@
|
|
|
1
1
|
// packages/expo-audio-stream/src/AudioAnalysis/extractAudioAnalysis.ts
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
AmplitudeAlgorithm,
|
|
4
|
+
AudioAnalysis,
|
|
5
|
+
AudioFeaturesOptions,
|
|
6
|
+
} from './AudioAnalysis.types'
|
|
7
|
+
import ExpoAudioStreamModule from '../ExpoAudioStreamModule'
|
|
8
|
+
import { isWeb } from '../constants'
|
|
9
|
+
import { getLogger } from '../logger'
|
|
10
|
+
import { convertPCMToFloat32 } from '../utils/convertPCMToFloat32'
|
|
11
|
+
import { getWavFileInfo, WavFileInfo } from '../utils/getWavFileInfo'
|
|
12
|
+
import { InlineFeaturesExtractor } from '../workers/InlineFeaturesExtractor.web'
|
|
10
13
|
|
|
11
|
-
const logger = getLogger(
|
|
14
|
+
const logger = getLogger('extractAudioAnalysis')
|
|
15
|
+
|
|
16
|
+
export interface ExtractAudioAnalysisProps {
|
|
17
|
+
fileUri?: string // should provide either fileUri or arrayBuffer
|
|
18
|
+
wavMetadata?: WavFileInfo
|
|
19
|
+
arrayBuffer?: ArrayBuffer
|
|
20
|
+
bitDepth?: number
|
|
21
|
+
skipWavHeader?: boolean
|
|
22
|
+
durationMs?: number
|
|
23
|
+
sampleRate?: number
|
|
24
|
+
numberOfChannels?: number
|
|
25
|
+
algorithm?: AmplitudeAlgorithm
|
|
26
|
+
position?: number // Optional number of bytes to skip. Default is 0
|
|
27
|
+
length?: number // Optional number of bytes to read.
|
|
28
|
+
pointsPerSecond?: number // Optional number of points per second. Use to reduce the number of points and compute the number of datapoints to return.
|
|
29
|
+
features?: AudioFeaturesOptions
|
|
30
|
+
featuresExtratorUrl?: string
|
|
31
|
+
}
|
|
12
32
|
|
|
13
33
|
export const extractAudioAnalysis = async ({
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}:
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
34
|
+
fileUri,
|
|
35
|
+
pointsPerSecond = 20,
|
|
36
|
+
arrayBuffer,
|
|
37
|
+
bitDepth,
|
|
38
|
+
skipWavHeader = true,
|
|
39
|
+
durationMs,
|
|
40
|
+
sampleRate,
|
|
41
|
+
numberOfChannels,
|
|
42
|
+
algorithm = 'rms',
|
|
43
|
+
features,
|
|
44
|
+
featuresExtratorUrl,
|
|
45
|
+
}: ExtractAudioAnalysisProps): Promise<AudioAnalysis> => {
|
|
46
|
+
if (isWeb) {
|
|
47
|
+
if (!arrayBuffer && !fileUri) {
|
|
48
|
+
throw new Error('Either arrayBuffer or fileUri must be provided')
|
|
49
|
+
}
|
|
30
50
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
51
|
+
if (!arrayBuffer) {
|
|
52
|
+
logger.log(`fetching fileUri`, fileUri)
|
|
53
|
+
const response = await fetch(fileUri!)
|
|
34
54
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
55
|
+
if (!response.ok) {
|
|
56
|
+
throw new Error(
|
|
57
|
+
`Failed to fetch fileUri: ${response.statusText}`
|
|
58
|
+
)
|
|
59
|
+
}
|
|
38
60
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
61
|
+
arrayBuffer = await response.arrayBuffer()
|
|
62
|
+
logger.log(`fetched fileUri`, arrayBuffer.byteLength, arrayBuffer)
|
|
63
|
+
}
|
|
42
64
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
65
|
+
// Create a new copy of the ArrayBuffer to avoid detachment issues
|
|
66
|
+
const bufferCopy = arrayBuffer.slice(0)
|
|
67
|
+
logger.log(
|
|
68
|
+
`extractAudioAnalysis skipWavHeader=${skipWavHeader} bitDepth=${bitDepth} len=${bufferCopy.byteLength}`,
|
|
69
|
+
bufferCopy.slice(0, 100)
|
|
70
|
+
)
|
|
49
71
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
// let copyChannelData: Float32Array;
|
|
60
|
-
// try {
|
|
61
|
-
// const audioContext = new (window.AudioContext ||
|
|
62
|
-
// // @ts-ignore
|
|
63
|
-
// window.webkitAudioContext)();
|
|
64
|
-
// const audioBuffer = await audioContext.decodeAudioData(bufferCopy);
|
|
65
|
-
// const channelData = audioBuffer.getChannelData(0); // Use only the first channel
|
|
66
|
-
// copyChannelData = new Float32Array(channelData); // Create a new Float32Array
|
|
67
|
-
// } catch (error) {
|
|
68
|
-
// console.warn("Failed to decode audio data:", error);
|
|
69
|
-
// // Fall back to creating a new Float32Array from the ArrayBuffer if decoding fails
|
|
70
|
-
// copyChannelData = new Float32Array(arrayBuffer);
|
|
71
|
-
// }
|
|
72
|
+
let actualBitDepth = bitDepth
|
|
73
|
+
if (!actualBitDepth) {
|
|
74
|
+
logger.log(
|
|
75
|
+
`extractAudioAnalysis bitDepth not provided -- getting wav file info`
|
|
76
|
+
)
|
|
77
|
+
const fileInfo = await getWavFileInfo(bufferCopy)
|
|
78
|
+
actualBitDepth = fileInfo.bitDepth
|
|
79
|
+
}
|
|
80
|
+
logger.log(`extractAudioAnalysis actualBitDepth=${actualBitDepth}`)
|
|
72
81
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
82
|
+
const {
|
|
83
|
+
pcmValues: channelData,
|
|
84
|
+
min,
|
|
85
|
+
max,
|
|
86
|
+
} = await convertPCMToFloat32({
|
|
87
|
+
buffer: arrayBuffer,
|
|
88
|
+
bitDepth: actualBitDepth,
|
|
89
|
+
skipWavHeader,
|
|
90
|
+
})
|
|
91
|
+
logger.log(
|
|
92
|
+
`extractAudioAnalysis skipWaveHeader=${skipWavHeader} convertPCMToFloat32 length=${channelData.length} range: [ ${min} :: ${max} ]`
|
|
93
|
+
)
|
|
85
94
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
95
|
+
return new Promise((resolve, reject) => {
|
|
96
|
+
let worker: Worker
|
|
97
|
+
if (featuresExtratorUrl) {
|
|
98
|
+
worker = new Worker(
|
|
99
|
+
new URL(featuresExtratorUrl, window.location.href)
|
|
100
|
+
)
|
|
101
|
+
} else {
|
|
102
|
+
const blob = new Blob([InlineFeaturesExtractor], {
|
|
103
|
+
type: 'application/javascript',
|
|
104
|
+
})
|
|
105
|
+
const url = URL.createObjectURL(blob)
|
|
106
|
+
worker = new Worker(url)
|
|
107
|
+
}
|
|
97
108
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
109
|
+
worker.onmessage = (event) => {
|
|
110
|
+
resolve(event.data.result)
|
|
111
|
+
}
|
|
101
112
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
113
|
+
worker.onerror = (error) => {
|
|
114
|
+
reject(error)
|
|
115
|
+
}
|
|
105
116
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
117
|
+
worker.postMessage({
|
|
118
|
+
command: 'process',
|
|
119
|
+
channelData,
|
|
120
|
+
sampleRate,
|
|
121
|
+
pointsPerSecond,
|
|
122
|
+
algorithm,
|
|
123
|
+
bitDepth,
|
|
124
|
+
fullAudioDurationMs: durationMs,
|
|
125
|
+
numberOfChannels,
|
|
126
|
+
})
|
|
127
|
+
})
|
|
128
|
+
} else {
|
|
129
|
+
if (!fileUri) {
|
|
130
|
+
throw new Error('fileUri is required')
|
|
131
|
+
}
|
|
132
|
+
logger.log(`extractAudioAnalysis`, {
|
|
133
|
+
fileUri,
|
|
134
|
+
pointsPerSecond,
|
|
135
|
+
algorithm,
|
|
136
|
+
})
|
|
137
|
+
const res = await ExpoAudioStreamModule.extractAudioAnalysis({
|
|
138
|
+
fileUri,
|
|
139
|
+
pointsPerSecond,
|
|
140
|
+
skipWavHeader,
|
|
141
|
+
algorithm,
|
|
142
|
+
features,
|
|
143
|
+
})
|
|
144
|
+
logger.log(`extractAudioAnalysis`, res)
|
|
145
|
+
return res
|
|
120
146
|
}
|
|
121
|
-
|
|
122
|
-
fileUri,
|
|
123
|
-
pointsPerSecond,
|
|
124
|
-
algorithm,
|
|
125
|
-
});
|
|
126
|
-
const res = await ExpoAudioStreamModule.extractAudioAnalysis({
|
|
127
|
-
fileUri,
|
|
128
|
-
pointsPerSecond,
|
|
129
|
-
skipWavHeader,
|
|
130
|
-
algorithm,
|
|
131
|
-
features,
|
|
132
|
-
});
|
|
133
|
-
logger.log(`extractAudioAnalysis`, res);
|
|
134
|
-
return res;
|
|
135
|
-
}
|
|
136
|
-
};
|
|
147
|
+
}
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import ExpoAudioStreamModule from
|
|
2
|
-
import { getLogger } from
|
|
1
|
+
import ExpoAudioStreamModule from '../ExpoAudioStreamModule'
|
|
2
|
+
import { getLogger } from '../logger'
|
|
3
3
|
|
|
4
|
-
const logger = getLogger(
|
|
4
|
+
const logger = getLogger('extractWaveform')
|
|
5
5
|
export interface ExtractWaveformProps {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
fileUri: string
|
|
7
|
+
numberOfSamples: number
|
|
8
|
+
offset?: number
|
|
9
|
+
length?: number
|
|
10
10
|
}
|
|
11
11
|
export const extractWaveform = async ({
|
|
12
|
-
fileUri,
|
|
13
|
-
numberOfSamples,
|
|
14
|
-
offset = 0,
|
|
15
|
-
length,
|
|
16
|
-
}: ExtractWaveformProps): Promise<unknown> => {
|
|
17
|
-
const res = await ExpoAudioStreamModule.extractAudioAnalysis({
|
|
18
12
|
fileUri,
|
|
19
13
|
numberOfSamples,
|
|
20
|
-
offset,
|
|
14
|
+
offset = 0,
|
|
21
15
|
length,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
}: ExtractWaveformProps): Promise<unknown> => {
|
|
17
|
+
const res = await ExpoAudioStreamModule.extractAudioAnalysis({
|
|
18
|
+
fileUri,
|
|
19
|
+
numberOfSamples,
|
|
20
|
+
offset,
|
|
21
|
+
length,
|
|
22
|
+
})
|
|
23
|
+
logger.log(`extractWaveform`, res)
|
|
24
|
+
return res
|
|
25
|
+
}
|
|
@@ -1,70 +1,70 @@
|
|
|
1
1
|
// packages/expo-audio-stream/src/AudioRecorder.provider.tsx
|
|
2
|
-
import React, { createContext, useContext } from
|
|
2
|
+
import React, { createContext, useContext } from 'react'
|
|
3
3
|
|
|
4
|
-
import {
|
|
4
|
+
import { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types'
|
|
5
5
|
import {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
} from
|
|
10
|
-
import { UseAudioRecorderProps, useAudioRecorder } from
|
|
6
|
+
AudioRecording,
|
|
7
|
+
RecordingConfig,
|
|
8
|
+
StartRecordingResult,
|
|
9
|
+
} from './ExpoAudioStream.types'
|
|
10
|
+
import { UseAudioRecorderProps, useAudioRecorder } from './useAudioRecorder'
|
|
11
11
|
|
|
12
12
|
export interface UseAudioRecorderState {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
13
|
+
startRecording: (_: RecordingConfig) => Promise<StartRecordingResult>
|
|
14
|
+
stopRecording: () => Promise<AudioRecording | null>
|
|
15
|
+
pauseRecording: () => void
|
|
16
|
+
resumeRecording: () => void
|
|
17
|
+
isRecording: boolean
|
|
18
|
+
isPaused: boolean
|
|
19
|
+
durationMs: number // Duration of the recording
|
|
20
|
+
size: number // Size in bytes of the recorded audio
|
|
21
|
+
analysisData?: AudioAnalysis // Analysis data for the recording depending on enableProcessing flag
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
const initContext: UseAudioRecorderState = {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
}
|
|
25
|
+
isRecording: false,
|
|
26
|
+
isPaused: false,
|
|
27
|
+
durationMs: 0,
|
|
28
|
+
size: 0,
|
|
29
|
+
startRecording: async () => {
|
|
30
|
+
throw new Error('AudioRecorderProvider not found')
|
|
31
|
+
},
|
|
32
|
+
stopRecording: async () => {
|
|
33
|
+
throw new Error('AudioRecorderProvider not found')
|
|
34
|
+
},
|
|
35
|
+
pauseRecording: () => {
|
|
36
|
+
throw new Error('AudioRecorderProvider not found')
|
|
37
|
+
},
|
|
38
|
+
resumeRecording: () => {
|
|
39
|
+
throw new Error('AudioRecorderProvider not found')
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
42
|
|
|
43
|
-
const AudioRecorderContext = createContext<UseAudioRecorderState>(initContext)
|
|
43
|
+
const AudioRecorderContext = createContext<UseAudioRecorderState>(initContext)
|
|
44
44
|
|
|
45
45
|
interface AudioRecorderProviderProps {
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
children: React.ReactNode
|
|
47
|
+
config?: UseAudioRecorderProps
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
export const AudioRecorderProvider: React.FC<AudioRecorderProviderProps> = ({
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
children,
|
|
52
|
+
config = {},
|
|
53
53
|
}) => {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
54
|
+
const audioRecorder = useAudioRecorder(config)
|
|
55
|
+
return (
|
|
56
|
+
<AudioRecorderContext.Provider value={audioRecorder}>
|
|
57
|
+
{children}
|
|
58
|
+
</AudioRecorderContext.Provider>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
61
61
|
|
|
62
62
|
export const useSharedAudioRecorder = () => {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
}
|
|
63
|
+
const context = useContext(AudioRecorderContext)
|
|
64
|
+
if (!context) {
|
|
65
|
+
throw new Error(
|
|
66
|
+
'useSharedAudioRecorder must be used within an AudioRecorderProvider'
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
return context
|
|
70
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/ExpoAudioStreamModule.ts
|
|
2
|
-
import { requireNativeModule } from
|
|
2
|
+
import { requireNativeModule } from 'expo-modules-core'
|
|
3
3
|
|
|
4
4
|
// It loads the native module object from the JSI or falls back to
|
|
5
5
|
// the bridge module (from NativeModulesProxy) if the remote debugger is on.
|
|
6
|
-
export default requireNativeModule(
|
|
6
|
+
export default requireNativeModule('ExpoAudioStream')
|