@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.
Files changed (132) hide show
  1. package/README.md +26 -175
  2. package/android/src/main/java/net/siteed/audiostream/AudioProcessor.kt +47 -7
  3. package/android/src/main/java/net/siteed/audiostream/AudioRecorderManager.kt +1 -0
  4. package/android/src/main/java/net/siteed/audiostream/Constants.kt +5 -0
  5. package/android/src/main/java/net/siteed/audiostream/ExpoAudioStreamModule.kt +12 -3
  6. package/build/index.js +8 -7
  7. package/ios/AudioProcessor.swift +7 -5
  8. package/ios/AudioStreamManager.swift +1 -0
  9. package/ios/ExpoAudioStream.podspec +1 -1
  10. package/ios/ExpoAudioStreamModule.swift +36 -0
  11. package/ios/RecordingResult.swift +1 -0
  12. package/package.json +95 -65
  13. package/src/AudioAnalysis/AudioAnalysis.types.ts +59 -60
  14. package/src/AudioAnalysis/extractAudioAnalysis.ts +132 -121
  15. package/src/AudioAnalysis/extractWaveform.ts +18 -18
  16. package/src/AudioRecorder.provider.tsx +53 -53
  17. package/src/ExpoAudioStream.native.ts +2 -2
  18. package/src/ExpoAudioStream.types.ts +59 -53
  19. package/src/ExpoAudioStream.web.ts +231 -205
  20. package/src/ExpoAudioStreamModule.ts +22 -15
  21. package/src/WebRecorder.web.ts +407 -390
  22. package/src/constants.ts +11 -11
  23. package/src/events.ts +27 -13
  24. package/src/index.ts +17 -15
  25. package/src/logger.ts +15 -19
  26. package/src/useAudioRecorder.tsx +394 -389
  27. package/src/utils/BlobFix.ts +550 -0
  28. package/src/utils/concatenateBuffers.ts +24 -0
  29. package/src/utils/convertPCMToFloat32.ts +72 -45
  30. package/src/utils/encodingToBitDepth.ts +14 -14
  31. package/src/utils/getWavFileInfo.ts +106 -99
  32. package/src/utils/writeWavHeader.ts +50 -45
  33. package/src/workers/InlineFeaturesExtractor.web.tsx +296 -286
  34. package/src/workers/inlineAudioWebWorker.web.tsx +230 -222
  35. package/.eslintrc.js +0 -2
  36. package/.size-limit.json +0 -6
  37. package/android/.gradle/8.1.1/checksums/checksums.lock +0 -0
  38. package/android/.gradle/8.1.1/dependencies-accessors/dependencies-accessors.lock +0 -0
  39. package/android/.gradle/8.1.1/dependencies-accessors/gc.properties +0 -0
  40. package/android/.gradle/8.1.1/fileChanges/last-build.bin +0 -0
  41. package/android/.gradle/8.1.1/fileHashes/fileHashes.lock +0 -0
  42. package/android/.gradle/8.1.1/gc.properties +0 -0
  43. package/android/.gradle/buildOutputCleanup/buildOutputCleanup.lock +0 -0
  44. package/android/.gradle/buildOutputCleanup/cache.properties +0 -2
  45. package/android/.gradle/vcs-1/gc.properties +0 -0
  46. package/app.plugin.js +0 -1
  47. package/build/AudioAnalysis/AudioAnalysis.types.d.ts +0 -76
  48. package/build/AudioAnalysis/AudioAnalysis.types.d.ts.map +0 -1
  49. package/build/AudioAnalysis/AudioAnalysis.types.js +0 -3
  50. package/build/AudioAnalysis/AudioAnalysis.types.js.map +0 -1
  51. package/build/AudioAnalysis/extractAudioAnalysis.d.ts +0 -4
  52. package/build/AudioAnalysis/extractAudioAnalysis.d.ts.map +0 -1
  53. package/build/AudioAnalysis/extractAudioAnalysis.js +0 -101
  54. package/build/AudioAnalysis/extractAudioAnalysis.js.map +0 -1
  55. package/build/AudioAnalysis/extractWaveform.d.ts +0 -8
  56. package/build/AudioAnalysis/extractWaveform.d.ts.map +0 -1
  57. package/build/AudioAnalysis/extractWaveform.js +0 -14
  58. package/build/AudioAnalysis/extractWaveform.js.map +0 -1
  59. package/build/AudioRecorder.provider.d.ts +0 -23
  60. package/build/AudioRecorder.provider.d.ts.map +0 -1
  61. package/build/AudioRecorder.provider.js +0 -36
  62. package/build/AudioRecorder.provider.js.map +0 -1
  63. package/build/ExpoAudioStream.native.d.ts +0 -3
  64. package/build/ExpoAudioStream.native.d.ts.map +0 -1
  65. package/build/ExpoAudioStream.native.js +0 -6
  66. package/build/ExpoAudioStream.native.js.map +0 -1
  67. package/build/ExpoAudioStream.types.d.ts +0 -60
  68. package/build/ExpoAudioStream.types.d.ts.map +0 -1
  69. package/build/ExpoAudioStream.types.js +0 -2
  70. package/build/ExpoAudioStream.types.js.map +0 -1
  71. package/build/ExpoAudioStream.web.d.ts +0 -42
  72. package/build/ExpoAudioStream.web.d.ts.map +0 -1
  73. package/build/ExpoAudioStream.web.js +0 -185
  74. package/build/ExpoAudioStream.web.js.map +0 -1
  75. package/build/ExpoAudioStreamModule.d.ts +0 -3
  76. package/build/ExpoAudioStreamModule.d.ts.map +0 -1
  77. package/build/ExpoAudioStreamModule.js +0 -18
  78. package/build/ExpoAudioStreamModule.js.map +0 -1
  79. package/build/WebRecorder.web.d.ts +0 -51
  80. package/build/WebRecorder.web.d.ts.map +0 -1
  81. package/build/WebRecorder.web.js +0 -288
  82. package/build/WebRecorder.web.js.map +0 -1
  83. package/build/constants.d.ts +0 -11
  84. package/build/constants.d.ts.map +0 -1
  85. package/build/constants.js +0 -14
  86. package/build/constants.js.map +0 -1
  87. package/build/events.d.ts +0 -6
  88. package/build/events.d.ts.map +0 -1
  89. package/build/events.js +0 -15
  90. package/build/events.js.map +0 -1
  91. package/build/index.d.ts +0 -10
  92. package/build/index.d.ts.map +0 -1
  93. package/build/index.js.map +0 -1
  94. package/build/logger.d.ts +0 -9
  95. package/build/logger.d.ts.map +0 -1
  96. package/build/logger.js +0 -17
  97. package/build/logger.js.map +0 -1
  98. package/build/useAudioRecorder.d.ts +0 -37
  99. package/build/useAudioRecorder.d.ts.map +0 -1
  100. package/build/useAudioRecorder.js +0 -271
  101. package/build/useAudioRecorder.js.map +0 -1
  102. package/build/utils/convertPCMToFloat32.d.ts +0 -11
  103. package/build/utils/convertPCMToFloat32.d.ts.map +0 -1
  104. package/build/utils/convertPCMToFloat32.js +0 -41
  105. package/build/utils/convertPCMToFloat32.js.map +0 -1
  106. package/build/utils/encodingToBitDepth.d.ts +0 -5
  107. package/build/utils/encodingToBitDepth.d.ts.map +0 -1
  108. package/build/utils/encodingToBitDepth.js +0 -13
  109. package/build/utils/encodingToBitDepth.js.map +0 -1
  110. package/build/utils/getWavFileInfo.d.ts +0 -25
  111. package/build/utils/getWavFileInfo.d.ts.map +0 -1
  112. package/build/utils/getWavFileInfo.js +0 -89
  113. package/build/utils/getWavFileInfo.js.map +0 -1
  114. package/build/utils/writeWavHeader.d.ts +0 -9
  115. package/build/utils/writeWavHeader.d.ts.map +0 -1
  116. package/build/utils/writeWavHeader.js +0 -41
  117. package/build/utils/writeWavHeader.js.map +0 -1
  118. package/build/workers/InlineFeaturesExtractor.web.d.ts +0 -2
  119. package/build/workers/InlineFeaturesExtractor.web.d.ts.map +0 -1
  120. package/build/workers/InlineFeaturesExtractor.web.js +0 -303
  121. package/build/workers/InlineFeaturesExtractor.web.js.map +0 -1
  122. package/build/workers/inlineAudioWebWorker.web.d.ts +0 -2
  123. package/build/workers/inlineAudioWebWorker.web.d.ts.map +0 -1
  124. package/build/workers/inlineAudioWebWorker.web.js +0 -243
  125. package/build/workers/inlineAudioWebWorker.web.js.map +0 -1
  126. package/expo-module.config.json +0 -18
  127. package/plugin/build/index.d.ts +0 -5
  128. package/plugin/build/index.js +0 -28
  129. package/plugin/src/index.ts +0 -53
  130. package/plugin/tsconfig.json +0 -14
  131. package/publish.sh +0 -8
  132. 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
- 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.
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
- 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;
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
- 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;
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 AudioAnalysisData {
64
- pointsPerSecond: number; // How many consolidated value per second
65
- durationMs: number; // Duration of the audio in milliseconds
66
- bitDepth: number; // Bit depth of the audio
67
- samples: number; // Size of the audio in bytes
68
- numberOfChannels: number; // Number of audio channels
69
- sampleRate: number; // Sample rate of the audio
70
- dataPoints: DataPoint[]; // Array of data points from the analysis.
71
- amplitudeRange: {
72
- min: number;
73
- max: number;
74
- };
75
- // TODO: speaker detection
76
- speakerChanges?: {
77
- timestamp: number; // Timestamp of the speaker change in milliseconds.
78
- speaker: number; // Speaker identifier.
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 { AudioAnalysisData } from "./AudioAnalysis.types";
3
- import ExpoAudioStreamModule from "../ExpoAudioStreamModule";
4
- import { isWeb } from "../constants";
5
- import { getLogger } from "../logger";
6
- import { ExtractMetadataProps } from "../useAudioRecorder";
7
- import { convertPCMToFloat32 } from "../utils/convertPCMToFloat32";
8
- import { getWavFileInfo } from "../utils/getWavFileInfo";
9
- import { InlineFeaturesExtractor } from "../workers/InlineFeaturesExtractor.web";
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("extractAudioAnalysis");
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
- fileUri,
15
- pointsPerSecond = 20,
16
- arrayBuffer,
17
- bitDepth,
18
- skipWavHeader,
19
- durationMs,
20
- sampleRate,
21
- numberOfChannels,
22
- algorithm = "rms",
23
- features,
24
- featuresExtratorUrl,
25
- }: ExtractMetadataProps): Promise<AudioAnalysisData> => {
26
- if (isWeb) {
27
- if (!arrayBuffer && !fileUri) {
28
- throw new Error("Either arrayBuffer or fileUri must be provided");
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
- if (!arrayBuffer) {
32
- logger.log(`fetching fileUri`, fileUri);
33
- const response = await fetch(fileUri!);
51
+ if (!arrayBuffer) {
52
+ logger.log(`fetching fileUri`, fileUri)
53
+ const response = await fetch(fileUri!)
34
54
 
35
- if (!response.ok) {
36
- throw new Error(`Failed to fetch fileUri: ${response.statusText}`);
37
- }
55
+ if (!response.ok) {
56
+ throw new Error(
57
+ `Failed to fetch fileUri: ${response.statusText}`
58
+ )
59
+ }
38
60
 
39
- arrayBuffer = (await response.arrayBuffer()).slice(0);
40
- logger.log(`fetched fileUri`, arrayBuffer.byteLength, arrayBuffer);
41
- }
61
+ arrayBuffer = await response.arrayBuffer()
62
+ logger.log(`fetched fileUri`, arrayBuffer.byteLength, arrayBuffer)
63
+ }
42
64
 
43
- // Create a new copy of the ArrayBuffer to avoid detachment issues
44
- const bufferCopy = arrayBuffer.slice(0);
45
- logger.log(
46
- `extractAudioAnalysis skipWavHeader=${skipWavHeader} bitDepth=${bitDepth} len=${bufferCopy.byteLength}`,
47
- bufferCopy.slice(0, 100),
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
- let actualBitDepth = bitDepth;
51
- if (!actualBitDepth) {
52
- logger.log(
53
- `extractAudioAnalysis bitDepth not provided -- getting wav file info`,
54
- );
55
- const fileInfo = await getWavFileInfo(bufferCopy);
56
- actualBitDepth = fileInfo.bitDepth;
57
- }
58
- logger.log(`extractAudioAnalysis actualBitDepth=${actualBitDepth}`);
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
- const {
74
- pcmValues: channelData,
75
- min,
76
- max,
77
- } = convertPCMToFloat32({
78
- buffer: arrayBuffer,
79
- bitDepth: actualBitDepth,
80
- skipWavHeader,
81
- });
82
- logger.log(
83
- `extractAudioAnalysis skipWaveHeader=${skipWavHeader} convertPCMToFloat32 length=${channelData.length} range: [ ${min} :: ${max} ]`,
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
- return new Promise((resolve, reject) => {
87
- let worker: Worker;
88
- if (featuresExtratorUrl) {
89
- worker = new Worker(new URL(featuresExtratorUrl, window.location.href));
90
- } else {
91
- const blob = new Blob([InlineFeaturesExtractor], {
92
- type: "application/javascript",
93
- });
94
- const url = URL.createObjectURL(blob);
95
- worker = new Worker(url);
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
- worker.onmessage = (event) => {
99
- resolve(event.data.result);
100
- };
109
+ worker.onmessage = (event) => {
110
+ resolve(event.data.result)
111
+ }
101
112
 
102
- worker.onerror = (error) => {
103
- reject(error);
104
- };
113
+ worker.onerror = (error) => {
114
+ reject(error)
115
+ }
105
116
 
106
- worker.postMessage({
107
- command: "process",
108
- channelData,
109
- sampleRate,
110
- pointsPerSecond,
111
- algorithm,
112
- bitDepth,
113
- fullAudioDurationMs: durationMs,
114
- numberOfChannels,
115
- });
116
- });
117
- } else {
118
- if (!fileUri) {
119
- throw new Error("fileUri is required");
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
- logger.log(`extractAudioAnalysis`, {
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 "../ExpoAudioStreamModule";
2
- import { getLogger } from "../logger";
1
+ import ExpoAudioStreamModule from '../ExpoAudioStreamModule'
2
+ import { getLogger } from '../logger'
3
3
 
4
- const logger = getLogger("extractWaveform");
4
+ const logger = getLogger('extractWaveform')
5
5
  export interface ExtractWaveformProps {
6
- fileUri: string;
7
- numberOfSamples: number;
8
- offset?: number;
9
- length?: number;
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
- logger.log(`extractWaveform`, res);
24
- return res;
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 "react";
2
+ import React, { createContext, useContext } from 'react'
3
3
 
4
- import { AudioAnalysisData } from "./AudioAnalysis/AudioAnalysis.types";
4
+ import { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types'
5
5
  import {
6
- AudioRecordingResult,
7
- RecordingConfig,
8
- StartRecordingResult,
9
- } from "./ExpoAudioStream.types";
10
- import { UseAudioRecorderProps, useAudioRecorder } from "./useAudioRecorder";
6
+ AudioRecording,
7
+ RecordingConfig,
8
+ StartRecordingResult,
9
+ } from './ExpoAudioStream.types'
10
+ import { UseAudioRecorderProps, useAudioRecorder } from './useAudioRecorder'
11
11
 
12
12
  export interface UseAudioRecorderState {
13
- startRecording: (_: RecordingConfig) => Promise<StartRecordingResult>;
14
- stopRecording: () => Promise<AudioRecordingResult | 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?: AudioAnalysisData;
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
- 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
- };
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
- children: React.ReactNode;
47
- config?: UseAudioRecorderProps;
46
+ children: React.ReactNode
47
+ config?: UseAudioRecorderProps
48
48
  }
49
49
 
50
50
  export const AudioRecorderProvider: React.FC<AudioRecorderProviderProps> = ({
51
- children,
52
- config = {},
51
+ children,
52
+ config = {},
53
53
  }) => {
54
- const audioRecorder = useAudioRecorder(config);
55
- return (
56
- <AudioRecorderContext.Provider value={audioRecorder}>
57
- {children}
58
- </AudioRecorderContext.Provider>
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
- 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
- };
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 "expo-modules-core";
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("ExpoAudioStream");
6
+ export default requireNativeModule('ExpoAudioStream')