@siteed/expo-audio-stream 1.5.2 → 1.7.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.
Files changed (94) hide show
  1. package/CHANGELOG.md +19 -27
  2. package/android/src/main/java/net/siteed/audiostream/AudioRecorderManager.kt +13 -2
  3. package/build/AudioAnalysis/AudioAnalysis.types.d.ts +74 -0
  4. package/build/AudioAnalysis/AudioAnalysis.types.d.ts.map +1 -0
  5. package/build/AudioAnalysis/AudioAnalysis.types.js +3 -0
  6. package/build/AudioAnalysis/AudioAnalysis.types.js.map +1 -0
  7. package/build/AudioAnalysis/extractAudioAnalysis.d.ts +22 -0
  8. package/build/AudioAnalysis/extractAudioAnalysis.d.ts.map +1 -0
  9. package/build/AudioAnalysis/extractAudioAnalysis.js +86 -0
  10. package/build/AudioAnalysis/extractAudioAnalysis.js.map +1 -0
  11. package/build/AudioAnalysis/extractWaveform.d.ts +8 -0
  12. package/build/AudioAnalysis/extractWaveform.d.ts.map +1 -0
  13. package/build/AudioAnalysis/extractWaveform.js +11 -0
  14. package/build/AudioAnalysis/extractWaveform.js.map +1 -0
  15. package/build/AudioRecorder.provider.d.ts +11 -0
  16. package/build/AudioRecorder.provider.d.ts.map +1 -0
  17. package/build/AudioRecorder.provider.js +36 -0
  18. package/build/AudioRecorder.provider.js.map +1 -0
  19. package/build/ExpoAudioStream.native.d.ts +3 -0
  20. package/build/ExpoAudioStream.native.d.ts.map +1 -0
  21. package/build/ExpoAudioStream.native.js +6 -0
  22. package/build/ExpoAudioStream.native.js.map +1 -0
  23. package/build/ExpoAudioStream.types.d.ts +127 -0
  24. package/build/ExpoAudioStream.types.d.ts.map +1 -0
  25. package/build/ExpoAudioStream.types.js +2 -0
  26. package/build/ExpoAudioStream.types.js.map +1 -0
  27. package/build/ExpoAudioStream.web.d.ts +44 -0
  28. package/build/ExpoAudioStream.web.d.ts.map +1 -0
  29. package/build/ExpoAudioStream.web.js +206 -0
  30. package/build/ExpoAudioStream.web.js.map +1 -0
  31. package/build/ExpoAudioStreamModule.d.ts +3 -0
  32. package/build/ExpoAudioStreamModule.d.ts.map +1 -0
  33. package/build/ExpoAudioStreamModule.js +35 -0
  34. package/build/ExpoAudioStreamModule.js.map +1 -0
  35. package/build/WebRecorder.web.d.ts +54 -0
  36. package/build/WebRecorder.web.d.ts.map +1 -0
  37. package/build/WebRecorder.web.js +336 -0
  38. package/build/WebRecorder.web.js.map +1 -0
  39. package/build/constants.d.ts +11 -0
  40. package/build/constants.d.ts.map +1 -0
  41. package/build/constants.js +14 -0
  42. package/build/constants.js.map +1 -0
  43. package/build/events.d.ts +18 -0
  44. package/build/events.d.ts.map +1 -0
  45. package/build/events.js +11 -0
  46. package/build/events.js.map +1 -0
  47. package/build/index.d.ts +11 -0
  48. package/build/index.d.ts.map +1 -0
  49. package/build/index.js.map +1 -0
  50. package/build/useAudioRecorder.d.ts +20 -0
  51. package/build/useAudioRecorder.d.ts.map +1 -0
  52. package/build/useAudioRecorder.js +311 -0
  53. package/build/useAudioRecorder.js.map +1 -0
  54. package/build/utils/BlobFix.d.ts +9 -0
  55. package/build/utils/BlobFix.d.ts.map +1 -0
  56. package/build/utils/BlobFix.js +498 -0
  57. package/build/utils/BlobFix.js.map +1 -0
  58. package/build/utils/concatenateBuffers.d.ts +8 -0
  59. package/build/utils/concatenateBuffers.d.ts.map +1 -0
  60. package/build/utils/concatenateBuffers.js +21 -0
  61. package/build/utils/concatenateBuffers.js.map +1 -0
  62. package/build/utils/convertPCMToFloat32.d.ts +13 -0
  63. package/build/utils/convertPCMToFloat32.d.ts.map +1 -0
  64. package/build/utils/convertPCMToFloat32.js +120 -0
  65. package/build/utils/convertPCMToFloat32.js.map +1 -0
  66. package/build/utils/encodingToBitDepth.d.ts +5 -0
  67. package/build/utils/encodingToBitDepth.d.ts.map +1 -0
  68. package/build/utils/encodingToBitDepth.js +13 -0
  69. package/build/utils/encodingToBitDepth.js.map +1 -0
  70. package/build/utils/getWavFileInfo.d.ts +26 -0
  71. package/build/utils/getWavFileInfo.d.ts.map +1 -0
  72. package/build/utils/getWavFileInfo.js +92 -0
  73. package/build/utils/getWavFileInfo.js.map +1 -0
  74. package/build/utils/writeWavHeader.d.ts +49 -0
  75. package/build/utils/writeWavHeader.d.ts.map +1 -0
  76. package/build/utils/writeWavHeader.js +91 -0
  77. package/build/utils/writeWavHeader.js.map +1 -0
  78. package/build/workers/InlineFeaturesExtractor.web.d.ts +2 -0
  79. package/build/workers/InlineFeaturesExtractor.web.d.ts.map +1 -0
  80. package/build/workers/InlineFeaturesExtractor.web.js +311 -0
  81. package/build/workers/InlineFeaturesExtractor.web.js.map +1 -0
  82. package/build/workers/inlineAudioWebWorker.web.d.ts +2 -0
  83. package/build/workers/inlineAudioWebWorker.web.d.ts.map +1 -0
  84. package/build/workers/inlineAudioWebWorker.web.js +251 -0
  85. package/build/workers/inlineAudioWebWorker.web.js.map +1 -0
  86. package/expo-module.config.json +9 -0
  87. package/ios/AudioStreamManager.swift +394 -184
  88. package/ios/ExpoAudioStreamModule.swift +2 -2
  89. package/package.json +8 -4
  90. package/plugin/build/index.d.ts +3 -0
  91. package/plugin/build/index.js +132 -0
  92. package/plugin/src/index.ts +176 -0
  93. package/plugin/tsconfig.json +10 -0
  94. package/plugin/tsconfig.tsbuildinfo +1 -0
package/CHANGELOG.md CHANGED
@@ -8,17 +8,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
8
8
  ## [Unreleased]
9
9
 
10
10
 
11
- ## [1.5.2] - 2024-12-11
11
+ ## [1.7.0] - 2025-01-05
12
+ - feat(playground): enhance app configuration and build setup for production deployment (#58) ([929d443](https://github.com/deeeed/expo-audio-stream/commit/929d443145378b1430d215db5c00b13758420e2b))
13
+ - chore(expo-audio-stream): release @siteed/expo-audio-stream@1.6.1 ([084e8ad](https://github.com/deeeed/expo-audio-stream/commit/084e8adb91da7874c9e608b55d9c7b2ffd7a8327))
14
+ - fix(ios): improve audio resampling and duration tracking (#69) ([51bef49](https://github.com/deeeed/expo-audio-stream/commit/51bef493b8e167852c64b8c66a9f8a14cd34f99c))
15
+ - handle paused state in stopRecording (#68) ([15eac9b](https://github.com/deeeed/expo-audio-stream/commit/15eac9bfcc3203e4a5eb5f236286ed72aafde722))
16
+ - reset audio recording state properly on iOS and Android (#66) ([61e9c26](https://github.com/deeeed/expo-audio-stream/commit/61e9c261fb3a979be1894e537233d6e5a4fbdae4))
17
+ - total size doesnt reset on new recording android (#64) ([f7da57b](https://github.com/deeeed/expo-audio-stream/commit/f7da57ba9d6f25870c130c54a049ba4cfad1c444))
18
+
19
+ ## [1.6.1] - 2024-12-11
20
+ - chore(expo-audio-stream): remove git commit step from publish script ([4a772ce](https://github.com/deeeed/expo-audio-stream/commit/4a772ce93bb7405d9b8e981f46bdf8941a71ecfe))
21
+ - chore: more publishing automation ([3693021](https://github.com/deeeed/expo-audio-stream/commit/369302107f9dca9dddd8ae68e6214481a39976ac))
22
+ - expo plugin files not published ([b88c446](https://github.com/deeeed/expo-audio-stream/commit/b88c44667013a901fccfe6f89dcb640ae2aae47f))
12
23
  - chore(expo-audio-stream): improved build publish script ([ad65a69](https://github.com/deeeed/expo-audio-stream/commit/ad65a69011273e0eab1ac0f464fc3b009fc3433d))
24
+ - fix(expo-audio-stream): missing package files ([0901a1b](https://github.com/deeeed/expo-audio-stream/commit/0901a1bbbcce3111c9b5d61ade8caa48bcdd3613))
25
+ - feat(expo-audio-stream): opt in debug log for plugin config ([03a0a71](https://github.com/deeeed/expo-audio-stream/commit/03a0a7168bb4f77638de51c55a1ad19c713b52dc))
26
+ - fix(expo-audio-stream): include all build + sourcemaps files in the package
13
27
  - fix(expo-audio-stream): missing plugin files ([e56254a](https://github.com/deeeed/expo-audio-stream/commit/e56254a4ffa1c015df3d300831ba0b392958b6c8))
14
-
15
- ## [1.5.1] - 2024-12-11
16
28
  - fix(expo-audio-stream): plugin deployment process and build system enhancements (#56) ([63fbeb8](https://github.com/deeeed/expo-audio-stream/commit/63fbeb82f56130dedeafa633e916f2ce0f8f1a67))
17
29
 
18
30
 
19
31
  ## [1.5.0] - 2024-12-10
20
- - feat(expo-audio-stream): add comprehensive ios audio session configuration support (#54) ([ba296ac](https://github.com/deeeed/expo-audio-stream/commit/ba296ac9be0d61e7a46cc64953e6f2c66881fdfd))
21
- - fix(expo-audio-stream): prevent invalid WAV files when stopping recording too quickly (#53) ([80f4898](https://github.com/deeeed/expo-audio-stream/commit/80f4898625cea52da8f3e34e425e61d7641353f7))
32
+ - UNPUBLISHED because of a bug in the build system
22
33
 
23
34
 
24
35
 
@@ -27,14 +38,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
27
38
 
28
39
 
29
40
 
30
-
31
41
  ## [1.3.1] - 2024-12-05
32
42
  - feat(web): implement throttling and optimize event processing (#49) ([da28765](https://github.com/deeeed/expo-audio-stream/commit/da2876524c2c9d6e0a980fde40a0197b929d8a7f))
33
43
 
34
44
 
35
45
 
36
-
37
-
38
46
  ## [1.3.0] - 2024-11-28
39
47
  ### Added
40
48
  - refactor(permissions): standardize permission status response structure across platforms (#44) ([7c9c800](https://github.com/deeeed/expo-audio-stream/commit/7c9c800d83b7cea3516643371484d5e1f3b99e4c))
@@ -45,9 +53,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
45
53
 
46
54
 
47
55
 
48
-
49
-
50
-
51
56
  ## [1.2.5] - 2024-11-12
52
57
  ### Added
53
58
  - docs(license): add MIT license to all packages (6 files changed)
@@ -55,9 +60,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
55
60
 
56
61
 
57
62
 
58
-
59
-
60
-
61
63
  ## [1.2.4] - 2024-11-05
62
64
  ### Changed
63
65
  - Android minimum audio interval set to 10ms.
@@ -68,9 +70,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
68
70
 
69
71
 
70
72
 
71
-
72
-
73
-
74
73
  ## [1.2.0] - 2024-10-24
75
74
  ### Added
76
75
  - Feature: Keep device awake during recording with `keepAwake` option
@@ -81,9 +80,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
81
80
 
82
81
 
83
82
 
84
-
85
-
86
-
87
83
  ## [1.1.17] - 2024-10-21
88
84
  ### Added
89
85
  - Support bluetooth headset on ios
@@ -91,11 +87,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
91
87
 
92
88
 
93
89
 
94
-
95
-
96
-
97
90
  ## [1.0.0] - 2024-04-01
98
-
99
91
  ### Added
100
92
  - Initial release of @siteed/expo-audio-stream.
101
93
  - Feature: Real-time audio streaming across iOS, Android, and web.
@@ -105,9 +97,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
105
97
  - Feature: Audio features extraction during recording.
106
98
  - Feature: Consistent WAV PCM recording format across all platforms.
107
99
 
108
- [unreleased]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-stream@1.5.2...HEAD
109
- [1.5.2]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-stream@1.5.1...@siteed/expo-audio-stream@1.5.2
110
- [1.5.1]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-stream@1.5.0...@siteed/expo-audio-stream@1.5.1
100
+ [unreleased]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-stream@1.7.0...HEAD
101
+ [1.7.0]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-stream@1.6.1...@siteed/expo-audio-stream@1.7.0
102
+ [1.6.1]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-stream@1.6.0...@siteed/expo-audio-stream@1.6.1
111
103
  [1.5.0]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-stream@1.4.0...@siteed/expo-audio-stream@1.5.0
112
104
  [1.4.0]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-stream@1.3.1...@siteed/expo-audio-stream@1.4.0
113
105
  [1.3.1]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-stream@1.3.0...@siteed/expo-audio-stream@1.3.1
@@ -339,6 +339,7 @@ class AudioRecorderManager(
339
339
  try {
340
340
  streamUuid = java.util.UUID.randomUUID().toString()
341
341
  audioFile = File(filesDir, "audio_${streamUuid}.$fileExtension")
342
+ totalDataSize = 0
342
343
 
343
344
  FileOutputStream(audioFile, true).use { fos ->
344
345
  audioFileHandler.writeWavHeader(
@@ -396,7 +397,6 @@ class AudioRecorderManager(
396
397
 
397
398
  fun stopRecording(promise: Promise) {
398
399
  synchronized(audioRecordLock) {
399
-
400
400
  if (!isRecording.get()) {
401
401
  Log.e(Constants.TAG, "Recording is not active")
402
402
  promise.reject("NOT_RECORDING", "Recording is not active", null)
@@ -404,16 +404,27 @@ class AudioRecorderManager(
404
404
  }
405
405
 
406
406
  try {
407
+ if (isPaused.get()) {
408
+ val remainingData = ByteArray(bufferSizeInBytes)
409
+ val bytesRead = audioRecord?.read(remainingData, 0, bufferSizeInBytes) ?: -1
410
+ if (bytesRead > 0) {
411
+ emitAudioData(remainingData.copyOfRange(0, bytesRead), bytesRead)
412
+ }
413
+ }
414
+
407
415
  if (recordingConfig.showNotification) {
408
416
  notificationManager.stopUpdates()
409
417
  AudioRecordingService.stopService(context)
410
418
  }
411
419
 
420
+ isRecording.set(false)
421
+ recordingThread?.join(1000)
422
+
412
423
  val audioData = ByteArray(bufferSizeInBytes)
413
424
  val bytesRead = audioRecord?.read(audioData, 0, bufferSizeInBytes) ?: -1
414
425
  Log.d(Constants.TAG, "Last Read $bytesRead bytes")
415
426
  if (bytesRead > 0) {
416
- emitAudioData(audioData, bytesRead)
427
+ emitAudioData(audioData.copyOfRange(0, bytesRead), bytesRead)
417
428
  }
418
429
 
419
430
  Log.d(Constants.TAG, "Stopping recording state = ${audioRecord?.state}")
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Represents various audio features extracted from an audio signal.
3
+ */
4
+ export interface AudioFeatures {
5
+ energy: number;
6
+ mfcc: number[];
7
+ rms: number;
8
+ minAmplitude: number;
9
+ maxAmplitude: number;
10
+ zcr: number;
11
+ spectralCentroid: number;
12
+ spectralFlatness: number;
13
+ spectralRolloff: number;
14
+ spectralBandwidth: number;
15
+ chromagram: number[];
16
+ tempo: number;
17
+ hnr: number;
18
+ }
19
+ /**
20
+ * Options to specify which audio features to extract.
21
+ */
22
+ export interface AudioFeaturesOptions {
23
+ energy?: boolean;
24
+ mfcc?: boolean;
25
+ rms?: boolean;
26
+ zcr?: boolean;
27
+ spectralCentroid?: boolean;
28
+ spectralFlatness?: boolean;
29
+ spectralRolloff?: boolean;
30
+ spectralBandwidth?: boolean;
31
+ chromagram?: boolean;
32
+ tempo?: boolean;
33
+ hnr?: boolean;
34
+ }
35
+ /**
36
+ * Represents a single data point in the audio analysis.
37
+ */
38
+ export interface DataPoint {
39
+ id: number;
40
+ amplitude: number;
41
+ activeSpeech?: boolean;
42
+ dB?: number;
43
+ silent?: boolean;
44
+ features?: AudioFeatures;
45
+ startTime?: number;
46
+ endTime?: number;
47
+ startPosition?: number;
48
+ endPosition?: number;
49
+ samples?: number;
50
+ speaker?: number;
51
+ }
52
+ export type AmplitudeAlgorithm = 'peak' | 'rms';
53
+ /**
54
+ * Represents the complete data from the audio analysis.
55
+ */
56
+ export interface AudioAnalysis {
57
+ pointsPerSecond: number;
58
+ durationMs: number;
59
+ bitDepth: number;
60
+ samples: number;
61
+ numberOfChannels: number;
62
+ sampleRate: number;
63
+ dataPoints: DataPoint[];
64
+ amplitudeAlgorithm: AmplitudeAlgorithm;
65
+ amplitudeRange: {
66
+ min: number;
67
+ max: number;
68
+ };
69
+ speakerChanges?: {
70
+ timestamp: number;
71
+ speaker: number;
72
+ }[];
73
+ }
74
+ //# sourceMappingURL=AudioAnalysis.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AudioAnalysis.types.d.ts","sourceRoot":"","sources":["../../src/AudioAnalysis/AudioAnalysis.types.ts"],"names":[],"mappings":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AM,CAAA;IACtB,WAAW,CAAC,EAAE,MAAM,CAAA;IAEpB,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB,OAAO,CAAC,EAAE,MAAM,CAAA;CACnB;AAED,MAAM,MAAM,kBAAkB,GAAG,MAAM,GAAG,KAAK,CAAA;AAE/C;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B,eAAe,EAAE,MAAM,CAAA;IACvB,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;IACf,gBAAgB,EAAE,MAAM,CAAA;IACxB,UAAU,EAAE,MAAM,CAAA;IAClB,UAAU,EAAE,SAAS,EAAE,CAAA;IACvB,kBAAkB,EAAE,kBAAkB,CAAA;IACtC,cAAc,EAAE;QACZ,GAAG,EAAE,MAAM,CAAA;QACX,GAAG,EAAE,MAAM,CAAA;KACd,CAAA;IAED,cAAc,CAAC,EAAE;QACb,SAAS,EAAE,MAAM,CAAA;QACjB,OAAO,EAAE,MAAM,CAAA;KAClB,EAAE,CAAA;CACN"}
@@ -0,0 +1,3 @@
1
+ // packages/expo-audio-stream/src/AudioAnalysis/AudioAnalysis.types.ts
2
+ export {};
3
+ //# sourceMappingURL=AudioAnalysis.types.js.map
@@ -0,0 +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 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"]}
@@ -0,0 +1,22 @@
1
+ import { ConsoleLike } from '../ExpoAudioStream.types';
2
+ import { AmplitudeAlgorithm, AudioAnalysis, AudioFeaturesOptions } from './AudioAnalysis.types';
3
+ import { WavFileInfo } from '../utils/getWavFileInfo';
4
+ export interface ExtractAudioAnalysisProps {
5
+ fileUri?: string;
6
+ wavMetadata?: WavFileInfo;
7
+ arrayBuffer?: ArrayBuffer;
8
+ bitDepth?: number;
9
+ skipWavHeader?: boolean;
10
+ durationMs?: number;
11
+ sampleRate?: number;
12
+ numberOfChannels?: number;
13
+ algorithm?: AmplitudeAlgorithm;
14
+ position?: number;
15
+ length?: number;
16
+ pointsPerSecond?: number;
17
+ features?: AudioFeaturesOptions;
18
+ featuresExtratorUrl?: string;
19
+ logger?: ConsoleLike;
20
+ }
21
+ export declare const extractAudioAnalysis: ({ fileUri, pointsPerSecond, arrayBuffer, bitDepth, skipWavHeader, durationMs, sampleRate, numberOfChannels, algorithm, features, featuresExtratorUrl, logger, }: ExtractAudioAnalysisProps) => Promise<AudioAnalysis>;
22
+ //# sourceMappingURL=extractAudioAnalysis.d.ts.map
@@ -0,0 +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,EACvB,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;CACvB;AAED,eAAO,MAAM,oBAAoB,oKAa9B,yBAAyB,KAAG,QAAQ,aAAa,CAsGnD,CAAA"}
@@ -0,0 +1,86 @@
1
+ import ExpoAudioStreamModule from '../ExpoAudioStreamModule';
2
+ import { isWeb } from '../constants';
3
+ import { convertPCMToFloat32 } from '../utils/convertPCMToFloat32';
4
+ import { getWavFileInfo } from '../utils/getWavFileInfo';
5
+ import { InlineFeaturesExtractor } from '../workers/InlineFeaturesExtractor.web';
6
+ export const extractAudioAnalysis = async ({ fileUri, pointsPerSecond = 20, arrayBuffer, bitDepth, skipWavHeader = true, durationMs, sampleRate, numberOfChannels, algorithm = 'rms', features, featuresExtratorUrl, logger, }) => {
7
+ if (isWeb) {
8
+ if (!arrayBuffer && !fileUri) {
9
+ throw new Error('Either arrayBuffer or fileUri must be provided');
10
+ }
11
+ if (!arrayBuffer) {
12
+ logger?.log(`fetching fileUri`, fileUri);
13
+ const response = await fetch(fileUri);
14
+ if (!response.ok) {
15
+ throw new Error(`Failed to fetch fileUri: ${response.statusText}`);
16
+ }
17
+ arrayBuffer = await response.arrayBuffer();
18
+ logger?.log(`fetched fileUri`, arrayBuffer.byteLength, arrayBuffer);
19
+ }
20
+ // Create a new copy of the ArrayBuffer to avoid detachment issues
21
+ const bufferCopy = arrayBuffer.slice(0);
22
+ logger?.log(`extractAudioAnalysis skipWavHeader=${skipWavHeader} bitDepth=${bitDepth} len=${bufferCopy.byteLength}`, bufferCopy.slice(0, 100));
23
+ let actualBitDepth = bitDepth;
24
+ if (!actualBitDepth) {
25
+ logger?.log(`extractAudioAnalysis bitDepth not provided -- getting wav file info`);
26
+ const fileInfo = await getWavFileInfo(bufferCopy);
27
+ actualBitDepth = fileInfo.bitDepth;
28
+ }
29
+ logger?.log(`extractAudioAnalysis actualBitDepth=${actualBitDepth}`);
30
+ const { pcmValues: channelData, min, max, } = await convertPCMToFloat32({
31
+ buffer: arrayBuffer,
32
+ bitDepth: actualBitDepth,
33
+ skipWavHeader,
34
+ });
35
+ logger?.log(`extractAudioAnalysis skipWaveHeader=${skipWavHeader} convertPCMToFloat32 length=${channelData.length} range: [ ${min} :: ${max} ]`);
36
+ return new Promise((resolve, reject) => {
37
+ let worker;
38
+ if (featuresExtratorUrl) {
39
+ worker = new Worker(new URL(featuresExtratorUrl, window.location.href));
40
+ }
41
+ else {
42
+ const blob = new Blob([InlineFeaturesExtractor], {
43
+ type: 'application/javascript',
44
+ });
45
+ const url = URL.createObjectURL(blob);
46
+ worker = new Worker(url);
47
+ }
48
+ worker.onmessage = (event) => {
49
+ resolve(event.data.result);
50
+ };
51
+ worker.onerror = (error) => {
52
+ reject(error);
53
+ };
54
+ worker.postMessage({
55
+ command: 'process',
56
+ channelData,
57
+ sampleRate,
58
+ pointsPerSecond,
59
+ algorithm,
60
+ bitDepth,
61
+ fullAudioDurationMs: durationMs,
62
+ numberOfChannels,
63
+ });
64
+ });
65
+ }
66
+ else {
67
+ if (!fileUri) {
68
+ throw new Error('fileUri is required');
69
+ }
70
+ logger?.log(`extractAudioAnalysis`, {
71
+ fileUri,
72
+ pointsPerSecond,
73
+ algorithm,
74
+ });
75
+ const res = await ExpoAudioStreamModule.extractAudioAnalysis({
76
+ fileUri,
77
+ pointsPerSecond,
78
+ skipWavHeader,
79
+ algorithm,
80
+ features,
81
+ });
82
+ logger?.log(`extractAudioAnalysis`, res);
83
+ return res;
84
+ }
85
+ };
86
+ //# sourceMappingURL=extractAudioAnalysis.js.map
@@ -0,0 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BACrC,MAAM,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,CAAA;YAC5B,CAAC;YAED,MAAM,CAAC,SAAS,GAAG,CAAC,KAAK,EAAE,EAAE;gBACzB,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;YAC9B,CAAC,CAAA;YAED,MAAM,CAAC,OAAO,GAAG,CAAC,KAAK,EAAE,EAAE;gBACvB,MAAM,CAAC,KAAK,CAAC,CAAA;YACjB,CAAC,CAAA;YAED,MAAM,CAAC,WAAW,CAAC;gBACf,OAAO,EAAE,SAAS;gBAClB,WAAW;gBACX,UAAU;gBACV,eAAe;gBACf,SAAS;gBACT,QAAQ;gBACR,mBAAmB,EAAE,UAAU;gBAC/B,gBAAgB;aACnB,CAAC,CAAA;QACN,CAAC,CAAC,CAAA;IACN,CAAC;SAAM,CAAC;QACJ,IAAI,CAAC,OAAO,EAAE,CAAC;YACX,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAA;QAC1C,CAAC;QACD,MAAM,EAAE,GAAG,CAAC,sBAAsB,EAAE;YAChC,OAAO;YACP,eAAe;YACf,SAAS;SACZ,CAAC,CAAA;QACF,MAAM,GAAG,GAAG,MAAM,qBAAqB,CAAC,oBAAoB,CAAC;YACzD,OAAO;YACP,eAAe;YACf,aAAa;YACb,SAAS;YACT,QAAQ;SACX,CAAC,CAAA;QACF,MAAM,EAAE,GAAG,CAAC,sBAAsB,EAAE,GAAG,CAAC,CAAA;QACxC,OAAO,GAAG,CAAA;IACd,CAAC;AACL,CAAC,CAAA","sourcesContent":["// packages/expo-audio-stream/src/AudioAnalysis/extractAudioAnalysis.ts\nimport { ConsoleLike } from '../ExpoAudioStream.types'\nimport ExpoAudioStreamModule from '../ExpoAudioStreamModule'\nimport { isWeb } from '../constants'\nimport {\n AmplitudeAlgorithm,\n AudioAnalysis,\n AudioFeaturesOptions,\n} from './AudioAnalysis.types'\nimport { convertPCMToFloat32 } from '../utils/convertPCMToFloat32'\nimport { getWavFileInfo, WavFileInfo } from '../utils/getWavFileInfo'\nimport { InlineFeaturesExtractor } from '../workers/InlineFeaturesExtractor.web'\n\nexport interface ExtractAudioAnalysisProps {\n fileUri?: string // should provide either fileUri or arrayBuffer\n wavMetadata?: WavFileInfo\n arrayBuffer?: ArrayBuffer\n bitDepth?: number\n skipWavHeader?: boolean\n durationMs?: number\n sampleRate?: number\n numberOfChannels?: number\n algorithm?: AmplitudeAlgorithm\n position?: number // Optional number of bytes to skip. Default is 0\n length?: number // Optional number of bytes to read.\n pointsPerSecond?: number // Optional number of points per second. Use to reduce the number of points and compute the number of datapoints to return.\n features?: AudioFeaturesOptions\n featuresExtratorUrl?: string\n logger?: ConsoleLike\n}\n\nexport const extractAudioAnalysis = async ({\n fileUri,\n pointsPerSecond = 20,\n arrayBuffer,\n bitDepth,\n skipWavHeader = true,\n durationMs,\n sampleRate,\n numberOfChannels,\n algorithm = 'rms',\n features,\n featuresExtratorUrl,\n logger,\n}: ExtractAudioAnalysisProps): Promise<AudioAnalysis> => {\n if (isWeb) {\n if (!arrayBuffer && !fileUri) {\n throw new Error('Either arrayBuffer or fileUri must be provided')\n }\n\n if (!arrayBuffer) {\n logger?.log(`fetching fileUri`, fileUri)\n const response = await fetch(fileUri!)\n\n if (!response.ok) {\n throw new Error(\n `Failed to fetch fileUri: ${response.statusText}`\n )\n }\n\n arrayBuffer = await response.arrayBuffer()\n logger?.log(`fetched fileUri`, arrayBuffer.byteLength, arrayBuffer)\n }\n\n // Create a new copy of the ArrayBuffer to avoid detachment issues\n const bufferCopy = arrayBuffer.slice(0)\n logger?.log(\n `extractAudioAnalysis skipWavHeader=${skipWavHeader} bitDepth=${bitDepth} len=${bufferCopy.byteLength}`,\n bufferCopy.slice(0, 100)\n )\n\n let actualBitDepth = bitDepth\n if (!actualBitDepth) {\n logger?.log(\n `extractAudioAnalysis bitDepth not provided -- getting wav file info`\n )\n const fileInfo = await getWavFileInfo(bufferCopy)\n actualBitDepth = fileInfo.bitDepth\n }\n logger?.log(`extractAudioAnalysis actualBitDepth=${actualBitDepth}`)\n\n const {\n pcmValues: channelData,\n min,\n max,\n } = await convertPCMToFloat32({\n buffer: arrayBuffer,\n bitDepth: actualBitDepth,\n skipWavHeader,\n })\n logger?.log(\n `extractAudioAnalysis skipWaveHeader=${skipWavHeader} convertPCMToFloat32 length=${channelData.length} range: [ ${min} :: ${max} ]`\n )\n\n return new Promise((resolve, reject) => {\n let worker: Worker\n if (featuresExtratorUrl) {\n worker = new Worker(\n new URL(featuresExtratorUrl, window.location.href)\n )\n } else {\n const blob = new Blob([InlineFeaturesExtractor], {\n type: 'application/javascript',\n })\n const url = URL.createObjectURL(blob)\n worker = new Worker(url)\n }\n\n worker.onmessage = (event) => {\n resolve(event.data.result)\n }\n\n worker.onerror = (error) => {\n reject(error)\n }\n\n worker.postMessage({\n command: 'process',\n channelData,\n sampleRate,\n pointsPerSecond,\n algorithm,\n bitDepth,\n fullAudioDurationMs: durationMs,\n numberOfChannels,\n })\n })\n } else {\n if (!fileUri) {\n throw new Error('fileUri is required')\n }\n logger?.log(`extractAudioAnalysis`, {\n fileUri,\n pointsPerSecond,\n algorithm,\n })\n const res = await ExpoAudioStreamModule.extractAudioAnalysis({\n fileUri,\n pointsPerSecond,\n skipWavHeader,\n algorithm,\n features,\n })\n logger?.log(`extractAudioAnalysis`, res)\n return res\n }\n}\n"]}
@@ -0,0 +1,8 @@
1
+ export interface ExtractWaveformProps {
2
+ fileUri: string;
3
+ numberOfSamples: number;
4
+ offset?: number;
5
+ length?: number;
6
+ }
7
+ export declare const extractWaveform: ({ fileUri, numberOfSamples, offset, length, }: ExtractWaveformProps) => Promise<unknown>;
8
+ //# sourceMappingURL=extractWaveform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractWaveform.d.ts","sourceRoot":"","sources":["../../src/AudioAnalysis/extractWaveform.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,oBAAoB;IACjC,OAAO,EAAE,MAAM,CAAA;IACf,eAAe,EAAE,MAAM,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,MAAM,CAAC,EAAE,MAAM,CAAA;CAClB;AACD,eAAO,MAAM,eAAe,kDAKzB,oBAAoB,KAAG,QAAQ,OAAO,CAQxC,CAAA"}
@@ -0,0 +1,11 @@
1
+ import ExpoAudioStreamModule from '../ExpoAudioStreamModule';
2
+ export const extractWaveform = async ({ fileUri, numberOfSamples, offset = 0, length, }) => {
3
+ const res = await ExpoAudioStreamModule.extractAudioAnalysis({
4
+ fileUri,
5
+ numberOfSamples,
6
+ offset,
7
+ length,
8
+ });
9
+ return res;
10
+ };
11
+ //# sourceMappingURL=extractWaveform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"extractWaveform.js","sourceRoot":"","sources":["../../src/AudioAnalysis/extractWaveform.ts"],"names":[],"mappings":"AAAA,OAAO,qBAAqB,MAAM,0BAA0B,CAAA;AAQ5D,MAAM,CAAC,MAAM,eAAe,GAAG,KAAK,EAAE,EAClC,OAAO,EACP,eAAe,EACf,MAAM,GAAG,CAAC,EACV,MAAM,GACa,EAAoB,EAAE;IACzC,MAAM,GAAG,GAAG,MAAM,qBAAqB,CAAC,oBAAoB,CAAC;QACzD,OAAO;QACP,eAAe;QACf,MAAM;QACN,MAAM;KACT,CAAC,CAAA;IACF,OAAO,GAAG,CAAA;AACd,CAAC,CAAA","sourcesContent":["import ExpoAudioStreamModule from '../ExpoAudioStreamModule'\n\nexport interface ExtractWaveformProps {\n fileUri: string\n numberOfSamples: number\n offset?: number\n length?: number\n}\nexport const extractWaveform = async ({\n fileUri,\n numberOfSamples,\n offset = 0,\n length,\n}: ExtractWaveformProps): Promise<unknown> => {\n const res = await ExpoAudioStreamModule.extractAudioAnalysis({\n fileUri,\n numberOfSamples,\n offset,\n length,\n })\n return res\n}\n"]}
@@ -0,0 +1,11 @@
1
+ import React from 'react';
2
+ import { UseAudioRecorderState } from './ExpoAudioStream.types';
3
+ import { UseAudioRecorderProps } from './useAudioRecorder';
4
+ interface AudioRecorderProviderProps {
5
+ children: React.ReactNode;
6
+ config?: UseAudioRecorderProps;
7
+ }
8
+ export declare const AudioRecorderProvider: React.FC<AudioRecorderProviderProps>;
9
+ export declare const useSharedAudioRecorder: () => UseAudioRecorderState;
10
+ export {};
11
+ //# sourceMappingURL=AudioRecorder.provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AudioRecorder.provider.d.ts","sourceRoot":"","sources":["../src/AudioRecorder.provider.tsx"],"names":[],"mappings":"AACA,OAAO,KAAoC,MAAM,OAAO,CAAA;AAExD,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAA;AAC/D,OAAO,EAAE,qBAAqB,EAAoB,MAAM,oBAAoB,CAAA;AAuB5E,UAAU,0BAA0B;IAChC,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,MAAM,CAAC,EAAE,qBAAqB,CAAA;CACjC;AAED,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,EAAE,CAAC,0BAA0B,CAUtE,CAAA;AAED,eAAO,MAAM,sBAAsB,6BAQlC,CAAA"}
@@ -0,0 +1,36 @@
1
+ // packages/expo-audio-stream/src/AudioRecorder.provider.tsx
2
+ import React, { createContext, useContext } from 'react';
3
+ import { useAudioRecorder } from './useAudioRecorder';
4
+ const initContext = {
5
+ isRecording: false,
6
+ isPaused: false,
7
+ durationMs: 0,
8
+ size: 0,
9
+ startRecording: async () => {
10
+ throw new Error('AudioRecorderProvider not found');
11
+ },
12
+ stopRecording: async () => {
13
+ throw new Error('AudioRecorderProvider not found');
14
+ },
15
+ pauseRecording: async () => {
16
+ throw new Error('AudioRecorderProvider not found');
17
+ },
18
+ resumeRecording: async () => {
19
+ throw new Error('AudioRecorderProvider not found');
20
+ },
21
+ };
22
+ const AudioRecorderContext = createContext(initContext);
23
+ export const AudioRecorderProvider = ({ children, config = {}, }) => {
24
+ const audioRecorder = useAudioRecorder(config);
25
+ return (<AudioRecorderContext.Provider value={audioRecorder}>
26
+ {children}
27
+ </AudioRecorderContext.Provider>);
28
+ };
29
+ export const useSharedAudioRecorder = () => {
30
+ const context = useContext(AudioRecorderContext);
31
+ if (!context) {
32
+ throw new Error('useSharedAudioRecorder must be used within an AudioRecorderProvider');
33
+ }
34
+ return context;
35
+ };
36
+ //# sourceMappingURL=AudioRecorder.provider.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AudioRecorder.provider.js","sourceRoot":"","sources":["../src/AudioRecorder.provider.tsx"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,OAAO,KAAK,EAAE,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAA;AAGxD,OAAO,EAAyB,gBAAgB,EAAE,MAAM,oBAAoB,CAAA;AAE5E,MAAM,WAAW,GAA0B;IACvC,WAAW,EAAE,KAAK;IAClB,QAAQ,EAAE,KAAK;IACf,UAAU,EAAE,CAAC;IACb,IAAI,EAAE,CAAC;IACP,cAAc,EAAE,KAAK,IAAI,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;IACtD,CAAC;IACD,aAAa,EAAE,KAAK,IAAI,EAAE;QACtB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;IACtD,CAAC;IACD,cAAc,EAAE,KAAK,IAAI,EAAE;QACvB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;IACtD,CAAC;IACD,eAAe,EAAE,KAAK,IAAI,EAAE;QACxB,MAAM,IAAI,KAAK,CAAC,iCAAiC,CAAC,CAAA;IACtD,CAAC;CACJ,CAAA;AAED,MAAM,oBAAoB,GAAG,aAAa,CAAwB,WAAW,CAAC,CAAA;AAO9E,MAAM,CAAC,MAAM,qBAAqB,GAAyC,CAAC,EACxE,QAAQ,EACR,MAAM,GAAG,EAAE,GACd,EAAE,EAAE;IACD,MAAM,aAAa,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAA;IAC9C,OAAO,CACH,CAAC,oBAAoB,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC,aAAa,CAAC,CAChD;YAAA,CAAC,QAAQ,CACb;QAAA,EAAE,oBAAoB,CAAC,QAAQ,CAAC,CACnC,CAAA;AACL,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAAG,EAAE;IACvC,MAAM,OAAO,GAAG,UAAU,CAAC,oBAAoB,CAAC,CAAA;IAChD,IAAI,CAAC,OAAO,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACX,qEAAqE,CACxE,CAAA;IACL,CAAC;IACD,OAAO,OAAO,CAAA;AAClB,CAAC,CAAA","sourcesContent":["// packages/expo-audio-stream/src/AudioRecorder.provider.tsx\nimport React, { createContext, useContext } from 'react'\n\nimport { UseAudioRecorderState } from './ExpoAudioStream.types'\nimport { UseAudioRecorderProps, useAudioRecorder } from './useAudioRecorder'\n\nconst initContext: UseAudioRecorderState = {\n isRecording: false,\n isPaused: false,\n durationMs: 0,\n size: 0,\n startRecording: async () => {\n throw new Error('AudioRecorderProvider not found')\n },\n stopRecording: async () => {\n throw new Error('AudioRecorderProvider not found')\n },\n pauseRecording: async () => {\n throw new Error('AudioRecorderProvider not found')\n },\n resumeRecording: async () => {\n throw new Error('AudioRecorderProvider not found')\n },\n}\n\nconst AudioRecorderContext = createContext<UseAudioRecorderState>(initContext)\n\ninterface AudioRecorderProviderProps {\n children: React.ReactNode\n config?: UseAudioRecorderProps\n}\n\nexport const AudioRecorderProvider: React.FC<AudioRecorderProviderProps> = ({\n children,\n config = {},\n}) => {\n const audioRecorder = useAudioRecorder(config)\n return (\n <AudioRecorderContext.Provider value={audioRecorder}>\n {children}\n </AudioRecorderContext.Provider>\n )\n}\n\nexport const useSharedAudioRecorder = () => {\n const context = useContext(AudioRecorderContext)\n if (!context) {\n throw new Error(\n 'useSharedAudioRecorder must be used within an AudioRecorderProvider'\n )\n }\n return context\n}\n"]}
@@ -0,0 +1,3 @@
1
+ declare const _default: any;
2
+ export default _default;
3
+ //# sourceMappingURL=ExpoAudioStream.native.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoAudioStream.native.d.ts","sourceRoot":"","sources":["../src/ExpoAudioStream.native.ts"],"names":[],"mappings":";AAKA,wBAAqD"}
@@ -0,0 +1,6 @@
1
+ // src/ExpoAudioStreamModule.ts
2
+ import { requireNativeModule } from 'expo-modules-core';
3
+ // It loads the native module object from the JSI or falls back to
4
+ // the bridge module (from NativeModulesProxy) if the remote debugger is on.
5
+ export default requireNativeModule('ExpoAudioStream');
6
+ //# sourceMappingURL=ExpoAudioStream.native.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoAudioStream.native.js","sourceRoot":"","sources":["../src/ExpoAudioStream.native.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAEvD,kEAAkE;AAClE,4EAA4E;AAC5E,eAAe,mBAAmB,CAAC,iBAAiB,CAAC,CAAA","sourcesContent":["// src/ExpoAudioStreamModule.ts\nimport { requireNativeModule } from 'expo-modules-core'\n\n// It loads the native module object from the JSI or falls back to\n// the bridge module (from NativeModulesProxy) if the remote debugger is on.\nexport default requireNativeModule('ExpoAudioStream')\n"]}
@@ -0,0 +1,127 @@
1
+ import { AmplitudeAlgorithm, AudioAnalysis, AudioFeaturesOptions } from './AudioAnalysis/AudioAnalysis.types';
2
+ import { AudioAnalysisEvent } from './events';
3
+ export interface AudioStreamStatus {
4
+ isRecording: boolean;
5
+ isPaused: boolean;
6
+ durationMs: number;
7
+ size: number;
8
+ interval: number;
9
+ mimeType: string;
10
+ }
11
+ export interface AudioDataEvent {
12
+ data: string | Float32Array;
13
+ position: number;
14
+ fileUri: string;
15
+ eventDataSize: number;
16
+ totalSize: number;
17
+ }
18
+ export type EncodingType = 'pcm_32bit' | 'pcm_16bit' | 'pcm_8bit';
19
+ export type SampleRate = 16000 | 44100 | 48000;
20
+ export type BitDepth = 8 | 16 | 32;
21
+ export type ConsoleLike = {
22
+ log: (message: string, ...args: unknown[]) => void;
23
+ debug: (message: string, ...args: unknown[]) => void;
24
+ warn: (message: string, ...args: unknown[]) => void;
25
+ error: (message: string, ...args: unknown[]) => void;
26
+ };
27
+ export interface Chunk {
28
+ text: string;
29
+ timestamp: [number, number | null];
30
+ }
31
+ export interface TranscriberData {
32
+ id: string;
33
+ isBusy: boolean;
34
+ text: string;
35
+ startTime: number;
36
+ endTime: number;
37
+ chunks: Chunk[];
38
+ }
39
+ export interface AudioRecording {
40
+ fileUri: string;
41
+ filename: string;
42
+ durationMs: number;
43
+ size: number;
44
+ mimeType: string;
45
+ channels: number;
46
+ bitDepth: BitDepth;
47
+ sampleRate: SampleRate;
48
+ transcripts?: TranscriberData[];
49
+ wavPCMData?: Float32Array;
50
+ analysisData?: AudioAnalysis;
51
+ }
52
+ export interface StartRecordingResult {
53
+ fileUri: string;
54
+ mimeType: string;
55
+ channels?: number;
56
+ bitDepth?: BitDepth;
57
+ sampleRate?: SampleRate;
58
+ }
59
+ export interface AudioSessionConfig {
60
+ category?: 'Ambient' | 'SoloAmbient' | 'Playback' | 'Record' | 'PlayAndRecord' | 'MultiRoute';
61
+ mode?: 'Default' | 'VoiceChat' | 'VideoChat' | 'GameChat' | 'VideoRecording' | 'Measurement' | 'MoviePlayback' | 'SpokenAudio';
62
+ categoryOptions?: ('MixWithOthers' | 'DuckOthers' | 'InterruptSpokenAudioAndMixWithOthers' | 'AllowBluetooth' | 'AllowBluetoothA2DP' | 'AllowAirPlay' | 'DefaultToSpeaker')[];
63
+ }
64
+ export interface IOSConfig {
65
+ audioSession?: AudioSessionConfig;
66
+ }
67
+ export interface RecordingConfig {
68
+ sampleRate?: SampleRate;
69
+ channels?: 1 | 2;
70
+ encoding?: EncodingType;
71
+ interval?: number;
72
+ keepAwake?: boolean;
73
+ showNotification?: boolean;
74
+ showWaveformInNotification?: boolean;
75
+ notification?: NotificationConfig;
76
+ enableProcessing?: boolean;
77
+ ios?: IOSConfig;
78
+ pointsPerSecond?: number;
79
+ algorithm?: AmplitudeAlgorithm;
80
+ features?: AudioFeaturesOptions;
81
+ onAudioStream?: (_: AudioDataEvent) => Promise<void>;
82
+ onAudioAnalysis?: (_: AudioAnalysisEvent) => Promise<void>;
83
+ }
84
+ export interface NotificationConfig {
85
+ title?: string;
86
+ text?: string;
87
+ icon?: string;
88
+ android?: {
89
+ channelId?: string;
90
+ channelName?: string;
91
+ channelDescription?: string;
92
+ notificationId?: number;
93
+ actions?: NotificationAction[];
94
+ waveform?: WaveformConfig;
95
+ lightColor?: string;
96
+ priority?: 'min' | 'low' | 'default' | 'high' | 'max';
97
+ accentColor?: string;
98
+ };
99
+ ios?: {
100
+ categoryIdentifier?: string;
101
+ };
102
+ }
103
+ export interface NotificationAction {
104
+ title: string;
105
+ identifier: string;
106
+ icon?: string;
107
+ }
108
+ export interface WaveformConfig {
109
+ color?: string;
110
+ opacity?: number;
111
+ strokeWidth?: number;
112
+ style?: 'stroke' | 'fill';
113
+ mirror?: boolean;
114
+ height?: number;
115
+ }
116
+ export interface UseAudioRecorderState {
117
+ startRecording: (_: RecordingConfig) => Promise<StartRecordingResult>;
118
+ stopRecording: () => Promise<AudioRecording | null>;
119
+ pauseRecording: () => Promise<void>;
120
+ resumeRecording: () => Promise<void>;
121
+ isRecording: boolean;
122
+ isPaused: boolean;
123
+ durationMs: number;
124
+ size: number;
125
+ analysisData?: AudioAnalysis;
126
+ }
127
+ //# sourceMappingURL=ExpoAudioStream.types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ExpoAudioStream.types.d.ts","sourceRoot":"","sources":["../src/ExpoAudioStream.types.ts"],"names":[],"mappings":"AACA,OAAO,EACH,kBAAkB,EAClB,aAAa,EACb,oBAAoB,EACvB,MAAM,qCAAqC,CAAA;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAE7C,MAAM,WAAW,iBAAiB;IAC9B,WAAW,E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