@siteed/expo-audio-stream 1.17.0 → 2.0.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 (74) hide show
  1. package/CHANGELOG.md +26 -1
  2. package/README.md +1 -1
  3. package/android/src/main/java/net/siteed/audiostream/AudioAnalysisData.kt +68 -22
  4. package/android/src/main/java/net/siteed/audiostream/AudioFormatUtils.kt +24 -0
  5. package/android/src/main/java/net/siteed/audiostream/AudioProcessor.kt +836 -386
  6. package/android/src/main/java/net/siteed/audiostream/AudioRecorderManager.kt +0 -2
  7. package/android/src/main/java/net/siteed/audiostream/AudioRecordingService.kt +35 -29
  8. package/android/src/main/java/net/siteed/audiostream/ExpoAudioStreamModule.kt +236 -96
  9. package/android/src/main/java/net/siteed/audiostream/FFT.kt +55 -0
  10. package/android/src/main/java/net/siteed/audiostream/Features.kt +49 -7
  11. package/android/src/main/java/net/siteed/audiostream/RecordingConfig.kt +2 -4
  12. package/build/AudioAnalysis/AudioAnalysis.types.d.ts +55 -47
  13. package/build/AudioAnalysis/AudioAnalysis.types.d.ts.map +1 -1
  14. package/build/AudioAnalysis/AudioAnalysis.types.js.map +1 -1
  15. package/build/AudioAnalysis/extractAudioAnalysis.d.ts +60 -13
  16. package/build/AudioAnalysis/extractAudioAnalysis.d.ts.map +1 -1
  17. package/build/AudioAnalysis/extractAudioAnalysis.js +147 -162
  18. package/build/AudioAnalysis/extractAudioAnalysis.js.map +1 -1
  19. package/build/ExpoAudioStream.types.d.ts +47 -3
  20. package/build/ExpoAudioStream.types.d.ts.map +1 -1
  21. package/build/ExpoAudioStream.types.js.map +1 -1
  22. package/build/ExpoAudioStream.web.d.ts.map +1 -1
  23. package/build/ExpoAudioStream.web.js +0 -1
  24. package/build/ExpoAudioStream.web.js.map +1 -1
  25. package/build/ExpoAudioStreamModule.d.ts.map +1 -1
  26. package/build/ExpoAudioStreamModule.js +216 -12
  27. package/build/ExpoAudioStreamModule.js.map +1 -1
  28. package/build/WebRecorder.web.d.ts +67 -13
  29. package/build/WebRecorder.web.d.ts.map +1 -1
  30. package/build/WebRecorder.web.js +177 -173
  31. package/build/WebRecorder.web.js.map +1 -1
  32. package/build/index.d.ts +3 -3
  33. package/build/index.d.ts.map +1 -1
  34. package/build/index.js +2 -2
  35. package/build/index.js.map +1 -1
  36. package/build/useAudioRecorder.d.ts.map +1 -1
  37. package/build/useAudioRecorder.js +12 -8
  38. package/build/useAudioRecorder.js.map +1 -1
  39. package/build/utils/audioProcessing.d.ts +24 -0
  40. package/build/utils/audioProcessing.d.ts.map +1 -0
  41. package/build/utils/audioProcessing.js +133 -0
  42. package/build/utils/audioProcessing.js.map +1 -0
  43. package/build/workers/InlineFeaturesExtractor.web.d.ts +1 -1
  44. package/build/workers/InlineFeaturesExtractor.web.d.ts.map +1 -1
  45. package/build/workers/InlineFeaturesExtractor.web.js +694 -194
  46. package/build/workers/InlineFeaturesExtractor.web.js.map +1 -1
  47. package/build/workers/inlineAudioWebWorker.web.d.ts +1 -1
  48. package/build/workers/inlineAudioWebWorker.web.d.ts.map +1 -1
  49. package/build/workers/inlineAudioWebWorker.web.js +3 -2
  50. package/build/workers/inlineAudioWebWorker.web.js.map +1 -1
  51. package/ios/AudioAnalysisData.swift +51 -16
  52. package/ios/AudioProcessingHelpers.swift +710 -26
  53. package/ios/AudioProcessor.swift +334 -185
  54. package/ios/AudioStreamManager.swift +2 -3
  55. package/ios/DataPoint.swift +25 -12
  56. package/ios/DecodingConfig.swift +47 -0
  57. package/ios/ExpoAudioStreamModule.swift +187 -103
  58. package/ios/FFT.swift +62 -0
  59. package/ios/Features.swift +24 -3
  60. package/ios/RecordingSettings.swift +7 -7
  61. package/package.json +2 -1
  62. package/plugin/build/index.js +6 -1
  63. package/plugin/src/index.ts +9 -1
  64. package/src/AudioAnalysis/AudioAnalysis.types.ts +68 -52
  65. package/src/AudioAnalysis/extractAudioAnalysis.ts +223 -219
  66. package/src/ExpoAudioStream.types.ts +53 -7
  67. package/src/ExpoAudioStream.web.ts +0 -1
  68. package/src/ExpoAudioStreamModule.ts +255 -10
  69. package/src/WebRecorder.web.ts +231 -244
  70. package/src/index.ts +5 -3
  71. package/src/useAudioRecorder.tsx +14 -10
  72. package/src/utils/audioProcessing.ts +205 -0
  73. package/src/workers/InlineFeaturesExtractor.web.tsx +694 -194
  74. package/src/workers/inlineAudioWebWorker.web.tsx +3 -2
@@ -1,29 +1,46 @@
1
+ import { BitDepth, ConsoleLike } from '../ExpoAudioStream.types';
1
2
  /**
2
3
  * Represents the configuration for decoding audio data.
3
4
  */
4
5
  export interface DecodingConfig {
6
+ /** Target sample rate for decoded audio (Android and Web) */
5
7
  targetSampleRate?: number;
8
+ /** Target number of channels (Android and Web) */
6
9
  targetChannels?: number;
7
- targetBitDepth?: number;
10
+ /** Target bit depth (Android and Web) */
11
+ targetBitDepth?: BitDepth;
12
+ /** Whether to normalize audio levels (Android and Web) */
8
13
  normalizeAudio?: boolean;
9
14
  }
15
+ /**
16
+ * Represents speech-related features extracted from audio.
17
+ */
18
+ export interface SpeechFeatures {
19
+ isActive: boolean;
20
+ speakerId?: number;
21
+ }
10
22
  /**
11
23
  * Represents various audio features extracted from an audio signal.
12
24
  */
13
25
  export interface AudioFeatures {
14
- energy: number;
15
- mfcc: number[];
16
- rms: number;
17
- minAmplitude: number;
18
- maxAmplitude: number;
19
- zcr: number;
20
- spectralCentroid: number;
21
- spectralFlatness: number;
22
- spectralRolloff: number;
23
- spectralBandwidth: number;
24
- chromagram: number[];
25
- tempo: number;
26
- hnr: number;
26
+ energy?: number;
27
+ mfcc?: number[];
28
+ rms?: number;
29
+ minAmplitude?: number;
30
+ maxAmplitude?: number;
31
+ zcr?: number;
32
+ spectralCentroid?: number;
33
+ spectralFlatness?: number;
34
+ spectralRolloff?: number;
35
+ spectralBandwidth?: number;
36
+ chromagram?: number[];
37
+ tempo?: number;
38
+ hnr?: number;
39
+ melSpectrogram?: number[];
40
+ spectralContrast?: number[];
41
+ tonnetz?: number[];
42
+ pitch?: number;
43
+ crc32?: number;
27
44
  }
28
45
  /**
29
46
  * Options to specify which audio features to extract.
@@ -40,6 +57,11 @@ export interface AudioFeaturesOptions {
40
57
  chromagram?: boolean;
41
58
  tempo?: boolean;
42
59
  hnr?: boolean;
60
+ melSpectrogram?: boolean;
61
+ spectralContrast?: boolean;
62
+ tonnetz?: boolean;
63
+ pitch?: boolean;
64
+ crc32?: boolean;
43
65
  }
44
66
  /**
45
67
  * Represents a single data point in the audio analysis.
@@ -47,47 +69,51 @@ export interface AudioFeaturesOptions {
47
69
  export interface DataPoint {
48
70
  id: number;
49
71
  amplitude: number;
50
- activeSpeech?: boolean;
51
- dB?: number;
52
- silent?: boolean;
72
+ rms: number;
73
+ dB: number;
74
+ silent: boolean;
53
75
  features?: AudioFeatures;
76
+ speech?: SpeechFeatures;
54
77
  startTime?: number;
55
78
  endTime?: number;
56
79
  startPosition?: number;
57
80
  endPosition?: number;
58
81
  samples?: number;
59
- speaker?: number;
60
82
  }
61
- export type AmplitudeAlgorithm = 'peak' | 'rms';
62
83
  /**
63
84
  * Represents the complete data from the audio analysis.
64
85
  */
65
86
  export interface AudioAnalysis {
66
- pointsPerSecond: number;
87
+ segmentDurationMs: number;
67
88
  durationMs: number;
68
89
  bitDepth: number;
69
90
  samples: number;
70
91
  numberOfChannels: number;
71
92
  sampleRate: number;
72
93
  dataPoints: DataPoint[];
73
- amplitudeAlgorithm: AmplitudeAlgorithm;
74
94
  amplitudeRange: {
75
95
  min: number;
76
96
  max: number;
77
97
  };
78
- speakerChanges?: {
79
- timestamp: number;
80
- speaker: number;
81
- }[];
98
+ rmsRange: {
99
+ min: number;
100
+ max: number;
101
+ };
102
+ speechAnalysis?: {
103
+ speakerChanges: {
104
+ timestamp: number;
105
+ speakerId: number;
106
+ }[];
107
+ };
82
108
  }
83
109
  /**
84
110
  * Options for specifying a time range within an audio file.
85
111
  */
86
112
  export interface AudioRangeOptions {
87
113
  /** Start time in milliseconds */
88
- startTime?: number;
114
+ startTimeMs?: number;
89
115
  /** End time in milliseconds */
90
- endTime?: number;
116
+ endTimeMs?: number;
91
117
  }
92
118
  /**
93
119
  * Options for generating a quick preview of audio waveform.
@@ -102,10 +128,9 @@ export interface PreviewOptions extends AudioRangeOptions {
102
128
  */
103
129
  numberOfPoints?: number;
104
130
  /**
105
- * Algorithm used to calculate amplitude values
106
- * @default "rms"
131
+ * Optional logger for debugging.
107
132
  */
108
- algorithm?: AmplitudeAlgorithm;
133
+ logger?: ConsoleLike;
109
134
  /**
110
135
  * Optional configuration for decoding the audio file.
111
136
  * Defaults to:
@@ -116,21 +141,4 @@ export interface PreviewOptions extends AudioRangeOptions {
116
141
  */
117
142
  decodingOptions?: DecodingConfig;
118
143
  }
119
- /**
120
- * Represents a simplified preview of audio waveform,
121
- * optimized for quick visualization.
122
- */
123
- export interface AudioPreview {
124
- /** Number of data points per second */
125
- pointsPerSecond: number;
126
- /** Duration of the audio in milliseconds */
127
- durationMs: number;
128
- /** Range of amplitude values in the preview */
129
- amplitudeRange: {
130
- min: number;
131
- max: number;
132
- };
133
- /** Array of data points representing the waveform */
134
- dataPoints: DataPoint[];
135
- }
136
144
  //# sourceMappingURL=AudioAnalysis.types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"AudioAnalysis.types.d.ts","sourceRoot":"","sources":["../../src/AudioAnalysis/AudioAnalysis.types.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,MAAM,WAAW,cAAc;IAC3B,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB,cAAc,CAAC,EAAE,OAAO,CAAA;CAC3B;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B,MAAM,EAAE,MAAM,CAAA;IACd,IAAI,EAAE,MAAM,EAAE,CAAA;IACd,GAAG,EAAE,MAAM,CAAA;IACX,YAAY,EAAE,MAAM,CAAA;IACpB,YAA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AAM,CAAA;IACxB,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,SAAS,EAAE,CAAA;IACvB,cAAc,EAAE;QACZ,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACd,CAAA;IACD,QAAQ,EAAE;QACN,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACd,CAAA;IAED,cAAc,CAAC,EAAE;QACb,cAAc,EAAE;YACZ,SAAS,EAAE,MAAM,CAAA;YACjB,SAAS,EAAE,MAAM,CAAA;SACpB,EAAE,CAAA;KAKN,CAAA;CACJ;AAED;;GAEG;AACH,MAAM,WAAW,iBAAiB;IAC9B,iCAAiC;IACjC,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,+BAA+B;IAC/B,SAAS,CAAC,EAAE,MAAM,CAAA;CACrB;AAED;;;GAGG;AACH,MAAM,WAAW,cAAe,SAAQ,iBAAiB;IACrD,uCAAuC;IACvC,OAAO,EAAE,MAAM,CAAA;IACf;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAA;IACvB;;OAEG;IACH,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB;;;;;;;OAOG;IACH,eAAe,CAAC,EAAE,cAAc,CAAA;CACnC"}
@@ -1 +1 @@
1
- {"version":3,"file":"AudioAnalysis.types.js","sourceRoot":"","sources":["../../src/AudioAnalysis/AudioAnalysis.types.ts"],"names":[],"mappings":"AAAA,sEAAsE","sourcesContent":["// packages/expo-audio-stream/src/AudioAnalysis/AudioAnalysis.types.ts\n\n/**\n * Represents the configuration for decoding audio data.\n */\nexport interface DecodingConfig {\n targetSampleRate?: number\n targetChannels?: number\n targetBitDepth?: number\n normalizeAudio?: boolean\n}\n\n/**\n * Represents various audio features extracted from an audio signal.\n */\nexport interface AudioFeatures {\n energy: number // The infinite integral of the squared signal, representing the overall energy of the audio.\n mfcc: number[] // Mel-frequency cepstral coefficients, describing the short-term power spectrum of a sound.\n rms: number // Root mean square value, indicating the amplitude of the audio signal.\n minAmplitude: number // Minimum amplitude value in the audio signal.\n maxAmplitude: number // Maximum amplitude value in the audio signal.\n zcr: number // Zero-crossing rate, indicating the rate at which the signal changes sign.\n spectralCentroid: number // The center of mass of the spectrum, indicating the brightness of the sound.\n spectralFlatness: number // Measure of the flatness of the spectrum, indicating how noise-like the signal is.\n spectralRolloff: number // The frequency below which a specified percentage (usually 85%) of the total spectral energy lies.\n spectralBandwidth: number // The width of the spectrum, indicating the range of frequencies present.\n chromagram: number[] // Chromagram, representing the 12 different pitch classes of the audio.\n tempo: number // Estimated tempo of the audio signal, measured in beats per minute (BPM).\n hnr: number // Harmonics-to-noise ratio, indicating the proportion of harmonics to noise in the audio signal.\n}\n\n/**\n * Options to specify which audio features to extract.\n */\nexport interface AudioFeaturesOptions {\n energy?: boolean\n mfcc?: boolean\n rms?: boolean\n zcr?: boolean\n spectralCentroid?: boolean\n spectralFlatness?: boolean\n spectralRolloff?: boolean\n spectralBandwidth?: boolean\n chromagram?: boolean\n tempo?: boolean\n hnr?: boolean\n}\n\n/**\n * Represents a single data point in the audio analysis.\n */\nexport interface DataPoint {\n id: number\n amplitude: number\n activeSpeech?: boolean\n dB?: number\n silent?: boolean\n features?: AudioFeatures\n startTime?: number\n endTime?: number\n // start / end position in bytes\n startPosition?: number\n endPosition?: number\n // number of audio samples for this point (samples size depends on bit depth)\n samples?: number\n // TODO: speaker detection\n speaker?: number\n}\n\nexport type AmplitudeAlgorithm = 'peak' | 'rms'\n\n/**\n * Represents the complete data from the audio analysis.\n */\nexport interface AudioAnalysis {\n pointsPerSecond: number // How many consolidated value per second\n durationMs: number // Duration of the audio in milliseconds\n bitDepth: number // Bit depth of the audio\n samples: number // Size of the audio in bytes\n numberOfChannels: number // Number of audio channels\n sampleRate: number // Sample rate of the audio\n dataPoints: DataPoint[] // Array of data points from the analysis.\n amplitudeAlgorithm: AmplitudeAlgorithm // Algorithm used to calculate amplitude values.\n amplitudeRange: {\n min: number\n max: number\n }\n // TODO: speaker detection\n speakerChanges?: {\n timestamp: number // Timestamp of the speaker change in milliseconds.\n speaker: number // Speaker identifier.\n }[]\n}\n\n/**\n * Options for specifying a time range within an audio file.\n */\nexport interface AudioRangeOptions {\n /** Start time in milliseconds */\n startTime?: number\n /** End time in milliseconds */\n endTime?: number\n}\n\n/**\n * Options for generating a quick preview of audio waveform.\n * This is optimized for UI rendering with a specified number of points.\n */\nexport interface PreviewOptions extends AudioRangeOptions {\n /** URI of the audio file to analyze */\n fileUri: string\n /**\n * Total number of points to generate for the preview.\n * @default 100\n */\n numberOfPoints?: number\n /**\n * Algorithm used to calculate amplitude values\n * @default \"rms\"\n */\n algorithm?: AmplitudeAlgorithm\n /**\n * Optional configuration for decoding the audio file.\n * Defaults to:\n * - targetSampleRate: undefined (keep original)\n * - targetChannels: undefined (keep original)\n * - targetBitDepth: 16\n * - normalizeAudio: false\n */\n decodingOptions?: DecodingConfig\n}\n\n/**\n * Represents a simplified preview of audio waveform,\n * optimized for quick visualization.\n */\nexport interface AudioPreview {\n /** Number of data points per second */\n pointsPerSecond: number\n /** Duration of the audio in milliseconds */\n durationMs: number\n /** Range of amplitude values in the preview */\n amplitudeRange: {\n min: number\n max: number\n }\n /** Array of data points representing the waveform */\n dataPoints: DataPoint[]\n}\n"]}
1
+ {"version":3,"file":"AudioAnalysis.types.js","sourceRoot":"","sources":["../../src/AudioAnalysis/AudioAnalysis.types.ts"],"names":[],"mappings":"AAAA,sEAAsE","sourcesContent":["// packages/expo-audio-stream/src/AudioAnalysis/AudioAnalysis.types.ts\n\nimport { BitDepth, ConsoleLike } from '../ExpoAudioStream.types'\n\n/**\n * Represents the configuration for decoding audio data.\n */\nexport interface DecodingConfig {\n /** Target sample rate for decoded audio (Android and Web) */\n targetSampleRate?: number\n /** Target number of channels (Android and Web) */\n targetChannels?: number\n /** Target bit depth (Android and Web) */\n targetBitDepth?: BitDepth\n /** Whether to normalize audio levels (Android and Web) */\n normalizeAudio?: boolean\n}\n\n/**\n * Represents speech-related features extracted from audio.\n */\nexport interface SpeechFeatures {\n isActive: boolean // Whether speech is detected in this segment\n speakerId?: number // Optional speaker identification\n // Could add more speech-related features here like:\n // confidence: number\n // language?: string\n // sentiment?: number\n // etc.\n}\n\n/**\n * Represents various audio features extracted from an audio signal.\n */\nexport interface AudioFeatures {\n energy?: number // The infinite integral of the squared signal, representing the overall energy of the audio.\n mfcc?: number[] // Mel-frequency cepstral coefficients, describing the short-term power spectrum of a sound.\n rms?: number // Root mean square value, indicating the amplitude of the audio signal.\n minAmplitude?: number // Minimum amplitude value in the audio signal.\n maxAmplitude?: number // Maximum amplitude value in the audio signal.\n zcr?: number // Zero-crossing rate, indicating the rate at which the signal changes sign.\n spectralCentroid?: number // The center of mass of the spectrum, indicating the brightness of the sound.\n spectralFlatness?: number // Measure of the flatness of the spectrum, indicating how noise-like the signal is.\n spectralRolloff?: number // The frequency below which a specified percentage (usually 85%) of the total spectral energy lies.\n spectralBandwidth?: number // The width of the spectrum, indicating the range of frequencies present.\n chromagram?: number[] // Chromagram, representing the 12 different pitch classes of the audio.\n tempo?: number // Estimated tempo of the audio signal, measured in beats per minute (BPM).\n hnr?: number // Harmonics-to-noise ratio, indicating the proportion of harmonics to noise in the audio signal.\n melSpectrogram?: number[] // Mel-scaled spectrogram representation of the audio.\n spectralContrast?: number[] // Spectral contrast features representing the difference between peaks and valleys.\n tonnetz?: number[] // Tonal network features representing harmonic relationships.\n pitch?: number // Pitch of the audio signal, measured in Hertz (Hz).\n crc32?: number // crc32 checksum of the audio signal, used to verify the integrity of the audio.\n}\n\n/**\n * Options to specify which audio features to extract.\n */\nexport interface AudioFeaturesOptions {\n energy?: boolean\n mfcc?: boolean\n rms?: boolean\n zcr?: boolean\n spectralCentroid?: boolean\n spectralFlatness?: boolean\n spectralRolloff?: boolean\n spectralBandwidth?: boolean\n chromagram?: boolean\n tempo?: boolean\n hnr?: boolean\n melSpectrogram?: boolean\n spectralContrast?: boolean\n tonnetz?: boolean\n pitch?: boolean\n crc32?: boolean\n}\n\n/**\n * Represents a single data point in the audio analysis.\n */\nexport interface DataPoint {\n id: number\n amplitude: number // Peak amplitude for the segment\n rms: number // Root mean square value\n dB: number // Always computed\n silent: boolean // Always computed\n features?: AudioFeatures\n speech?: SpeechFeatures\n startTime?: number\n endTime?: number\n // start / end position in bytes\n startPosition?: number\n endPosition?: number\n // number of audio samples for this point (samples size depends on bit depth)\n samples?: number\n}\n\n/**\n * Represents the complete data from the audio analysis.\n */\nexport interface AudioAnalysis {\n segmentDurationMs: number // Duration of each segment in milliseconds\n durationMs: number // Duration of the audio in milliseconds\n bitDepth: number // Bit depth of the audio\n samples: number // Size of the audio in bytes\n numberOfChannels: number // Number of audio channels\n sampleRate: number // Sample rate of the audio\n dataPoints: DataPoint[] // Array of data points from the analysis.\n amplitudeRange: {\n min: number\n max: number\n }\n rmsRange: {\n min: number\n max: number\n }\n // TODO: speaker changes into a broader speech analysis section\n speechAnalysis?: {\n speakerChanges: {\n timestamp: number\n speakerId: number\n }[]\n // Could add more speech analysis data here like:\n // dominantSpeaker?: number\n // totalSpeechDuration?: number\n // speakerStats?: { [speakerId: number]: { duration: number, segments: number } }\n }\n}\n\n/**\n * Options for specifying a time range within an audio file.\n */\nexport interface AudioRangeOptions {\n /** Start time in milliseconds */\n startTimeMs?: number\n /** End time in milliseconds */\n endTimeMs?: number\n}\n\n/**\n * Options for generating a quick preview of audio waveform.\n * This is optimized for UI rendering with a specified number of points.\n */\nexport interface PreviewOptions extends AudioRangeOptions {\n /** URI of the audio file to analyze */\n fileUri: string\n /**\n * Total number of points to generate for the preview.\n * @default 100\n */\n numberOfPoints?: number\n /**\n * Optional logger for debugging.\n */\n logger?: ConsoleLike\n /**\n * Optional configuration for decoding the audio file.\n * Defaults to:\n * - targetSampleRate: undefined (keep original)\n * - targetChannels: undefined (keep original)\n * - targetBitDepth: 16\n * - normalizeAudio: false\n */\n decodingOptions?: DecodingConfig\n}\n"]}
@@ -1,31 +1,78 @@
1
- import { ConsoleLike } from '../ExpoAudioStream.types';
2
- import { AmplitudeAlgorithm, AudioAnalysis, AudioFeaturesOptions, AudioPreview, DecodingConfig, PreviewOptions } from './AudioAnalysis.types';
1
+ import { ConsoleLike, ExtractAudioDataOptions } from '../ExpoAudioStream.types';
2
+ import { AudioAnalysis, AudioFeaturesOptions, DecodingConfig, PreviewOptions } from './AudioAnalysis.types';
3
3
  import { WavFileInfo } from '../utils/getWavFileInfo';
4
- export interface ExtractAudioAnalysisProps {
4
+ export interface ExtractWavAudioAnalysisProps {
5
5
  fileUri?: string;
6
6
  wavMetadata?: WavFileInfo;
7
7
  arrayBuffer?: ArrayBuffer;
8
8
  bitDepth?: number;
9
- skipWavHeader?: boolean;
10
9
  durationMs?: number;
11
10
  sampleRate?: number;
12
11
  numberOfChannels?: number;
13
- algorithm?: AmplitudeAlgorithm;
14
12
  position?: number;
15
13
  length?: number;
16
- pointsPerSecond?: number;
14
+ segmentDurationMs?: number;
17
15
  features?: AudioFeaturesOptions;
18
16
  featuresExtratorUrl?: string;
19
17
  logger?: ConsoleLike;
20
18
  decodingOptions?: DecodingConfig;
21
19
  }
22
- export interface ExtractAudioFromAnyFormatProps extends ExtractAudioAnalysisProps {
23
- mimeType?: string;
20
+ interface BaseExtractOptions {
21
+ fileUri?: string;
22
+ arrayBuffer?: ArrayBuffer;
23
+ /**
24
+ * Duration of each analysis segment in milliseconds. Defaults to 100ms if not specified.
25
+ */
26
+ segmentDurationMs?: number;
27
+ features?: AudioFeaturesOptions;
24
28
  decodingOptions?: DecodingConfig;
25
- startTime?: number;
26
- endTime?: number;
29
+ logger?: ConsoleLike;
30
+ }
31
+ interface TimeRangeOptions extends BaseExtractOptions {
32
+ startTimeMs?: number;
33
+ endTimeMs?: number;
34
+ position?: never;
35
+ length?: never;
36
+ }
37
+ interface ByteRangeOptions extends BaseExtractOptions {
38
+ position?: number;
39
+ length?: number;
40
+ startTimeMs?: never;
41
+ endTimeMs?: never;
27
42
  }
28
- export declare function extractAudioFromAnyFormat({ fileUri, arrayBuffer, mimeType, decodingOptions, startTime, endTime, ...restProps }: ExtractAudioFromAnyFormatProps): Promise<AudioAnalysis>;
29
- export declare const extractAudioAnalysis: ({ fileUri, pointsPerSecond, arrayBuffer, bitDepth, skipWavHeader, durationMs, sampleRate, numberOfChannels, algorithm, features, featuresExtratorUrl, logger, }: ExtractAudioAnalysisProps) => Promise<AudioAnalysis>;
30
- export declare function extractPreview({ fileUri, numberOfPoints, algorithm, startTime, endTime, decodingOptions, }: PreviewOptions): Promise<AudioPreview>;
43
+ /**
44
+ * Options for extracting audio analysis.
45
+ * - For time-based analysis, provide `startTimeMs` and `endTimeMs`.
46
+ * - For byte-based analysis, provide `position` and `length`.
47
+ * - Do not mix time and byte ranges.
48
+ */
49
+ export type ExtractAudioAnalysisProps = TimeRangeOptions | ByteRangeOptions;
50
+ /**
51
+ * Extracts detailed audio analysis from the specified audio file or buffer.
52
+ * Supports either time-based or byte-based ranges for flexibility in analysis.
53
+ *
54
+ * @param props - The options for extraction, including file URI, ranges, and decoding settings.
55
+ * @returns A promise that resolves to the audio analysis data.
56
+ * @throws {Error} If both time and byte ranges are provided or if required parameters are missing.
57
+ */
58
+ export declare function extractAudioAnalysis(props: ExtractAudioAnalysisProps): Promise<AudioAnalysis>;
59
+ /**
60
+ * Analyzes WAV files without decoding, preserving original PCM values.
61
+ * Use this function when you need to ensure the analysis matches other software by avoiding any transformations.
62
+ *
63
+ * @param props - The options for WAV analysis, including file URI and range.
64
+ * @returns A promise that resolves to the audio analysis data.
65
+ */
66
+ export declare const extractRawWavAnalysis: ({ fileUri, segmentDurationMs, arrayBuffer, bitDepth, durationMs, sampleRate, numberOfChannels, features, logger, position, length, }: ExtractWavAudioAnalysisProps) => Promise<AudioAnalysis>;
67
+ /**
68
+ * Generates a simplified preview of the audio waveform for quick visualization.
69
+ * Ideal for UI rendering with a specified number of points.
70
+ *
71
+ * @param options - The options for the preview, including file URI and time range.
72
+ * @returns A promise that resolves to the audio preview data.
73
+ */
74
+ export declare function extractPreview({ fileUri, numberOfPoints, startTimeMs, endTimeMs, // First 30 seconds
75
+ decodingOptions, logger, }: PreviewOptions): Promise<AudioAnalysis>;
76
+ export declare const extractAudioData: (props: ExtractAudioDataOptions) => Promise<any>;
77
+ export {};
31
78
  //# sourceMappingURL=extractAudioAnalysis.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"extractAudioAnalysis.d.ts","sourceRoot":"","sources":["../../src/AudioAnalysis/extractAudioAnalysis.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAA;AAGtD,OAAO,EACH,kBAAkB,EAClB,aAAa,EACb,oBAAoB,EACpB,YAAY,EACZ,cAAc,EACd,cAAc,EACjB,MAAM,uBAAuB,CAAA;AAE9B,OAAO,EAAkB,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAGrE,MAAM,WAAW,yBAAyB;IACtC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,aAAa,CAAC,EAAE,OAAO,CAAA;IACvB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,SAAS,CAAC,EAAE,kBAAkB,CAAA;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,eAAe,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,EAAE,oBAAoB,CAAA;IAC/B,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,MAAM,CAAC,EAAE,WAAW,CAAA;IACpB,eAAe,CAAC,EAAE,cAAc,CAAA;CACnC;AAED,MAAM,WAAW,8BACb,SAAQ,yBAAyB;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,eAAe,CAAC,EAAE,cAAc,CAAA;IAChC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,OAAO,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,wBAAsB,yBAAyB,CAAC,EAC5C,OAAO,EACP,WAAW,EACX,QAAQ,EACR,eAAe,EACf,SAAS,EACT,OAAO,EACP,GAAG,SAAS,EACf,EAAE,8BAA8B,GAAG,OAAO,CAAC,aAAa,CAAC,CAsJzD;AAED,eAAO,MAAM,oBAAoB,oKAa9B,yBAAyB,KAAG,QAAQ,aAAa,CAsGnD,CAAA;AAED,wBAAsB,cAAc,CAAC,EACjC,OAAO,EACP,cAAc,EACd,SAAiB,EACjB,SAAS,EACT,OAAO,EACP,eAAe,GAClB,EAAE,cAAc,GAAG,OAAO,CAAC,YAAY,CAAC,CAsCxC"}
1
+ {"version":3,"file":"extractAudioAnalysis.d.ts","sourceRoot":"","sources":["../../src/AudioAnalysis/extractAudioAnalysis.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,MAAM,0BAA0B,CAAA;AAG/E,OAAO,EACH,aAAa,EACb,oBAAoB,EAEpB,cAAc,EACd,cAAc,EACjB,MAAM,uBAAuB,CAAA;AAG9B,OAAO,EAAkB,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAerE,MAAM,WAAW,4BAA4B;IACzC,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,WAAW,CAAC,EAAE,WAAW,CAAA;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,iBAAiB,CAAC,EAAE,MAAM,CAAA;IAC1B,QAA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