@siteed/expo-audio-studio 2.9.0 → 2.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -1
- package/android/build.gradle +9 -0
- package/android/src/androidTest/assets/chorus.wav +0 -0
- package/android/src/androidTest/assets/jfk.wav +0 -0
- package/android/src/androidTest/assets/osr_us_000_0010_8k.wav +0 -0
- package/android/src/androidTest/assets/recorder_hello_world.wav +0 -0
- package/android/src/androidTest/java/net/siteed/audiostream/AudioProcessorInstrumentedTest.kt +197 -0
- package/android/src/androidTest/java/net/siteed/audiostream/AudioRecorderInstrumentedTest.kt +541 -0
- package/android/src/androidTest/java/net/siteed/audiostream/integration/BufferDurationIntegrationTest.kt +324 -0
- package/android/src/androidTest/java/net/siteed/audiostream/integration/OutputControlIntegrationTest.kt +340 -0
- package/android/src/androidTest/java/net/siteed/audiostream/integration/README.md +95 -0
- package/android/src/androidTest/java/net/siteed/audiostream/integration/run_integration_tests.sh +28 -0
- package/android/src/main/java/net/siteed/audiostream/AudioFormatUtils.kt +264 -13
- package/android/src/main/java/net/siteed/audiostream/AudioProcessor.kt +3 -13
- package/android/src/main/java/net/siteed/audiostream/AudioRecorderManager.kt +118 -55
- package/android/src/main/java/net/siteed/audiostream/LogUtils.kt +32 -4
- package/android/src/main/java/net/siteed/audiostream/RecordingConfig.kt +50 -15
- package/android/src/test/java/net/siteed/audiostream/AudioFileHandlerTest.kt +279 -0
- package/android/src/test/java/net/siteed/audiostream/AudioFormatUtilsTest.kt +273 -0
- package/android/src/test/resources/chorus.wav +0 -0
- package/android/src/test/resources/generate_test_audio.py +94 -0
- package/android/src/test/resources/jfk.wav +0 -0
- package/android/src/test/resources/osr_us_000_0010_8k.wav +0 -0
- package/android/src/test/resources/recorder_hello_world.wav +0 -0
- package/build/cjs/ExpoAudioStream.types.js.map +1 -1
- package/build/cjs/ExpoAudioStream.web.js +37 -34
- package/build/cjs/ExpoAudioStream.web.js.map +1 -1
- package/build/cjs/WebRecorder.web.js +12 -10
- package/build/cjs/WebRecorder.web.js.map +1 -1
- package/build/cjs/useAudioRecorder.js.map +1 -1
- package/build/esm/ExpoAudioStream.types.js.map +1 -1
- package/build/esm/ExpoAudioStream.web.js +37 -34
- package/build/esm/ExpoAudioStream.web.js.map +1 -1
- package/build/esm/WebRecorder.web.js +12 -10
- package/build/esm/WebRecorder.web.js.map +1 -1
- package/build/esm/useAudioRecorder.js.map +1 -1
- package/build/types/ExpoAudioStream.types.d.ts +54 -22
- package/build/types/ExpoAudioStream.types.d.ts.map +1 -1
- package/build/types/ExpoAudioStream.web.d.ts.map +1 -1
- package/build/types/WebRecorder.web.d.ts.map +1 -1
- package/ios/AudioNotificationManager.swift +2 -6
- package/ios/AudioStreamManager.swift +116 -50
- package/ios/ExpoAudioStream.podspec +6 -0
- package/ios/ExpoAudioStreamModule.swift +11 -8
- package/ios/ExpoAudioStudioTests/AudioFileHandlerTests.swift +338 -0
- package/ios/ExpoAudioStudioTests/AudioFormatUtilsTests.swift +331 -0
- package/ios/ExpoAudioStudioTests/AudioTestHelpers.swift +130 -0
- package/ios/ExpoAudioStudioTests/Info.plist +22 -0
- package/ios/ExpoAudioStudioTests/SimpleAudioTest.swift +98 -0
- package/ios/ExpoAudioStudioTests/TestAudioGenerator.swift +75 -0
- package/ios/RecordingSettings.swift +53 -22
- package/ios/tests/integration/buffer_duration_test.swift +185 -0
- package/ios/tests/integration/output_control_test.swift +322 -0
- package/ios/tests/integration/run_integration_tests.sh +27 -0
- package/ios/tests/standalone/audio_processing_test.swift +144 -0
- package/ios/tests/standalone/audio_recording_test.swift +277 -0
- package/ios/tests/standalone/audio_streaming_test.swift +249 -0
- package/ios/tests/standalone/standalone_test.swift +144 -0
- package/package.json +140 -133
- package/src/ExpoAudioStream.types.ts +66 -22
- package/src/ExpoAudioStream.web.ts +43 -38
- package/src/WebRecorder.web.ts +13 -10
- package/src/useAudioRecorder.tsx +1 -1
- package/android/src/main/test/java/net/siteed/audiostream/AudioProcessorTest.kt +0 -56
- package/ios/siteedexpoaudiostudio.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
- package/ios/siteedexpoaudiostudio.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
- /package/plugin/build/{index.d.ts → index.d.cts} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoAudioStream.types.js","sourceRoot":"","sources":["../../src/ExpoAudioStream.types.ts"],"names":[],"mappings":";;;AAyRA,4EAA4E;AAC/D,QAAA,2BAA2B,GAAG;IACvC,8CAA8C;IAC9C,KAAK,EAAE,OAAO;IACd,sDAAsD;IACtD,QAAQ,EAAE,UAAU;CACd,CAAA","sourcesContent":["// packages/expo-audio-stream/src/ExpoAudioStream.types.ts\nimport {\n AudioAnalysis,\n AudioFeaturesOptions,\n DecodingConfig,\n} from './AudioAnalysis/AudioAnalysis.types'\nimport { AudioAnalysisEvent } from './events'\n\nexport interface CompressionInfo {\n /** Size of the compressed audio data in bytes */\n size: number\n /** MIME type of the compressed audio (e.g., 'audio/aac', 'audio/opus') */\n mimeType: string\n /** Bitrate of the compressed audio in bits per second */\n bitrate: number\n /** Format of the compression (e.g., 'aac', 'opus') */\n format: string\n /** URI to the compressed audio file if available */\n compressedFileUri?: string\n}\n\nexport interface AudioStreamStatus {\n /** Indicates whether audio recording is currently active */\n isRecording: boolean\n /** Indicates whether recording is in a paused state */\n isPaused: boolean\n /** Duration of the current recording in milliseconds */\n durationMs: number\n /** Size of the recorded audio data in bytes */\n size: number\n /** Interval in milliseconds at which recording data is emitted */\n interval: number\n /** Interval in milliseconds at which analysis data is emitted */\n intervalAnalysis: number\n /** MIME type of the recorded audio (e.g., 'audio/wav') */\n mimeType: string\n /** Information about audio compression if enabled */\n compression?: CompressionInfo\n}\n\nexport interface AudioDataEvent {\n /** Audio data as base64 string (native) or Float32Array (web) */\n data: string | Float32Array\n /** Current position in the audio stream in bytes */\n position: number\n /** URI to the file being recorded */\n fileUri: string\n /** Size of the current data chunk in bytes */\n eventDataSize: number\n /** Total size of the recording so far in bytes */\n totalSize: number\n /** Information about compression if enabled, including the compressed data chunk */\n compression?: CompressionInfo & {\n /** Base64 (native) or Blob (web) encoded compressed data chunk */\n data?: string | Blob\n }\n}\n\nexport type EncodingType = 'pcm_32bit' | 'pcm_16bit' | 'pcm_8bit'\nexport type SampleRate = 16000 | 44100 | 48000\nexport type BitDepth = 8 | 16 | 32\nexport type PCMFormat = `pcm_${BitDepth}bit`\n\nexport type ConsoleLike = {\n /** Logs a message with optional arguments */\n log: (message: string, ...args: unknown[]) => void\n /** Logs a debug message with optional arguments */\n debug: (message: string, ...args: unknown[]) => void\n /** Logs an info message with optional arguments */\n info: (message: string, ...args: unknown[]) => void\n /** Logs a warning message with optional arguments */\n warn: (message: string, ...args: unknown[]) => void\n /** Logs an error message with optional arguments */\n error: (message: string, ...args: unknown[]) => void\n}\n\nexport interface Chunk {\n /** Transcribed text content */\n text: string\n /** Start and end timestamp in seconds [start, end] where end can be null if ongoing */\n timestamp: [number, number | null]\n}\n\nexport interface TranscriberData {\n /** Unique identifier for the transcription */\n id: string\n /** Indicates if the transcriber is currently processing */\n isBusy: boolean\n /** Complete transcribed text */\n text: string\n /** Start time of the transcription in milliseconds */\n startTime: number\n /** End time of the transcription in milliseconds */\n endTime: number\n /** Array of transcribed text chunks with timestamps */\n chunks: Chunk[]\n}\n\nexport interface AudioRecording {\n /** URI to the recorded audio file */\n fileUri: string\n /** Filename of the recorded audio */\n filename: string\n /** Duration of the recording in milliseconds */\n durationMs: number\n /** Size of the recording in bytes */\n size: number\n /** MIME type of the recorded audio */\n mimeType: string\n /** Number of audio channels (1 for mono, 2 for stereo) */\n channels: number\n /** Bit depth of the audio (8, 16, or 32 bits) */\n bitDepth: BitDepth\n /** Sample rate of the audio in Hz */\n sampleRate: SampleRate\n /** Timestamp when the recording was created */\n createdAt?: number\n /** Array of transcription data if available */\n transcripts?: TranscriberData[]\n /** Analysis data for the recording if processing was enabled */\n analysisData?: AudioAnalysis\n /** Information about compression if enabled, including the URI to the compressed file */\n compression?: CompressionInfo & {\n /** URI to the compressed audio file */\n compressedFileUri: string\n }\n}\n\nexport interface StartRecordingResult {\n /** URI to the file being recorded */\n fileUri: string\n /** MIME type of the recording */\n mimeType: string\n /** Number of audio channels (1 for mono, 2 for stereo) */\n channels?: number\n /** Bit depth of the audio (8, 16, or 32 bits) */\n bitDepth?: BitDepth\n /** Sample rate of the audio in Hz */\n sampleRate?: SampleRate\n /** Information about compression if enabled, including the URI to the compressed file */\n compression?: CompressionInfo & {\n /** URI to the compressed audio file */\n compressedFileUri: string\n }\n}\n\nexport interface AudioSessionConfig {\n /**\n * Audio session category that defines the audio behavior\n * - 'Ambient': Audio continues with silent switch, mixes with other audio\n * - 'SoloAmbient': Audio continues with silent switch, interrupts other audio\n * - 'Playback': Audio continues in background, interrupts other audio\n * - 'Record': Optimized for recording, interrupts other audio\n * - 'PlayAndRecord': Allows simultaneous playback and recording\n * - 'MultiRoute': Routes audio to multiple outputs simultaneously\n */\n category?:\n | 'Ambient'\n | 'SoloAmbient'\n | 'Playback'\n | 'Record'\n | 'PlayAndRecord'\n | 'MultiRoute'\n /**\n * Audio session mode that defines the behavior for specific use cases\n * - 'Default': Standard audio behavior\n * - 'VoiceChat': Optimized for voice chat applications\n * - 'VideoChat': Optimized for video chat applications\n * - 'GameChat': Optimized for in-game chat\n * - 'VideoRecording': Optimized for video recording\n * - 'Measurement': Optimized for audio measurement\n * - 'MoviePlayback': Optimized for movie playback\n * - 'SpokenAudio': Optimized for spoken audio content\n */\n mode?:\n | 'Default'\n | 'VoiceChat'\n | 'VideoChat'\n | 'GameChat'\n | 'VideoRecording'\n | 'Measurement'\n | 'MoviePlayback'\n | 'SpokenAudio'\n /**\n * Options that modify the behavior of the audio session category\n * - 'MixWithOthers': Allows mixing with other active audio sessions\n * - 'DuckOthers': Reduces the volume of other audio sessions\n * - 'InterruptSpokenAudioAndMixWithOthers': Interrupts spoken audio and mixes with others\n * - 'AllowBluetooth': Allows audio routing to Bluetooth devices\n * - 'AllowBluetoothA2DP': Allows audio routing to Bluetooth A2DP devices\n * - 'AllowAirPlay': Allows audio routing to AirPlay devices\n * - 'DefaultToSpeaker': Routes audio to the speaker by default\n */\n categoryOptions?: (\n | 'MixWithOthers'\n | 'DuckOthers'\n | 'InterruptSpokenAudioAndMixWithOthers'\n | 'AllowBluetooth'\n | 'AllowBluetoothA2DP'\n | 'AllowAirPlay'\n | 'DefaultToSpeaker'\n )[]\n}\n\nexport interface IOSConfig {\n /** Configuration for the iOS audio session */\n audioSession?: AudioSessionConfig\n}\n\n/** Web platform specific configuration options */\nexport interface WebConfig {\n /**\n * Whether to store uncompressed audio data for WAV generation\n *\n * When true, all PCM chunks are stored in memory to create a WAV file when compression is disabled\n * When false, uncompressed audio won't be available, but memory usage will be lower\n *\n * Default: true (for backward compatibility)\n */\n storeUncompressedAudio?: boolean\n}\n\n// Add new type for interruption reasons\nexport type RecordingInterruptionReason =\n /** Audio focus was lost to another app */\n | 'audioFocusLoss'\n /** Audio focus was regained */\n | 'audioFocusGain'\n /** Recording was interrupted by a phone call */\n | 'phoneCall'\n /** Phone call that interrupted recording has ended */\n | 'phoneCallEnded'\n /** Recording was stopped by the system or another app */\n | 'recordingStopped'\n /** Recording device was disconnected */\n | 'deviceDisconnected'\n /** Recording switched to default device after disconnection */\n | 'deviceFallback'\n /** A new audio device was connected */\n | 'deviceConnected'\n /** Device switching failed */\n | 'deviceSwitchFailed'\n\n// Add new interface for interruption events\nexport interface RecordingInterruptionEvent {\n /** The reason for the recording interruption */\n reason: RecordingInterruptionReason\n /** Indicates whether the recording is paused due to the interruption */\n isPaused: boolean\n}\n\nexport interface AudioDeviceCapabilities {\n /** Supported sample rates for the device */\n sampleRates: number[]\n /** Supported channel counts for the device */\n channelCounts: number[]\n /** Supported bit depths for the device */\n bitDepths: number[]\n /** Whether the device supports echo cancellation */\n hasEchoCancellation?: boolean\n /** Whether the device supports noise suppression */\n hasNoiseSuppression?: boolean\n /** Whether the device supports automatic gain control */\n hasAutomaticGainControl?: boolean\n}\n\nexport interface AudioDevice {\n /** Unique identifier for the device */\n id: string\n /** Human-readable name of the device */\n name: string\n /** Device type (builtin_mic, bluetooth, etc.) */\n type: string\n /** Whether this is the system default device */\n isDefault: boolean\n /** Audio capabilities for the device */\n capabilities: AudioDeviceCapabilities\n /** Whether the device is currently available */\n isAvailable: boolean\n}\n\n/** Defines how recording should behave when a device becomes unavailable */\nexport const DeviceDisconnectionBehavior = {\n /** Pause recording when device disconnects */\n PAUSE: 'pause',\n /** Switch to default device and continue recording */\n FALLBACK: 'fallback',\n} as const\n\n/** Type for DeviceDisconnectionBehavior values */\nexport type DeviceDisconnectionBehaviorType =\n (typeof DeviceDisconnectionBehavior)[keyof typeof DeviceDisconnectionBehavior]\n\nexport interface RecordingConfig {\n /** Sample rate for recording in Hz (16000, 44100, or 48000) */\n sampleRate?: SampleRate\n\n /** Number of audio channels (1 for mono, 2 for stereo) */\n channels?: 1 | 2\n\n /** Encoding type for the recording (pcm_32bit, pcm_16bit, pcm_8bit) */\n encoding?: EncodingType\n\n /** Interval in milliseconds at which to emit recording data */\n interval?: number\n\n /** Interval in milliseconds at which to emit analysis data */\n intervalAnalysis?: number\n\n /** Keep the device awake while recording (default is false) */\n keepAwake?: boolean\n\n /** Show a notification during recording (default is false) */\n showNotification?: boolean\n\n /** Show waveform in the notification (Android only, when showNotification is true) */\n showWaveformInNotification?: boolean\n\n /** Configuration for the notification */\n notification?: NotificationConfig\n\n /** Enable audio processing (default is false) */\n enableProcessing?: boolean\n\n /** iOS-specific configuration */\n ios?: IOSConfig\n\n /** Web-specific configuration options */\n web?: WebConfig\n\n /** Duration of each segment in milliseconds for analysis (default: 100) */\n segmentDurationMs?: number\n\n /** Feature options to extract during audio processing */\n features?: AudioFeaturesOptions\n\n /** Callback function to handle audio stream data */\n onAudioStream?: (_: AudioDataEvent) => Promise<void>\n\n /** Callback function to handle audio features extraction results */\n onAudioAnalysis?: (_: AudioAnalysisEvent) => Promise<void>\n\n /** Configuration for audio compression */\n compression?: {\n /** Enable audio compression */\n enabled: boolean\n /**\n * Format for compression\n * - 'aac': Advanced Audio Coding - supported on all platforms\n * - 'opus': Opus encoding - supported on Android and Web; on iOS will automatically fall back to AAC\n */\n format: 'aac' | 'opus'\n /** Bitrate for compression in bits per second */\n bitrate?: number\n }\n\n /** Whether to automatically resume recording after an interruption (default is false) */\n autoResumeAfterInterruption?: boolean\n\n /** Optional callback to handle recording interruptions */\n onRecordingInterrupted?: (_: RecordingInterruptionEvent) => void\n\n /** Optional directory path where output files will be saved */\n outputDirectory?: string // If not provided, uses default app directory\n /** Optional filename for the recording (uses UUID if not provided) */\n filename?: string // If not provided, uses UUID\n\n /** ID of the device to use for recording (if not specified, uses default) */\n deviceId?: string\n\n /** How to handle device disconnection during recording */\n deviceDisconnectionBehavior?: DeviceDisconnectionBehaviorType\n}\n\nexport interface NotificationConfig {\n /** Title of the notification */\n title?: string\n\n /** Main text content of the notification */\n text?: string\n\n /** Icon to be displayed in the notification (resource name or URI) */\n icon?: string\n\n /** Android-specific notification configuration */\n android?: {\n /** Unique identifier for the notification channel */\n channelId?: string\n\n /** User-visible name of the notification channel */\n channelName?: string\n\n /** User-visible description of the notification channel */\n channelDescription?: string\n\n /** Unique identifier for this notification */\n notificationId?: number\n\n /** List of actions that can be performed from the notification */\n actions?: NotificationAction[]\n\n /** Configuration for the waveform visualization in the notification */\n waveform?: WaveformConfig\n\n /** Color of the notification LED (if device supports it) */\n lightColor?: string\n\n /** Priority of the notification (affects how it's displayed) */\n priority?: 'min' | 'low' | 'default' | 'high' | 'max'\n\n /** Accent color for the notification (used for the app icon and buttons) */\n accentColor?: string\n }\n\n /** iOS-specific notification configuration */\n ios?: {\n /** Identifier for the notification category (used for grouping similar notifications) */\n categoryIdentifier?: string\n }\n}\n\nexport interface NotificationAction {\n /** Display title for the action */\n title: string\n\n /** Unique identifier for the action */\n identifier: string\n\n /** Icon to be displayed for the action (Android only) */\n icon?: string\n}\n\nexport interface WaveformConfig {\n /** The color of the waveform (e.g., \"#FFFFFF\" for white) */\n color?: string // The color of the waveform (e.g., \"#FFFFFF\" for white)\n /** Opacity of the waveform (0.0 - 1.0) */\n opacity?: number // Opacity of the waveform (0.0 - 1.0)\n /** Width of the waveform line (default: 1.5) */\n strokeWidth?: number // Width of the waveform line (default: 1.5)\n /** Drawing style: \"stroke\" for outline, \"fill\" for solid */\n style?: 'stroke' | 'fill' // Drawing style: \"stroke\" for outline, \"fill\" for solid\n /** Whether to mirror the waveform (symmetrical display) */\n mirror?: boolean // Whether to mirror the waveform (symmetrical display)\n /** Height of the waveform view in dp (default: 64) */\n height?: number // Height of the waveform view in dp (default: 64)\n}\n\nexport interface ExtractAudioDataOptions {\n /** URI of the audio file to extract data from */\n fileUri: string\n /** Start time in milliseconds (for time-based range) */\n startTimeMs?: number\n /** End time in milliseconds (for time-based range) */\n endTimeMs?: number\n /** Start position in bytes (for byte-based range) */\n position?: number\n /** Length in bytes to extract (for byte-based range) */\n length?: number\n /** Include normalized audio data in [-1, 1] range */\n includeNormalizedData?: boolean\n /** Include base64 encoded string representation of the audio data */\n includeBase64Data?: boolean\n /** Include WAV header in the PCM data (makes it a valid WAV file) */\n includeWavHeader?: boolean\n /** Logger for debugging - can pass console directly. */\n logger?: ConsoleLike\n /** Compute the checksum of the PCM data */\n computeChecksum?: boolean\n /** Target config for the normalized audio (Android and Web) */\n decodingOptions?: DecodingConfig\n}\n\nexport interface ExtractedAudioData {\n /** Raw PCM audio data */\n pcmData: Uint8Array\n /** Normalized audio data in [-1, 1] range (when includeNormalizedData is true) */\n normalizedData?: Float32Array\n /** Base64 encoded string representation of the audio data (when includeBase64Data is true) */\n base64Data?: string\n /** Sample rate in Hz (e.g., 44100, 48000) */\n sampleRate: number\n /** Number of audio channels (1 for mono, 2 for stereo) */\n channels: number\n /** Bits per sample (8, 16, or 32) */\n bitDepth: BitDepth\n /** Duration of the audio in milliseconds */\n durationMs: number\n /** PCM format identifier (e.g., \"pcm_16bit\") */\n format: PCMFormat\n /** Total number of audio samples per channel */\n samples: number\n /** Whether the pcmData includes a WAV header */\n hasWavHeader?: boolean\n /** CRC32 Checksum of PCM data */\n checksum?: number\n}\n\nexport interface UseAudioRecorderState {\n /**\n * Prepares recording with the specified configuration without starting it.\n *\n * This method eliminates the latency between calling startRecording and the actual recording beginning.\n * It pre-initializes all audio resources, requests permissions, and sets up audio sessions in advance,\n * allowing for true zero-latency recording start when startRecording is called later.\n *\n * Technical benefits:\n * - Eliminates audio pipeline initialization delay (50-300ms depending on platform)\n * - Pre-allocates audio buffers to avoid memory allocation during recording start\n * - Initializes audio hardware in advance (particularly important on iOS)\n * - Requests and verifies permissions before the critical recording moment\n *\n * Use this method when:\n * - You need zero-latency recording start (e.g., voice commands, musical applications)\n * - You're building time-sensitive applications where missing initial audio would be problematic\n * - You want to prepare resources during app initialization, screen loading, or preceding user interaction\n * - You need to ensure recording starts reliably and instantly on all platforms\n *\n * @param config - The recording configuration, identical to what you would pass to startRecording\n * @returns A promise that resolves when preparation is complete\n *\n * @example\n * // Prepare during component mounting\n * useEffect(() => {\n * prepareRecording({\n * sampleRate: 44100,\n * channels: 1,\n * encoding: 'pcm_16bit',\n * });\n * }, []);\n *\n * // Later when user taps record button, it starts with zero latency\n * const handleRecordPress = () => startRecording({\n * sampleRate: 44100,\n * channels: 1,\n * encoding: 'pcm_16bit',\n * });\n */\n prepareRecording: (_: RecordingConfig) => Promise<void>\n /** Starts recording with the specified configuration */\n startRecording: (_: RecordingConfig) => Promise<StartRecordingResult>\n /** Stops the current recording and returns the recording data */\n stopRecording: () => Promise<AudioRecording | null>\n /** Pauses the current recording */\n pauseRecording: () => Promise<void>\n /** Resumes a paused recording */\n resumeRecording: () => Promise<void>\n /** Indicates whether recording is currently active */\n isRecording: boolean\n /** Indicates whether recording is in a paused state */\n isPaused: boolean\n /** Duration of the current recording in milliseconds */\n durationMs: number // Duration of the recording\n /** Size of the recorded audio in bytes */\n size: number // Size in bytes of the recorded audio\n /** Information about compression if enabled */\n compression?: CompressionInfo\n /** Analysis data for the recording if processing was enabled */\n analysisData?: AudioAnalysis // Analysis data for the recording depending on enableProcessing flag\n /** Optional callback to handle recording interruptions */\n onRecordingInterrupted?: (_: RecordingInterruptionEvent) => void\n}\n\n/**\n * Represents an event emitted during the trimming process to report progress.\n */\nexport interface TrimProgressEvent {\n /**\n * The percentage of the trimming process that has been completed, ranging from 0 to 100.\n */\n progress: number\n\n /**\n * The number of bytes that have been processed so far. This is optional and may not be provided in all implementations.\n */\n bytesProcessed?: number\n\n /**\n * The total number of bytes to process. This is optional and may not be provided in all implementations.\n */\n totalBytes?: number\n}\n\n/**\n * Defines a time range in milliseconds for trimming operations.\n */\nexport interface TimeRange {\n /**\n * The start time of the range in milliseconds.\n */\n startTimeMs: number\n\n /**\n * The end time of the range in milliseconds.\n */\n endTimeMs: number\n}\n\n/**\n * Options for configuring the audio trimming operation.\n */\nexport interface TrimAudioOptions {\n /**\n * The URI of the audio file to trim.\n */\n fileUri: string\n\n /**\n * The mode of trimming to apply.\n * - `'single'`: Trims the audio to a single range defined by `startTimeMs` and `endTimeMs`.\n * - `'keep'`: Keeps the specified `ranges` and removes all other portions of the audio.\n * - `'remove'`: Removes the specified `ranges` and keeps the remaining portions of the audio.\n * @default 'single'\n */\n mode?: 'single' | 'keep' | 'remove'\n\n /**\n * An array of time ranges to keep or remove, depending on the `mode`.\n * - Required for `'keep'` and `'remove'` modes.\n * - Ignored when `mode` is `'single'`.\n */\n ranges?: TimeRange[]\n\n /**\n * The start time in milliseconds for the `'single'` mode.\n * - If not provided, trimming starts from the beginning of the audio (0 ms).\n */\n startTimeMs?: number\n\n /**\n * The end time in milliseconds for the `'single'` mode.\n * - If not provided, trimming extends to the end of the audio.\n */\n endTimeMs?: number\n\n /**\n * The name of the output file. If not provided, a default name will be generated.\n */\n outputFileName?: string\n\n /**\n * Configuration for the output audio format.\n */\n outputFormat?: {\n /**\n * The format of the output audio file.\n * - `'wav'`: Waveform Audio File Format (uncompressed).\n * - `'aac'`: Advanced Audio Coding (compressed). Not supported on web platforms.\n * - `'opus'`: Opus Interactive Audio Codec (compressed).\n */\n format: 'wav' | 'aac' | 'opus'\n\n /**\n * The sample rate of the output audio in Hertz (Hz).\n * - If not provided, the input audio's sample rate is used.\n */\n sampleRate?: number\n\n /**\n * The number of channels in the output audio (e.g., 1 for mono, 2 for stereo).\n * - If not provided, the input audio's channel count is used.\n */\n channels?: number\n\n /**\n * The bit depth of the output audio, applicable to PCM formats like `'wav'`.\n * - If not provided, the input audio's bit depth is used.\n */\n bitDepth?: number\n\n /**\n * The bitrate of the output audio in bits per second, applicable to compressed formats like `'aac'`.\n * - If not provided, a default bitrate is used based on the format.\n */\n bitrate?: number\n }\n\n /**\n * Options for decoding the input audio file.\n * - See `DecodingConfig` for details.\n */\n decodingOptions?: DecodingConfig\n}\n\n/**\n * Result of the audio trimming operation.\n */\nexport interface TrimAudioResult {\n /**\n * The URI of the trimmed audio file.\n */\n uri: string\n\n /**\n * The filename of the trimmed audio file.\n */\n filename: string\n\n /**\n * The duration of the trimmed audio in milliseconds.\n */\n durationMs: number\n\n /**\n * The size of the trimmed audio file in bytes.\n */\n size: number\n\n /**\n * The sample rate of the trimmed audio in Hertz (Hz).\n */\n sampleRate: number\n\n /**\n * The number of channels in the trimmed audio (e.g., 1 for mono, 2 for stereo).\n */\n channels: number\n\n /**\n * The bit depth of the trimmed audio, applicable to PCM formats like `'wav'`.\n */\n bitDepth: number\n\n /**\n * The MIME type of the trimmed audio file (e.g., `'audio/wav'`, `'audio/mpeg'`).\n */\n mimeType: string\n\n /**\n * Information about compression if the output format is compressed.\n */\n compression?: {\n /**\n * The format of the compression (e.g., `'aac'`, `'mp3'`, `'opus'`).\n */\n format: string\n\n /**\n * The bitrate of the compressed audio in bits per second.\n */\n bitrate: number\n\n /**\n * The size of the compressed audio file in bytes.\n */\n size: number\n }\n\n /**\n * Information about the processing time.\n */\n processingInfo?: {\n /**\n * The time it took to process the audio in milliseconds.\n */\n durationMs: number\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"ExpoAudioStream.types.js","sourceRoot":"","sources":["../../src/ExpoAudioStream.types.ts"],"names":[],"mappings":";;;AAiRA,4EAA4E;AAC/D,QAAA,2BAA2B,GAAG;IACvC,8CAA8C;IAC9C,KAAK,EAAE,OAAO;IACd,sDAAsD;IACtD,QAAQ,EAAE,UAAU;CACd,CAAA","sourcesContent":["// packages/expo-audio-stream/src/ExpoAudioStream.types.ts\nimport {\n AudioAnalysis,\n AudioFeaturesOptions,\n DecodingConfig,\n} from './AudioAnalysis/AudioAnalysis.types'\nimport { AudioAnalysisEvent } from './events'\n\nexport interface CompressionInfo {\n /** Size of the compressed audio data in bytes */\n size: number\n /** MIME type of the compressed audio (e.g., 'audio/aac', 'audio/opus') */\n mimeType: string\n /** Bitrate of the compressed audio in bits per second */\n bitrate: number\n /** Format of the compression (e.g., 'aac', 'opus') */\n format: string\n /** URI to the compressed audio file if available */\n compressedFileUri?: string\n}\n\nexport interface AudioStreamStatus {\n /** Indicates whether audio recording is currently active */\n isRecording: boolean\n /** Indicates whether recording is in a paused state */\n isPaused: boolean\n /** Duration of the current recording in milliseconds */\n durationMs: number\n /** Size of the recorded audio data in bytes */\n size: number\n /** Interval in milliseconds at which recording data is emitted */\n interval: number\n /** Interval in milliseconds at which analysis data is emitted */\n intervalAnalysis: number\n /** MIME type of the recorded audio (e.g., 'audio/wav') */\n mimeType: string\n /** Information about audio compression if enabled */\n compression?: CompressionInfo\n}\n\nexport interface AudioDataEvent {\n /** Audio data as base64 string (native) or Float32Array (web) */\n data: string | Float32Array\n /** Current position in the audio stream in bytes */\n position: number\n /** URI to the file being recorded */\n fileUri: string\n /** Size of the current data chunk in bytes */\n eventDataSize: number\n /** Total size of the recording so far in bytes */\n totalSize: number\n /** Information about compression if enabled, including the compressed data chunk */\n compression?: CompressionInfo & {\n /** Base64 (native) or Blob (web) encoded compressed data chunk */\n data?: string | Blob\n }\n}\n\nexport type EncodingType = 'pcm_32bit' | 'pcm_16bit' | 'pcm_8bit'\nexport type SampleRate = 16000 | 44100 | 48000\nexport type BitDepth = 8 | 16 | 32\nexport type PCMFormat = `pcm_${BitDepth}bit`\n\nexport type ConsoleLike = {\n /** Logs a message with optional arguments */\n log: (message: string, ...args: unknown[]) => void\n /** Logs a debug message with optional arguments */\n debug: (message: string, ...args: unknown[]) => void\n /** Logs an info message with optional arguments */\n info: (message: string, ...args: unknown[]) => void\n /** Logs a warning message with optional arguments */\n warn: (message: string, ...args: unknown[]) => void\n /** Logs an error message with optional arguments */\n error: (message: string, ...args: unknown[]) => void\n}\n\nexport interface Chunk {\n /** Transcribed text content */\n text: string\n /** Start and end timestamp in seconds [start, end] where end can be null if ongoing */\n timestamp: [number, number | null]\n}\n\nexport interface TranscriberData {\n /** Unique identifier for the transcription */\n id: string\n /** Indicates if the transcriber is currently processing */\n isBusy: boolean\n /** Complete transcribed text */\n text: string\n /** Start time of the transcription in milliseconds */\n startTime: number\n /** End time of the transcription in milliseconds */\n endTime: number\n /** Array of transcribed text chunks with timestamps */\n chunks: Chunk[]\n}\n\nexport interface AudioRecording {\n /** URI to the recorded audio file */\n fileUri: string\n /** Filename of the recorded audio */\n filename: string\n /** Duration of the recording in milliseconds */\n durationMs: number\n /** Size of the recording in bytes */\n size: number\n /** MIME type of the recorded audio */\n mimeType: string\n /** Number of audio channels (1 for mono, 2 for stereo) */\n channels: number\n /** Bit depth of the audio (8, 16, or 32 bits) */\n bitDepth: BitDepth\n /** Sample rate of the audio in Hz */\n sampleRate: SampleRate\n /** Timestamp when the recording was created */\n createdAt?: number\n /** Array of transcription data if available */\n transcripts?: TranscriberData[]\n /** Analysis data for the recording if processing was enabled */\n analysisData?: AudioAnalysis\n /** Information about compression if enabled, including the URI to the compressed file */\n compression?: CompressionInfo & {\n /** URI to the compressed audio file */\n compressedFileUri: string\n }\n}\n\nexport interface StartRecordingResult {\n /** URI to the file being recorded */\n fileUri: string\n /** MIME type of the recording */\n mimeType: string\n /** Number of audio channels (1 for mono, 2 for stereo) */\n channels?: number\n /** Bit depth of the audio (8, 16, or 32 bits) */\n bitDepth?: BitDepth\n /** Sample rate of the audio in Hz */\n sampleRate?: SampleRate\n /** Information about compression if enabled, including the URI to the compressed file */\n compression?: CompressionInfo & {\n /** URI to the compressed audio file */\n compressedFileUri: string\n }\n}\n\nexport interface AudioSessionConfig {\n /**\n * Audio session category that defines the audio behavior\n * - 'Ambient': Audio continues with silent switch, mixes with other audio\n * - 'SoloAmbient': Audio continues with silent switch, interrupts other audio\n * - 'Playback': Audio continues in background, interrupts other audio\n * - 'Record': Optimized for recording, interrupts other audio\n * - 'PlayAndRecord': Allows simultaneous playback and recording\n * - 'MultiRoute': Routes audio to multiple outputs simultaneously\n */\n category?:\n | 'Ambient'\n | 'SoloAmbient'\n | 'Playback'\n | 'Record'\n | 'PlayAndRecord'\n | 'MultiRoute'\n /**\n * Audio session mode that defines the behavior for specific use cases\n * - 'Default': Standard audio behavior\n * - 'VoiceChat': Optimized for voice chat applications\n * - 'VideoChat': Optimized for video chat applications\n * - 'GameChat': Optimized for in-game chat\n * - 'VideoRecording': Optimized for video recording\n * - 'Measurement': Optimized for audio measurement\n * - 'MoviePlayback': Optimized for movie playback\n * - 'SpokenAudio': Optimized for spoken audio content\n */\n mode?:\n | 'Default'\n | 'VoiceChat'\n | 'VideoChat'\n | 'GameChat'\n | 'VideoRecording'\n | 'Measurement'\n | 'MoviePlayback'\n | 'SpokenAudio'\n /**\n * Options that modify the behavior of the audio session category\n * - 'MixWithOthers': Allows mixing with other active audio sessions\n * - 'DuckOthers': Reduces the volume of other audio sessions\n * - 'InterruptSpokenAudioAndMixWithOthers': Interrupts spoken audio and mixes with others\n * - 'AllowBluetooth': Allows audio routing to Bluetooth devices\n * - 'AllowBluetoothA2DP': Allows audio routing to Bluetooth A2DP devices\n * - 'AllowAirPlay': Allows audio routing to AirPlay devices\n * - 'DefaultToSpeaker': Routes audio to the speaker by default\n */\n categoryOptions?: (\n | 'MixWithOthers'\n | 'DuckOthers'\n | 'InterruptSpokenAudioAndMixWithOthers'\n | 'AllowBluetooth'\n | 'AllowBluetoothA2DP'\n | 'AllowAirPlay'\n | 'DefaultToSpeaker'\n )[]\n}\n\nexport interface IOSConfig {\n /** Configuration for the iOS audio session */\n audioSession?: AudioSessionConfig\n}\n\n/** Web platform specific configuration options */\nexport interface WebConfig {\n // Reserved for future web-specific options\n}\n\n// Add new type for interruption reasons\nexport type RecordingInterruptionReason =\n /** Audio focus was lost to another app */\n | 'audioFocusLoss'\n /** Audio focus was regained */\n | 'audioFocusGain'\n /** Recording was interrupted by a phone call */\n | 'phoneCall'\n /** Phone call that interrupted recording has ended */\n | 'phoneCallEnded'\n /** Recording was stopped by the system or another app */\n | 'recordingStopped'\n /** Recording device was disconnected */\n | 'deviceDisconnected'\n /** Recording switched to default device after disconnection */\n | 'deviceFallback'\n /** A new audio device was connected */\n | 'deviceConnected'\n /** Device switching failed */\n | 'deviceSwitchFailed'\n\n// Add new interface for interruption events\nexport interface RecordingInterruptionEvent {\n /** The reason for the recording interruption */\n reason: RecordingInterruptionReason\n /** Indicates whether the recording is paused due to the interruption */\n isPaused: boolean\n}\n\nexport interface AudioDeviceCapabilities {\n /** Supported sample rates for the device */\n sampleRates: number[]\n /** Supported channel counts for the device */\n channelCounts: number[]\n /** Supported bit depths for the device */\n bitDepths: number[]\n /** Whether the device supports echo cancellation */\n hasEchoCancellation?: boolean\n /** Whether the device supports noise suppression */\n hasNoiseSuppression?: boolean\n /** Whether the device supports automatic gain control */\n hasAutomaticGainControl?: boolean\n}\n\nexport interface AudioDevice {\n /** Unique identifier for the device */\n id: string\n /** Human-readable name of the device */\n name: string\n /** Device type (builtin_mic, bluetooth, etc.) */\n type: string\n /** Whether this is the system default device */\n isDefault: boolean\n /** Audio capabilities for the device */\n capabilities: AudioDeviceCapabilities\n /** Whether the device is currently available */\n isAvailable: boolean\n}\n\n/** Defines how recording should behave when a device becomes unavailable */\nexport const DeviceDisconnectionBehavior = {\n /** Pause recording when device disconnects */\n PAUSE: 'pause',\n /** Switch to default device and continue recording */\n FALLBACK: 'fallback',\n} as const\n\n/** Type for DeviceDisconnectionBehavior values */\nexport type DeviceDisconnectionBehaviorType =\n (typeof DeviceDisconnectionBehavior)[keyof typeof DeviceDisconnectionBehavior]\n\n/**\n * Configuration for audio output files during recording\n */\nexport interface OutputConfig {\n /**\n * Configuration for the primary (uncompressed) output file\n */\n primary?: {\n /** Whether to create the primary output file (default: true) */\n enabled?: boolean\n /** Format for the primary output (currently only 'wav' is supported) */\n format?: 'wav'\n }\n\n /**\n * Configuration for the compressed output file\n */\n compressed?: {\n /** Whether to create a compressed output file (default: false) */\n enabled?: boolean\n /**\n * Format for compression\n * - 'aac': Advanced Audio Coding - supported on all platforms\n * - 'opus': Opus encoding - supported on Android and Web; on iOS will automatically fall back to AAC\n */\n format?: 'aac' | 'opus'\n /** Bitrate for compression in bits per second (default: 128000) */\n bitrate?: number\n }\n\n // Future enhancement: Post-processing pipeline\n // postProcessing?: {\n // normalize?: boolean\n // trimSilence?: boolean\n // noiseReduction?: boolean\n // customProcessors?: AudioProcessor[]\n // }\n}\n\nexport interface RecordingConfig {\n /** Sample rate for recording in Hz (16000, 44100, or 48000) */\n sampleRate?: SampleRate\n\n /** Number of audio channels (1 for mono, 2 for stereo) */\n channels?: 1 | 2\n\n /** Encoding type for the recording (pcm_32bit, pcm_16bit, pcm_8bit) */\n encoding?: EncodingType\n\n /** Interval in milliseconds at which to emit recording data */\n interval?: number\n\n /** Interval in milliseconds at which to emit analysis data */\n intervalAnalysis?: number\n\n /** Keep the device awake while recording (default is false) */\n keepAwake?: boolean\n\n /** Show a notification during recording (default is false) */\n showNotification?: boolean\n\n /** Show waveform in the notification (Android only, when showNotification is true) */\n showWaveformInNotification?: boolean\n\n /** Configuration for the notification */\n notification?: NotificationConfig\n\n /** Enable audio processing (default is false) */\n enableProcessing?: boolean\n\n /** iOS-specific configuration */\n ios?: IOSConfig\n\n /** Web-specific configuration options */\n web?: WebConfig\n\n /** Duration of each segment in milliseconds for analysis (default: 100) */\n segmentDurationMs?: number\n\n /** Feature options to extract during audio processing */\n features?: AudioFeaturesOptions\n\n /** Callback function to handle audio stream data */\n onAudioStream?: (_: AudioDataEvent) => Promise<void>\n\n /** Callback function to handle audio features extraction results */\n onAudioAnalysis?: (_: AudioAnalysisEvent) => Promise<void>\n\n /**\n * Configuration for audio output files\n *\n * Examples:\n * - Primary only (default): `{ primary: { enabled: true } }`\n * - Compressed only: `{ primary: { enabled: false }, compressed: { enabled: true, format: 'aac' } }`\n * - Both outputs: `{ compressed: { enabled: true } }`\n * - Streaming only: `{ primary: { enabled: false } }`\n */\n output?: OutputConfig\n\n /** Whether to automatically resume recording after an interruption (default is false) */\n autoResumeAfterInterruption?: boolean\n\n /** Optional callback to handle recording interruptions */\n onRecordingInterrupted?: (_: RecordingInterruptionEvent) => void\n\n /** Optional directory path where output files will be saved */\n outputDirectory?: string // If not provided, uses default app directory\n /** Optional filename for the recording (uses UUID if not provided) */\n filename?: string // If not provided, uses UUID\n\n /** ID of the device to use for recording (if not specified, uses default) */\n deviceId?: string\n\n /** How to handle device disconnection during recording */\n deviceDisconnectionBehavior?: DeviceDisconnectionBehaviorType\n\n /**\n * Buffer duration in seconds. Controls the size of audio buffers\n * used during recording. Smaller values reduce latency but increase\n * CPU usage. Larger values improve efficiency but increase latency.\n *\n * Platform Notes:\n * - iOS/macOS: Minimum effective 0.1s, uses accumulation below\n * - Android: Respects all sizes within hardware limits\n * - Web: Fully configurable\n *\n * Default: undefined (uses platform default ~23ms at 44.1kHz)\n * Recommended: 0.01 - 0.5 seconds\n * Optimal iOS: >= 0.1 seconds\n */\n bufferDurationSeconds?: number\n}\n\nexport interface NotificationConfig {\n /** Title of the notification */\n title?: string\n\n /** Main text content of the notification */\n text?: string\n\n /** Icon to be displayed in the notification (resource name or URI) */\n icon?: string\n\n /** Android-specific notification configuration */\n android?: {\n /** Unique identifier for the notification channel */\n channelId?: string\n\n /** User-visible name of the notification channel */\n channelName?: string\n\n /** User-visible description of the notification channel */\n channelDescription?: string\n\n /** Unique identifier for this notification */\n notificationId?: number\n\n /** List of actions that can be performed from the notification */\n actions?: NotificationAction[]\n\n /** Configuration for the waveform visualization in the notification */\n waveform?: WaveformConfig\n\n /** Color of the notification LED (if device supports it) */\n lightColor?: string\n\n /** Priority of the notification (affects how it's displayed) */\n priority?: 'min' | 'low' | 'default' | 'high' | 'max'\n\n /** Accent color for the notification (used for the app icon and buttons) */\n accentColor?: string\n }\n\n /** iOS-specific notification configuration */\n ios?: {\n /** Identifier for the notification category (used for grouping similar notifications) */\n categoryIdentifier?: string\n }\n}\n\nexport interface NotificationAction {\n /** Display title for the action */\n title: string\n\n /** Unique identifier for the action */\n identifier: string\n\n /** Icon to be displayed for the action (Android only) */\n icon?: string\n}\n\nexport interface WaveformConfig {\n /** The color of the waveform (e.g., \"#FFFFFF\" for white) */\n color?: string // The color of the waveform (e.g., \"#FFFFFF\" for white)\n /** Opacity of the waveform (0.0 - 1.0) */\n opacity?: number // Opacity of the waveform (0.0 - 1.0)\n /** Width of the waveform line (default: 1.5) */\n strokeWidth?: number // Width of the waveform line (default: 1.5)\n /** Drawing style: \"stroke\" for outline, \"fill\" for solid */\n style?: 'stroke' | 'fill' // Drawing style: \"stroke\" for outline, \"fill\" for solid\n /** Whether to mirror the waveform (symmetrical display) */\n mirror?: boolean // Whether to mirror the waveform (symmetrical display)\n /** Height of the waveform view in dp (default: 64) */\n height?: number // Height of the waveform view in dp (default: 64)\n}\n\nexport interface ExtractAudioDataOptions {\n /** URI of the audio file to extract data from */\n fileUri: string\n /** Start time in milliseconds (for time-based range) */\n startTimeMs?: number\n /** End time in milliseconds (for time-based range) */\n endTimeMs?: number\n /** Start position in bytes (for byte-based range) */\n position?: number\n /** Length in bytes to extract (for byte-based range) */\n length?: number\n /** Include normalized audio data in [-1, 1] range */\n includeNormalizedData?: boolean\n /** Include base64 encoded string representation of the audio data */\n includeBase64Data?: boolean\n /** Include WAV header in the PCM data (makes it a valid WAV file) */\n includeWavHeader?: boolean\n /** Logger for debugging - can pass console directly. */\n logger?: ConsoleLike\n /** Compute the checksum of the PCM data */\n computeChecksum?: boolean\n /** Target config for the normalized audio (Android and Web) */\n decodingOptions?: DecodingConfig\n}\n\nexport interface ExtractedAudioData {\n /** Raw PCM audio data */\n pcmData: Uint8Array\n /** Normalized audio data in [-1, 1] range (when includeNormalizedData is true) */\n normalizedData?: Float32Array\n /** Base64 encoded string representation of the audio data (when includeBase64Data is true) */\n base64Data?: string\n /** Sample rate in Hz (e.g., 44100, 48000) */\n sampleRate: number\n /** Number of audio channels (1 for mono, 2 for stereo) */\n channels: number\n /** Bits per sample (8, 16, or 32) */\n bitDepth: BitDepth\n /** Duration of the audio in milliseconds */\n durationMs: number\n /** PCM format identifier (e.g., \"pcm_16bit\") */\n format: PCMFormat\n /** Total number of audio samples per channel */\n samples: number\n /** Whether the pcmData includes a WAV header */\n hasWavHeader?: boolean\n /** CRC32 Checksum of PCM data */\n checksum?: number\n}\n\nexport interface UseAudioRecorderState {\n /**\n * Prepares recording with the specified configuration without starting it.\n *\n * This method eliminates the latency between calling startRecording and the actual recording beginning.\n * It pre-initializes all audio resources, requests permissions, and sets up audio sessions in advance,\n * allowing for true zero-latency recording start when startRecording is called later.\n *\n * Technical benefits:\n * - Eliminates audio pipeline initialization delay (50-300ms depending on platform)\n * - Pre-allocates audio buffers to avoid memory allocation during recording start\n * - Initializes audio hardware in advance (particularly important on iOS)\n * - Requests and verifies permissions before the critical recording moment\n *\n * Use this method when:\n * - You need zero-latency recording start (e.g., voice commands, musical applications)\n * - You're building time-sensitive applications where missing initial audio would be problematic\n * - You want to prepare resources during app initialization, screen loading, or preceding user interaction\n * - You need to ensure recording starts reliably and instantly on all platforms\n *\n * @param config - The recording configuration, identical to what you would pass to startRecording\n * @returns A promise that resolves when preparation is complete\n *\n * @example\n * // Prepare during component mounting\n * useEffect(() => {\n * prepareRecording({\n * sampleRate: 44100,\n * channels: 1,\n * encoding: 'pcm_16bit',\n * });\n * }, []);\n *\n * // Later when user taps record button, it starts with zero latency\n * const handleRecordPress = () => startRecording({\n * sampleRate: 44100,\n * channels: 1,\n * encoding: 'pcm_16bit',\n * });\n */\n prepareRecording: (_: RecordingConfig) => Promise<void>\n /** Starts recording with the specified configuration */\n startRecording: (_: RecordingConfig) => Promise<StartRecordingResult>\n /** Stops the current recording and returns the recording data */\n stopRecording: () => Promise<AudioRecording | null>\n /** Pauses the current recording */\n pauseRecording: () => Promise<void>\n /** Resumes a paused recording */\n resumeRecording: () => Promise<void>\n /** Indicates whether recording is currently active */\n isRecording: boolean\n /** Indicates whether recording is in a paused state */\n isPaused: boolean\n /** Duration of the current recording in milliseconds */\n durationMs: number // Duration of the recording\n /** Size of the recorded audio in bytes */\n size: number // Size in bytes of the recorded audio\n /** Information about compression if enabled */\n compression?: CompressionInfo\n /** Analysis data for the recording if processing was enabled */\n analysisData?: AudioAnalysis // Analysis data for the recording depending on enableProcessing flag\n /** Optional callback to handle recording interruptions */\n onRecordingInterrupted?: (_: RecordingInterruptionEvent) => void\n}\n\n/**\n * Represents an event emitted during the trimming process to report progress.\n */\nexport interface TrimProgressEvent {\n /**\n * The percentage of the trimming process that has been completed, ranging from 0 to 100.\n */\n progress: number\n\n /**\n * The number of bytes that have been processed so far. This is optional and may not be provided in all implementations.\n */\n bytesProcessed?: number\n\n /**\n * The total number of bytes to process. This is optional and may not be provided in all implementations.\n */\n totalBytes?: number\n}\n\n/**\n * Defines a time range in milliseconds for trimming operations.\n */\nexport interface TimeRange {\n /**\n * The start time of the range in milliseconds.\n */\n startTimeMs: number\n\n /**\n * The end time of the range in milliseconds.\n */\n endTimeMs: number\n}\n\n/**\n * Options for configuring the audio trimming operation.\n */\nexport interface TrimAudioOptions {\n /**\n * The URI of the audio file to trim.\n */\n fileUri: string\n\n /**\n * The mode of trimming to apply.\n * - `'single'`: Trims the audio to a single range defined by `startTimeMs` and `endTimeMs`.\n * - `'keep'`: Keeps the specified `ranges` and removes all other portions of the audio.\n * - `'remove'`: Removes the specified `ranges` and keeps the remaining portions of the audio.\n * @default 'single'\n */\n mode?: 'single' | 'keep' | 'remove'\n\n /**\n * An array of time ranges to keep or remove, depending on the `mode`.\n * - Required for `'keep'` and `'remove'` modes.\n * - Ignored when `mode` is `'single'`.\n */\n ranges?: TimeRange[]\n\n /**\n * The start time in milliseconds for the `'single'` mode.\n * - If not provided, trimming starts from the beginning of the audio (0 ms).\n */\n startTimeMs?: number\n\n /**\n * The end time in milliseconds for the `'single'` mode.\n * - If not provided, trimming extends to the end of the audio.\n */\n endTimeMs?: number\n\n /**\n * The name of the output file. If not provided, a default name will be generated.\n */\n outputFileName?: string\n\n /**\n * Configuration for the output audio format.\n */\n outputFormat?: {\n /**\n * The format of the output audio file.\n * - `'wav'`: Waveform Audio File Format (uncompressed).\n * - `'aac'`: Advanced Audio Coding (compressed). Not supported on web platforms.\n * - `'opus'`: Opus Interactive Audio Codec (compressed).\n */\n format: 'wav' | 'aac' | 'opus'\n\n /**\n * The sample rate of the output audio in Hertz (Hz).\n * - If not provided, the input audio's sample rate is used.\n */\n sampleRate?: number\n\n /**\n * The number of channels in the output audio (e.g., 1 for mono, 2 for stereo).\n * - If not provided, the input audio's channel count is used.\n */\n channels?: number\n\n /**\n * The bit depth of the output audio, applicable to PCM formats like `'wav'`.\n * - If not provided, the input audio's bit depth is used.\n */\n bitDepth?: number\n\n /**\n * The bitrate of the output audio in bits per second, applicable to compressed formats like `'aac'`.\n * - If not provided, a default bitrate is used based on the format.\n */\n bitrate?: number\n }\n\n /**\n * Options for decoding the input audio file.\n * - See `DecodingConfig` for details.\n */\n decodingOptions?: DecodingConfig\n}\n\n/**\n * Result of the audio trimming operation.\n */\nexport interface TrimAudioResult {\n /**\n * The URI of the trimmed audio file.\n */\n uri: string\n\n /**\n * The filename of the trimmed audio file.\n */\n filename: string\n\n /**\n * The duration of the trimmed audio in milliseconds.\n */\n durationMs: number\n\n /**\n * The size of the trimmed audio file in bytes.\n */\n size: number\n\n /**\n * The sample rate of the trimmed audio in Hertz (Hz).\n */\n sampleRate: number\n\n /**\n * The number of channels in the trimmed audio (e.g., 1 for mono, 2 for stereo).\n */\n channels: number\n\n /**\n * The bit depth of the trimmed audio, applicable to PCM formats like `'wav'`.\n */\n bitDepth: number\n\n /**\n * The MIME type of the trimmed audio file (e.g., `'audio/wav'`, `'audio/mpeg'`).\n */\n mimeType: string\n\n /**\n * Information about compression if the output format is compressed.\n */\n compression?: {\n /**\n * The format of the compression (e.g., `'aac'`, `'mp3'`, `'opus'`).\n */\n format: string\n\n /**\n * The bitrate of the compressed audio in bits per second.\n */\n bitrate: number\n\n /**\n * The size of the compressed audio file in bytes.\n */\n size: number\n }\n\n /**\n * Information about the processing time.\n */\n processingInfo?: {\n /**\n * The time it took to process the audio in milliseconds.\n */\n durationMs: number\n }\n}\n"]}
|
|
@@ -203,13 +203,13 @@ class ExpoAudioStreamWeb extends expo_modules_core_1.LegacyEventEmitter {
|
|
|
203
203
|
bitDepth: this.bitDepth,
|
|
204
204
|
channels: recordingConfig.channels ?? 1,
|
|
205
205
|
sampleRate: recordingConfig.sampleRate ?? 44100,
|
|
206
|
-
compression: recordingConfig.
|
|
206
|
+
compression: recordingConfig.output?.compressed?.enabled
|
|
207
207
|
? {
|
|
208
|
-
...recordingConfig.
|
|
209
|
-
bitrate: recordingConfig.
|
|
208
|
+
...recordingConfig.output.compressed,
|
|
209
|
+
bitrate: recordingConfig.output.compressed.bitrate ?? 128000,
|
|
210
210
|
size: 0,
|
|
211
211
|
mimeType: 'audio/webm',
|
|
212
|
-
format: recordingConfig.
|
|
212
|
+
format: recordingConfig.output.compressed.format ?? 'opus',
|
|
213
213
|
compressedFileUri: '',
|
|
214
214
|
}
|
|
215
215
|
: undefined,
|
|
@@ -339,45 +339,46 @@ class ExpoAudioStreamWeb extends expo_modules_core_1.LegacyEventEmitter {
|
|
|
339
339
|
let compression;
|
|
340
340
|
let fileUri = `${this.streamUuid}.${this.extension}`;
|
|
341
341
|
let mimeType = `audio/${this.extension}`;
|
|
342
|
-
// Handle both compressed and uncompressed blobs according to configuration
|
|
343
|
-
const
|
|
344
|
-
|
|
345
|
-
if
|
|
342
|
+
// Handle both compressed and uncompressed blobs according to new output configuration
|
|
343
|
+
const primaryEnabled = this.recordingConfig?.output?.primary?.enabled ?? true;
|
|
344
|
+
const compressedEnabled = this.recordingConfig?.output?.compressed?.enabled ?? false;
|
|
345
|
+
// Process compressed blob if available and enabled
|
|
346
|
+
if (compressedBlob && compressedEnabled) {
|
|
346
347
|
const compressedUri = URL.createObjectURL(compressedBlob);
|
|
347
348
|
const compressedInfo = {
|
|
348
349
|
compressedFileUri: compressedUri,
|
|
349
350
|
size: compressedBlob.size,
|
|
350
351
|
mimeType: 'audio/webm',
|
|
351
|
-
format:
|
|
352
|
-
|
|
352
|
+
format: this.recordingConfig?.output?.compressed?.format ??
|
|
353
|
+
'opus',
|
|
354
|
+
bitrate: this.recordingConfig?.output?.compressed?.bitrate ??
|
|
355
|
+
128000,
|
|
353
356
|
};
|
|
354
|
-
//
|
|
355
|
-
|
|
356
|
-
|
|
357
|
+
// Store compression info
|
|
358
|
+
compression = compressedInfo;
|
|
359
|
+
// If primary is disabled, use compressed as main file
|
|
360
|
+
if (!primaryEnabled) {
|
|
361
|
+
this.logger?.debug('Using compressed audio as primary output (primary disabled)');
|
|
357
362
|
fileUri = compressedUri;
|
|
358
363
|
mimeType = 'audio/webm';
|
|
359
|
-
// Store compression info
|
|
360
|
-
compression = compressedInfo;
|
|
361
|
-
}
|
|
362
|
-
else {
|
|
363
|
-
// Compression was enabled during recording but not set as primary
|
|
364
|
-
// Store as alternate format
|
|
365
|
-
compression = compressedInfo;
|
|
366
364
|
}
|
|
367
365
|
}
|
|
368
|
-
// Process uncompressed WAV if available
|
|
369
|
-
if (uncompressedBlob) {
|
|
366
|
+
// Process uncompressed WAV if available and primary is enabled
|
|
367
|
+
if (uncompressedBlob && primaryEnabled) {
|
|
370
368
|
const wavUri = URL.createObjectURL(uncompressedBlob);
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
369
|
+
fileUri = wavUri;
|
|
370
|
+
mimeType = 'audio/wav';
|
|
371
|
+
}
|
|
372
|
+
else if (!primaryEnabled && !compressedEnabled) {
|
|
373
|
+
// No outputs enabled - streaming only mode
|
|
374
|
+
this.logger?.debug('No outputs enabled - streaming only mode');
|
|
375
|
+
fileUri = '';
|
|
376
|
+
mimeType = 'audio/wav';
|
|
378
377
|
}
|
|
379
378
|
// Use the stored streamUuid for the final filename
|
|
380
|
-
const filename =
|
|
379
|
+
const filename = fileUri
|
|
380
|
+
? `${this.streamUuid}.${this.extension}`
|
|
381
|
+
: 'stream-only';
|
|
381
382
|
const result = {
|
|
382
383
|
fileUri,
|
|
383
384
|
filename,
|
|
@@ -386,7 +387,7 @@ class ExpoAudioStreamWeb extends expo_modules_core_1.LegacyEventEmitter {
|
|
|
386
387
|
channels: this.recordingConfig?.channels ?? 1,
|
|
387
388
|
sampleRate: this.recordingConfig?.sampleRate ?? 44100,
|
|
388
389
|
durationMs: this.currentDurationMs,
|
|
389
|
-
size: this.currentSize,
|
|
390
|
+
size: primaryEnabled ? this.currentSize : 0,
|
|
390
391
|
mimeType,
|
|
391
392
|
compression,
|
|
392
393
|
};
|
|
@@ -482,12 +483,14 @@ class ExpoAudioStreamWeb extends expo_modules_core_1.LegacyEventEmitter {
|
|
|
482
483
|
interval: this.currentInterval,
|
|
483
484
|
intervalAnalysis: this.currentIntervalAnalysis,
|
|
484
485
|
mimeType: `audio/${this.extension}`,
|
|
485
|
-
compression: this.recordingConfig?.
|
|
486
|
+
compression: this.recordingConfig?.output?.compressed?.enabled
|
|
486
487
|
? {
|
|
487
488
|
size: this.totalCompressedSize,
|
|
488
489
|
mimeType: 'audio/webm',
|
|
489
|
-
format: this.recordingConfig.
|
|
490
|
-
|
|
490
|
+
format: this.recordingConfig.output.compressed.format ??
|
|
491
|
+
'opus',
|
|
492
|
+
bitrate: this.recordingConfig.output.compressed.bitrate ??
|
|
493
|
+
128000,
|
|
491
494
|
compressedFileUri: `${this.streamUuid}.webm`,
|
|
492
495
|
}
|
|
493
496
|
: undefined,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ExpoAudioStream.web.js","sourceRoot":"","sources":["../../src/ExpoAudioStream.web.ts"],"names":[],"mappings":";;;AAAA,mCAAmC;AACnC,yDAAsD;AAYtD,uDAA+C;AAE/C,mEAA+D;AAmC/D,MAAa,kBAAmB,SAAQ,sCAAkB;IACtD,cAAc,CAAoB;IAClC,WAAW,CAAgB;IAC3B,WAAW,CAAS;IACpB,QAAQ,CAAS;IACjB,kBAAkB,CAAQ;IAC1B,UAAU,CAAQ;IAClB,iBAAiB,CAAQ;IACzB,WAAW,CAAQ;IACnB,eAAe,CAAQ;IACvB,uBAAuB,CAAQ;IAC/B,eAAe,CAAQ;IACvB,eAAe,CAAQ;IACvB,0BAA0B,CAAQ;IAClC,uBAAuB,CAAQ;IAC/B,UAAU,CAAe;IACzB,SAAS,GAAmB,KAAK,CAAA,CAAC,6BAA6B;IAC/D,eAAe,CAAkB;IACjC,QAAQ,CAAU,CAAC,yBAAyB;IAC5C,eAAe,CAAQ;IACvB,mBAAmB,CAAQ;IAC3B,MAAM,CAAc;IACpB,cAAc,GAAW,CAAC,CAAA;IAC1B,mBAAmB,GAAW,CAAC,CAAA;IACd,aAAa,CAAQ;IAC9B,aAAa,CAAoC;IAEzD,YAAY,EACR,eAAe,EACf,mBAAmB,EACnB,MAAM,EACN,aAAa,GAAG,GAAG,EAAE,6DAA6D;MAC5D;QACtB,MAAM,gBAAgB,GAAG;YACrB,WAAW,EAAE,GAAG,EAAE,GAAE,CAAC;YACrB,eAAe,EAAE,GAAG,EAAE,GAAE,CAAC;SA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AAE;oBACH,QAAQ,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE;iBAChC;aACJ,CAAC,CAAA;QACN,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,EAAE,KAAK,CACd,kCAAkC,QAAQ,EAAE,EAC5C,KAAK,CACR,CAAA;YACD,2CAA2C;YAC3C,OAAO,MAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;QACrE,CAAC;IACL,CAAC;IAED,IAAI,CAAC,OAAgC;QACjC,IAAI,CAAC;YACD,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,CAAA;YAC7B,IAAI,CAAC,aAAa,GAAG,OAAO,EAAE,aAAa,CAAA;YAC3C,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;QAC5B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAA;YAC/D,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAChC,CAAC;IACL,CAAC;CACJ;AAj1BD,gDAi1BC","sourcesContent":["// src/ExpoAudioStreamModule.web.ts\nimport { LegacyEventEmitter } from 'expo-modules-core'\n\nimport { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types'\nimport {\n AudioRecording,\n AudioStreamStatus,\n BitDepth,\n ConsoleLike,\n RecordingConfig,\n RecordingInterruptionReason,\n StartRecordingResult,\n} from './ExpoAudioStream.types'\nimport { WebRecorder } from './WebRecorder.web'\nimport { AudioEventPayload } from './events'\nimport { encodingToBitDepth } from './utils/encodingToBitDepth'\n\nexport interface AudioStreamEvent {\n type: string\n device?: string\n timestamp: Date\n}\n\nexport interface ExpoAudioStreamOptions {\n logger?: ConsoleLike\n eventCallback?: (event: AudioStreamEvent) => void\n}\n\nexport interface EmitAudioEventProps {\n data: Float32Array\n position: number\n compression?: {\n data: Blob\n size: number\n totalSize: number\n mimeType: string\n format: string\n bitrate: number\n }\n}\nexport type EmitAudioEventFunction = (_: EmitAudioEventProps) => void\nexport type EmitAudioAnalysisFunction = (_: AudioAnalysis) => void\n\nexport interface ExpoAudioStreamWebProps {\n logger?: ConsoleLike\n audioWorkletUrl: string\n featuresExtratorUrl: string\n maxBufferSize?: number // Maximum number of chunks to keep in memory\n}\n\nexport class ExpoAudioStreamWeb extends LegacyEventEmitter {\n customRecorder: WebRecorder | null\n audioChunks: Float32Array[]\n isRecording: boolean\n isPaused: boolean\n recordingStartTime: number\n pausedTime: number\n currentDurationMs: number\n currentSize: number\n currentInterval: number\n currentIntervalAnalysis: number\n lastEmittedSize: number\n lastEmittedTime: number\n lastEmittedCompressionSize: number\n lastEmittedAnalysisTime: number\n streamUuid: string | null\n extension: 'webm' | 'wav' = 'wav' // Default extension is 'wav'\n recordingConfig?: RecordingConfig\n bitDepth: BitDepth // Bit depth of the audio\n audioWorkletUrl: string\n featuresExtratorUrl: string\n logger?: ConsoleLike\n latestPosition: number = 0\n totalCompressedSize: number = 0\n private readonly maxBufferSize: number\n private eventCallback?: (event: AudioStreamEvent) => void\n\n constructor({\n audioWorkletUrl,\n featuresExtratorUrl,\n logger,\n maxBufferSize = 100, // Default to storing last 100 chunks (1 chunk = 0.5 seconds)\n }: ExpoAudioStreamWebProps) {\n const mockNativeModule = {\n addListener: () => {},\n removeListeners: () => {},\n }\n super(mockNativeModule) // Pass the mock native module to the parent class\n\n this.logger = logger\n this.customRecorder = null\n this.audioChunks = []\n this.isRecording = false\n this.isPaused = false\n this.recordingStartTime = 0\n this.pausedTime = 0\n this.currentDurationMs = 0\n this.currentSize = 0\n this.bitDepth = 32 // Default\n this.currentInterval = 1000 // Default interval in ms\n this.currentIntervalAnalysis = 500 // Default analysis interval in ms\n this.lastEmittedSize = 0\n this.lastEmittedTime = 0\n this.latestPosition = 0\n this.lastEmittedCompressionSize = 0\n this.lastEmittedAnalysisTime = 0\n this.streamUuid = null // Initialize UUID on first recording start\n this.audioWorkletUrl = audioWorkletUrl\n this.featuresExtratorUrl = featuresExtratorUrl\n this.maxBufferSize = maxBufferSize\n }\n\n // Utility to handle user media stream\n async getMediaStream() {\n try {\n this.logger?.debug('Requesting user media (microphone)...')\n\n // First check if the browser supports the necessary audio APIs\n if (!navigator?.mediaDevices?.getUserMedia) {\n this.logger?.error(\n 'Browser does not support mediaDevices.getUserMedia'\n )\n throw new Error('Browser does not support audio recording')\n }\n\n // Get media with detailed audio constraints for better diagnostics\n const constraints = {\n audio: {\n echoCancellation: true,\n noiseSuppression: true,\n autoGainControl: true,\n // Add deviceId constraint if specified\n ...(this.recordingConfig?.deviceId\n ? {\n deviceId: {\n exact: this.recordingConfig.deviceId,\n },\n }\n : {}),\n },\n }\n\n this.logger?.debug('Media constraints:', constraints)\n\n const stream =\n await navigator.mediaDevices.getUserMedia(constraints)\n\n // Get detailed info about the audio track for debugging\n const audioTracks = stream.getAudioTracks()\n if (audioTracks.length > 0) {\n const track = audioTracks[0]\n const settings = track.getSettings()\n this.logger?.debug('Audio track obtained:', {\n label: track.label,\n id: track.id,\n enabled: track.enabled,\n muted: track.muted,\n readyState: track.readyState,\n settings,\n })\n } else {\n this.logger?.warn('Stream has no audio tracks!')\n }\n\n return stream\n } catch (error) {\n this.logger?.error('Failed to get media stream:', error)\n throw error\n }\n }\n\n // Prepare recording with options\n async prepareRecording(\n recordingConfig: RecordingConfig = {}\n ): Promise<boolean> {\n if (this.isRecording) {\n this.logger?.warn(\n 'Cannot prepare: Recording is already in progress'\n )\n return false\n }\n\n try {\n // Check permissions and initialize basic settings\n await this.getMediaStream().then((stream) => {\n // Just verify we can access the microphone by getting a stream, then release it\n stream.getTracks().forEach((track) => track.stop())\n })\n\n this.bitDepth = encodingToBitDepth({\n encoding: recordingConfig.encoding ?? 'pcm_32bit',\n })\n\n // Store recording configuration for later use\n this.recordingConfig = recordingConfig\n\n // Use custom filename if provided, otherwise fallback to timestamp\n if (recordingConfig.filename) {\n // Remove any existing extension from the filename\n this.streamUuid = recordingConfig.filename.replace(\n /\\.[^/.]+$/,\n ''\n )\n } else {\n this.streamUuid = Date.now().toString()\n }\n\n this.logger?.debug('Recording preparation completed successfully')\n return true\n } catch (error) {\n this.logger?.error('Error preparing recording:', error)\n return false\n }\n }\n\n // Start recording with options\n async startRecording(\n recordingConfig: RecordingConfig = {}\n ): Promise<StartRecordingResult> {\n if (this.isRecording) {\n throw new Error('Recording is already in progress')\n }\n\n // If we haven't prepared or have different settings, prepare now\n if (\n !this.recordingConfig ||\n this.recordingConfig.sampleRate !== recordingConfig.sampleRate ||\n this.recordingConfig.channels !== recordingConfig.channels ||\n this.recordingConfig.encoding !== recordingConfig.encoding\n ) {\n await this.prepareRecording(recordingConfig)\n } else {\n this.logger?.debug(\n 'Using previously prepared recording configuration'\n )\n }\n\n // Save recording config for reference\n this.recordingConfig = recordingConfig\n\n const audioContext = new (window.AudioContext ||\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - Allow webkitAudioContext for Safari\n window.webkitAudioContext)()\n const stream = await this.getMediaStream()\n\n const source = audioContext.createMediaStreamSource(stream)\n\n this.customRecorder = new WebRecorder({\n logger: this.logger,\n audioContext,\n source,\n recordingConfig,\n emitAudioEventCallback: this.customRecorderEventCallback.bind(this),\n emitAudioAnalysisCallback:\n this.customRecorderAnalysisCallback.bind(this),\n onInterruption: this.handleRecordingInterruption.bind(this),\n })\n await this.customRecorder.init()\n this.customRecorder.start()\n\n this.isRecording = true\n this.recordingStartTime = Date.now()\n this.pausedTime = 0\n this.isPaused = false\n this.lastEmittedSize = 0\n this.lastEmittedTime = 0\n this.lastEmittedCompressionSize = 0\n this.currentInterval = recordingConfig.interval ?? 1000\n this.currentIntervalAnalysis = recordingConfig.intervalAnalysis ?? 500\n this.lastEmittedAnalysisTime = Date.now()\n\n // Use custom filename if provided, otherwise fallback to timestamp\n if (recordingConfig.filename) {\n // Remove any existing extension from the filename\n this.streamUuid = recordingConfig.filename.replace(/\\.[^/.]+$/, '')\n } else {\n this.streamUuid = Date.now().toString()\n }\n\n const fileUri = `${this.streamUuid}.${this.extension}`\n const streamConfig: StartRecordingResult = {\n fileUri,\n mimeType: `audio/${this.extension}`,\n bitDepth: this.bitDepth,\n channels: recordingConfig.channels ?? 1,\n sampleRate: recordingConfig.sampleRate ?? 44100,\n compression: recordingConfig.compression\n ? {\n ...recordingConfig.compression,\n bitrate: recordingConfig.compression?.bitrate ?? 128000,\n size: 0,\n mimeType: 'audio/webm',\n format: recordingConfig.compression?.format ?? 'opus',\n compressedFileUri: '',\n }\n : undefined,\n }\n return streamConfig\n }\n\n /**\n * Centralized handler for recording interruptions\n */\n private handleRecordingInterruption(event: {\n reason: RecordingInterruptionReason | string\n isPaused: boolean\n timestamp: number\n message?: string\n }): void {\n this.logger?.debug(`Received recording interruption: ${event.reason}`)\n\n // Update local state if the interruption should pause recording\n if (event.isPaused) {\n this.isPaused = true\n\n // If this is a device disconnection, handle according to behavior setting\n if (event.reason === 'deviceDisconnected') {\n this.pausedTime = Date.now()\n\n // Check if we should try fallback to another device\n if (\n this.recordingConfig?.deviceDisconnectionBehavior ===\n 'fallback'\n ) {\n this.logger?.debug(\n 'Device disconnected with fallback behavior - attempting to switch to default device'\n )\n\n // Try to restart with default device\n this.handleDeviceFallback().catch((error) => {\n // If fallback fails, emit warning\n this.logger?.error('Device fallback failed:', error)\n this.emit('onRecordingInterrupted', {\n reason: 'deviceSwitchFailed',\n isPaused: true,\n timestamp: Date.now(),\n message:\n 'Failed to switch to fallback device. Recording paused.',\n })\n })\n } else {\n // Just warn about disconnection if fallback not enabled\n this.logger?.warn(\n 'Device disconnected - recording paused automatically'\n )\n this.emit('onRecordingInterrupted', event)\n }\n } else {\n // For other interruption types, just emit the event\n this.emit('onRecordingInterrupted', event)\n }\n } else {\n // If not causing a pause, just forward the event\n this.emit('onRecordingInterrupted', event)\n }\n }\n\n /**\n * Handler for audio events from the WebRecorder\n */\n private customRecorderEventCallback({\n data,\n position,\n compression,\n }: EmitAudioEventProps): void {\n // Keep only the latest chunks based on maxBufferSize\n this.audioChunks.push(new Float32Array(data))\n if (this.audioChunks.length > this.maxBufferSize) {\n this.audioChunks.shift() // Remove oldest chunk\n }\n this.currentSize += data.byteLength\n this.emitAudioEvent({ data, position, compression })\n this.lastEmittedTime = Date.now()\n this.lastEmittedSize = this.currentSize\n this.lastEmittedCompressionSize = compression?.size ?? 0\n }\n\n /**\n * Handler for audio analysis events from the WebRecorder\n */\n private customRecorderAnalysisCallback(\n audioAnalysisData: AudioAnalysis\n ): void {\n this.emit('AudioAnalysis', audioAnalysisData)\n }\n\n // Get recording duration\n private getRecordingDuration(): number {\n if (!this.isRecording) {\n return 0\n }\n\n return this.currentDurationMs\n }\n\n emitAudioEvent({ data, position, compression }: EmitAudioEventProps) {\n const fileUri = `${this.streamUuid}.${this.extension}`\n if (compression?.size) {\n this.lastEmittedCompressionSize = compression.size\n this.totalCompressedSize = compression.totalSize\n }\n\n // Update latest position for tracking\n this.latestPosition = position\n\n // Calculate duration of this chunk in ms\n const sampleRate = this.recordingConfig?.sampleRate || 44100\n const chunkDurationMs = (data.length / sampleRate) * 1000\n\n // Handle duration calculation\n if (this.customRecorder?.isFirstChunkAfterSwitch) {\n this.logger?.debug(\n `Processing first chunk after device switch, duration preserved at ${this.currentDurationMs}ms`\n )\n this.customRecorder.isFirstChunkAfterSwitch = false\n } else {\n this.currentDurationMs += chunkDurationMs\n }\n\n const audioEventPayload: AudioEventPayload = {\n fileUri,\n mimeType: `audio/${this.extension}`,\n lastEmittedSize: this.lastEmittedSize,\n deltaSize: data.byteLength,\n position,\n totalSize: this.currentSize,\n buffer: data,\n streamUuid: this.streamUuid ?? '',\n compression: compression\n ? {\n data: compression?.data,\n totalSize: this.totalCompressedSize,\n eventDataSize: compression?.size ?? 0,\n position,\n }\n : undefined,\n }\n\n this.emit('AudioData', audioEventPayload)\n }\n\n // Stop recording\n async stopRecording(): Promise<AudioRecording> {\n if (!this.customRecorder) {\n throw new Error('Recorder is not initialized')\n }\n\n this.logger?.debug('Starting stop process')\n\n try {\n const { compressedBlob, uncompressedBlob } =\n await this.customRecorder.stop()\n\n this.isRecording = false\n this.isPaused = false\n\n let compression: AudioRecording['compression']\n let fileUri = `${this.streamUuid}.${this.extension}`\n let mimeType = `audio/${this.extension}`\n\n // Handle both compressed and uncompressed blobs according to configuration\n const compressionEnabled =\n this.recordingConfig?.compression?.enabled ?? false\n\n // Process compressed blob if available\n if (compressedBlob) {\n const compressedUri = URL.createObjectURL(compressedBlob)\n const compressedInfo = {\n compressedFileUri: compressedUri,\n size: compressedBlob.size,\n mimeType: 'audio/webm',\n format: 'opus',\n bitrate:\n this.recordingConfig?.compression?.bitrate ?? 128000,\n }\n\n // If compression is enabled, use compressed blob as primary format\n if (compressionEnabled) {\n this.logger?.debug(\n 'Using compressed audio as primary output'\n )\n fileUri = compressedUri\n mimeType = 'audio/webm'\n\n // Store compression info\n compression = compressedInfo\n } else {\n // Compression was enabled during recording but not set as primary\n // Store as alternate format\n compression = compressedInfo\n }\n }\n\n // Process uncompressed WAV if available\n if (uncompressedBlob) {\n const wavUri = URL.createObjectURL(uncompressedBlob)\n\n // If compression is disabled or no compressed blob is available,\n // use WAV as primary format\n if (!compressionEnabled || !compressedBlob) {\n this.logger?.debug(\n 'Using uncompressed WAV as primary output'\n )\n fileUri = wavUri\n mimeType = 'audio/wav'\n }\n }\n\n // Use the stored streamUuid for the final filename\n const filename = `${this.streamUuid}.${this.extension}`\n const result: AudioRecording = {\n fileUri,\n filename,\n bitDepth: this.bitDepth,\n createdAt: this.recordingStartTime,\n channels: this.recordingConfig?.channels ?? 1,\n sampleRate: this.recordingConfig?.sampleRate ?? 44100,\n durationMs: this.currentDurationMs,\n size: this.currentSize,\n mimeType,\n compression,\n }\n\n // Reset after creating the result\n this.streamUuid = null\n\n // Reset recording state variables to prepare for next recording\n this.currentDurationMs = 0\n this.currentSize = 0\n this.lastEmittedSize = 0\n this.totalCompressedSize = 0\n this.lastEmittedCompressionSize = 0\n this.audioChunks = []\n\n return result\n } catch (error) {\n this.logger?.error('Error stopping recording:', error)\n throw error\n }\n }\n\n // Pause recording\n async pauseRecording() {\n if (!this.isRecording) {\n throw new Error('Recording is not active')\n }\n\n if (this.isPaused) {\n this.logger?.debug('Recording already paused, skipping')\n return\n }\n\n try {\n if (this.customRecorder) {\n this.customRecorder.pause()\n }\n this.isPaused = true\n this.pausedTime = Date.now()\n } catch (error) {\n this.logger?.error('Error in pauseRecording', error)\n // Even if the pause operation failed, make sure our state is consistent\n this.isPaused = true\n this.pausedTime = Date.now()\n }\n }\n\n // Resume recording\n async resumeRecording() {\n if (!this.isPaused) {\n throw new Error('Recording is not paused')\n }\n\n this.logger?.debug('Resuming recording', {\n deviceDisconnectionBehavior:\n this.recordingConfig?.deviceDisconnectionBehavior,\n isDeviceDisconnected: this.customRecorder?.isDeviceDisconnected,\n })\n\n try {\n // If we have no recorder, or if the device is disconnected, always attempt fallback\n if (\n !this.customRecorder ||\n this.customRecorder.isDeviceDisconnected\n ) {\n this.logger?.debug(\n 'No recorder exists or device disconnected - attempting fallback on resume'\n )\n await this.handleDeviceFallback()\n // handleDeviceFallback will manage resuming if successful, or emit error if failed.\n return\n }\n\n // Normal resume path - device is still connected\n this.customRecorder.resume()\n this.isPaused = false\n\n // Adjust the recording start time to account for the pause duration\n const pauseDuration = Date.now() - this.pausedTime\n this.recordingStartTime += pauseDuration\n this.pausedTime = 0\n\n this.emit('onRecordingInterrupted', {\n reason: 'userResumed',\n isPaused: false,\n timestamp: Date.now(),\n })\n } catch (error) {\n this.logger?.error('Resume failed:', error)\n // Fallback to emitting a general failure if resume fails unexpectedly\n this.emit('onRecordingInterrupted', {\n reason: 'resumeFailed', // Use a more specific reason\n isPaused: true, // Remain paused if resume fails\n timestamp: Date.now(),\n message:\n 'Failed to resume recording. Please stop and start again.',\n })\n }\n }\n\n // Get current status\n status() {\n const durationMs = this.getRecordingDuration()\n\n const status: AudioStreamStatus = {\n isRecording: this.isRecording,\n isPaused: this.isPaused,\n durationMs,\n size: this.currentSize,\n interval: this.currentInterval,\n intervalAnalysis: this.currentIntervalAnalysis,\n mimeType: `audio/${this.extension}`,\n compression: this.recordingConfig?.compression?.enabled\n ? {\n size: this.totalCompressedSize,\n mimeType: 'audio/webm',\n format: this.recordingConfig.compression.format ?? 'opus',\n bitrate:\n this.recordingConfig.compression.bitrate ?? 128000,\n compressedFileUri: `${this.streamUuid}.webm`,\n }\n : undefined,\n }\n return status\n }\n\n /**\n * Handles device fallback when the current device is disconnected\n */\n private async handleDeviceFallback(): Promise<boolean> {\n this.logger?.debug('Starting device fallback procedure')\n\n if (!this.isRecording) {\n return false\n }\n\n try {\n // Save important state before switching\n const currentPosition = this.latestPosition\n const existingAudioChunks = [...this.audioChunks]\n\n // Save compressed chunks if available\n let compressedChunks: Blob[] = []\n if (this.customRecorder) {\n try {\n compressedChunks = this.customRecorder.getCompressedChunks()\n } catch (err) {\n this.logger?.warn('Failed to get compressed chunks:', err)\n }\n }\n\n // Save the current counter value for continuity\n let currentDataPointCounter = 0\n if (this.customRecorder) {\n currentDataPointCounter =\n this.customRecorder.getDataPointCounter()\n }\n\n // Clean up existing recorder\n if (this.customRecorder) {\n try {\n this.customRecorder.cleanup()\n } catch (cleanupError) {\n this.logger?.warn('Error during cleanup:', cleanupError)\n }\n }\n\n // Keep recording state true but mark as paused\n this.isPaused = true\n this.pausedTime = Date.now()\n\n // Store current size and other stats\n const previousTotalSize = this.currentSize\n const previousLastEmittedSize = this.lastEmittedSize\n const previousCompressedSize = this.totalCompressedSize\n\n // Try to get a fallback device\n const fallbackDeviceInfo = await this.getFallbackDevice()\n if (!fallbackDeviceInfo) {\n this.emit('onRecordingInterrupted', {\n reason: 'deviceSwitchFailed',\n isPaused: true,\n timestamp: Date.now(),\n message:\n 'Failed to switch to fallback device. Recording paused.',\n })\n return false\n }\n\n // Start recording with the new device\n try {\n const stream = await this.requestPermissionsAndGetUserMedia(\n fallbackDeviceInfo.deviceId\n )\n const audioContext = new (window.AudioContext ||\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - Allow webkitAudioContext for Safari\n window.webkitAudioContext)()\n\n const source = audioContext.createMediaStreamSource(stream)\n\n // Create a new recorder with the fallback device\n this.customRecorder = new WebRecorder({\n logger: this.logger,\n audioContext,\n source,\n recordingConfig: this.recordingConfig || {},\n emitAudioEventCallback:\n this.customRecorderEventCallback.bind(this),\n emitAudioAnalysisCallback:\n this.customRecorderAnalysisCallback.bind(this),\n onInterruption: this.handleRecordingInterruption.bind(this),\n })\n\n await this.customRecorder.init()\n\n // Set the initial position to continue from the previous device\n this.customRecorder.setPosition(currentPosition)\n\n // Reset the data point counter to continue from where the previous device left off\n if (currentDataPointCounter > 0) {\n this.customRecorder.resetDataPointCounter(\n currentDataPointCounter\n )\n }\n\n // Prepare the recorder to handle the device switch properly\n this.customRecorder.prepareForDeviceSwitch()\n\n // Restore the existing audio chunks\n if (existingAudioChunks.length > 0) {\n this.audioChunks = existingAudioChunks\n }\n\n // Restore compressed chunks if available\n if (compressedChunks.length > 0) {\n this.customRecorder.setCompressedChunks(compressedChunks)\n }\n\n // Start the new recorder while preserving counters\n this.customRecorder.start(true)\n\n // Update recording state\n this.isPaused = false\n this.recordingStartTime = Date.now()\n\n // Restore size counters to maintain continuity\n this.currentSize = previousTotalSize\n this.lastEmittedSize = previousLastEmittedSize\n this.totalCompressedSize = previousCompressedSize\n\n // Notify that we switched to a fallback device\n if (this.eventCallback) {\n this.eventCallback({\n type: 'deviceFallback',\n device: fallbackDeviceInfo.deviceId,\n timestamp: new Date(),\n })\n }\n return true\n } catch (error) {\n this.logger?.error(\n 'Failed to start recording with fallback device',\n error\n )\n this.isPaused = true\n this.emit('onRecordingInterrupted', {\n reason: 'deviceSwitchFailed',\n isPaused: true,\n timestamp: Date.now(),\n message:\n 'Failed to switch to fallback device. Recording paused.',\n })\n return false\n }\n } catch (error) {\n this.logger?.error('Failed to use fallback device', error)\n this.isPaused = true\n this.emit('onRecordingInterrupted', {\n reason: 'deviceSwitchFailed',\n isPaused: true,\n timestamp: Date.now(),\n message:\n 'Failed to switch to fallback device. Recording paused.',\n })\n return false\n }\n }\n\n /**\n * Attempts to get a fallback audio device\n */\n private async getFallbackDevice(): Promise<MediaDeviceInfo | null> {\n try {\n // Get list of available audio input devices\n const devices = await navigator.mediaDevices.enumerateDevices()\n const audioInputDevices = devices.filter(\n (device) => device.kind === 'audioinput'\n )\n\n if (audioInputDevices.length === 0) {\n return null\n }\n\n // Try to find a device that's not the current one\n if (this.customRecorder) {\n try {\n // Use mediaDevices.enumerateDevices to find the current active device\n const tracks = navigator.mediaDevices\n .getUserMedia({ audio: true })\n .then((stream) => {\n const track = stream.getAudioTracks()[0]\n return track ? track.label : ''\n })\n .catch(() => '')\n\n const currentTrackLabel = await tracks\n\n if (currentTrackLabel) {\n // Find a device with a different label\n const differentDevice = audioInputDevices.find(\n (device) =>\n device.label &&\n device.label !== currentTrackLabel\n )\n\n if (differentDevice) {\n return differentDevice\n }\n }\n } catch (err) {\n this.logger?.warn(\n 'Error determining current device, using default',\n err\n )\n }\n }\n\n // Return the first available device (default device)\n return audioInputDevices[0]\n } catch (error) {\n this.logger?.error('Error finding fallback device:', error)\n return null\n }\n }\n\n /**\n * Gets user media with specific device ID\n */\n private async requestPermissionsAndGetUserMedia(\n deviceId: string\n ): Promise<MediaStream> {\n try {\n // Request the specific device\n return await navigator.mediaDevices.getUserMedia({\n audio: {\n deviceId: { exact: deviceId },\n },\n })\n } catch (error) {\n this.logger?.error(\n `Failed to get media for device ${deviceId}`,\n error\n )\n // Try with default constraints as fallback\n return await navigator.mediaDevices.getUserMedia({ audio: true })\n }\n }\n\n init(options?: ExpoAudioStreamOptions): Promise<void> {\n try {\n this.logger = options?.logger\n this.eventCallback = options?.eventCallback\n return Promise.resolve()\n } catch (error) {\n this.logger?.error('Error initializing ExpoAudioStream', error)\n return Promise.reject(error)\n }\n }\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C,QAAgB;QAEhB,IAAI,CAAC;YACD,8BAA8B;YAC9B,OAAO,MAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC;gBAC7C,KAAK,EAAE;oBACH,QAAQ,EAAE,EAAE,KAAK,EAAE,QAAQ,EAAE;iBAChC;aACJ,CAAC,CAAA;QACN,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,EAAE,KAAK,CACd,kCAAkC,QAAQ,EAAE,EAC5C,KAAK,CACR,CAAA;YACD,2CAA2C;YAC3C,OAAO,MAAM,SAAS,CAAC,YAAY,CAAC,YAAY,CAAC,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAA;QACrE,CAAC;IACL,CAAC;IAED,IAAI,CAAC,OAAgC;QACjC,IAAI,CAAC;YACD,IAAI,CAAC,MAAM,GAAG,OAAO,EAAE,MAAM,CAAA;YAC7B,IAAI,CAAC,aAAa,GAAG,OAAO,EAAE,aAAa,CAAA;YAC3C,OAAO,OAAO,CAAC,OAAO,EAAE,CAAA;QAC5B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,EAAE,KAAK,CAAC,oCAAoC,EAAE,KAAK,CAAC,CAAA;YAC/D,OAAO,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;QAChC,CAAC;IACL,CAAC;CACJ;AAt1BD,gDAs1BC","sourcesContent":["// src/ExpoAudioStreamModule.web.ts\nimport { LegacyEventEmitter } from 'expo-modules-core'\n\nimport { AudioAnalysis } from './AudioAnalysis/AudioAnalysis.types'\nimport {\n AudioRecording,\n AudioStreamStatus,\n BitDepth,\n ConsoleLike,\n RecordingConfig,\n RecordingInterruptionReason,\n StartRecordingResult,\n} from './ExpoAudioStream.types'\nimport { WebRecorder } from './WebRecorder.web'\nimport { AudioEventPayload } from './events'\nimport { encodingToBitDepth } from './utils/encodingToBitDepth'\n\nexport interface AudioStreamEvent {\n type: string\n device?: string\n timestamp: Date\n}\n\nexport interface ExpoAudioStreamOptions {\n logger?: ConsoleLike\n eventCallback?: (event: AudioStreamEvent) => void\n}\n\nexport interface EmitAudioEventProps {\n data: Float32Array\n position: number\n compression?: {\n data: Blob\n size: number\n totalSize: number\n mimeType: string\n format: string\n bitrate: number\n }\n}\nexport type EmitAudioEventFunction = (_: EmitAudioEventProps) => void\nexport type EmitAudioAnalysisFunction = (_: AudioAnalysis) => void\n\nexport interface ExpoAudioStreamWebProps {\n logger?: ConsoleLike\n audioWorkletUrl: string\n featuresExtratorUrl: string\n maxBufferSize?: number // Maximum number of chunks to keep in memory\n}\n\nexport class ExpoAudioStreamWeb extends LegacyEventEmitter {\n customRecorder: WebRecorder | null\n audioChunks: Float32Array[]\n isRecording: boolean\n isPaused: boolean\n recordingStartTime: number\n pausedTime: number\n currentDurationMs: number\n currentSize: number\n currentInterval: number\n currentIntervalAnalysis: number\n lastEmittedSize: number\n lastEmittedTime: number\n lastEmittedCompressionSize: number\n lastEmittedAnalysisTime: number\n streamUuid: string | null\n extension: 'webm' | 'wav' = 'wav' // Default extension is 'wav'\n recordingConfig?: RecordingConfig\n bitDepth: BitDepth // Bit depth of the audio\n audioWorkletUrl: string\n featuresExtratorUrl: string\n logger?: ConsoleLike\n latestPosition: number = 0\n totalCompressedSize: number = 0\n private readonly maxBufferSize: number\n private eventCallback?: (event: AudioStreamEvent) => void\n\n constructor({\n audioWorkletUrl,\n featuresExtratorUrl,\n logger,\n maxBufferSize = 100, // Default to storing last 100 chunks (1 chunk = 0.5 seconds)\n }: ExpoAudioStreamWebProps) {\n const mockNativeModule = {\n addListener: () => {},\n removeListeners: () => {},\n }\n super(mockNativeModule) // Pass the mock native module to the parent class\n\n this.logger = logger\n this.customRecorder = null\n this.audioChunks = []\n this.isRecording = false\n this.isPaused = false\n this.recordingStartTime = 0\n this.pausedTime = 0\n this.currentDurationMs = 0\n this.currentSize = 0\n this.bitDepth = 32 // Default\n this.currentInterval = 1000 // Default interval in ms\n this.currentIntervalAnalysis = 500 // Default analysis interval in ms\n this.lastEmittedSize = 0\n this.lastEmittedTime = 0\n this.latestPosition = 0\n this.lastEmittedCompressionSize = 0\n this.lastEmittedAnalysisTime = 0\n this.streamUuid = null // Initialize UUID on first recording start\n this.audioWorkletUrl = audioWorkletUrl\n this.featuresExtratorUrl = featuresExtratorUrl\n this.maxBufferSize = maxBufferSize\n }\n\n // Utility to handle user media stream\n async getMediaStream() {\n try {\n this.logger?.debug('Requesting user media (microphone)...')\n\n // First check if the browser supports the necessary audio APIs\n if (!navigator?.mediaDevices?.getUserMedia) {\n this.logger?.error(\n 'Browser does not support mediaDevices.getUserMedia'\n )\n throw new Error('Browser does not support audio recording')\n }\n\n // Get media with detailed audio constraints for better diagnostics\n const constraints = {\n audio: {\n echoCancellation: true,\n noiseSuppression: true,\n autoGainControl: true,\n // Add deviceId constraint if specified\n ...(this.recordingConfig?.deviceId\n ? {\n deviceId: {\n exact: this.recordingConfig.deviceId,\n },\n }\n : {}),\n },\n }\n\n this.logger?.debug('Media constraints:', constraints)\n\n const stream =\n await navigator.mediaDevices.getUserMedia(constraints)\n\n // Get detailed info about the audio track for debugging\n const audioTracks = stream.getAudioTracks()\n if (audioTracks.length > 0) {\n const track = audioTracks[0]\n const settings = track.getSettings()\n this.logger?.debug('Audio track obtained:', {\n label: track.label,\n id: track.id,\n enabled: track.enabled,\n muted: track.muted,\n readyState: track.readyState,\n settings,\n })\n } else {\n this.logger?.warn('Stream has no audio tracks!')\n }\n\n return stream\n } catch (error) {\n this.logger?.error('Failed to get media stream:', error)\n throw error\n }\n }\n\n // Prepare recording with options\n async prepareRecording(\n recordingConfig: RecordingConfig = {}\n ): Promise<boolean> {\n if (this.isRecording) {\n this.logger?.warn(\n 'Cannot prepare: Recording is already in progress'\n )\n return false\n }\n\n try {\n // Check permissions and initialize basic settings\n await this.getMediaStream().then((stream) => {\n // Just verify we can access the microphone by getting a stream, then release it\n stream.getTracks().forEach((track) => track.stop())\n })\n\n this.bitDepth = encodingToBitDepth({\n encoding: recordingConfig.encoding ?? 'pcm_32bit',\n })\n\n // Store recording configuration for later use\n this.recordingConfig = recordingConfig\n\n // Use custom filename if provided, otherwise fallback to timestamp\n if (recordingConfig.filename) {\n // Remove any existing extension from the filename\n this.streamUuid = recordingConfig.filename.replace(\n /\\.[^/.]+$/,\n ''\n )\n } else {\n this.streamUuid = Date.now().toString()\n }\n\n this.logger?.debug('Recording preparation completed successfully')\n return true\n } catch (error) {\n this.logger?.error('Error preparing recording:', error)\n return false\n }\n }\n\n // Start recording with options\n async startRecording(\n recordingConfig: RecordingConfig = {}\n ): Promise<StartRecordingResult> {\n if (this.isRecording) {\n throw new Error('Recording is already in progress')\n }\n\n // If we haven't prepared or have different settings, prepare now\n if (\n !this.recordingConfig ||\n this.recordingConfig.sampleRate !== recordingConfig.sampleRate ||\n this.recordingConfig.channels !== recordingConfig.channels ||\n this.recordingConfig.encoding !== recordingConfig.encoding\n ) {\n await this.prepareRecording(recordingConfig)\n } else {\n this.logger?.debug(\n 'Using previously prepared recording configuration'\n )\n }\n\n // Save recording config for reference\n this.recordingConfig = recordingConfig\n\n const audioContext = new (window.AudioContext ||\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - Allow webkitAudioContext for Safari\n window.webkitAudioContext)()\n const stream = await this.getMediaStream()\n\n const source = audioContext.createMediaStreamSource(stream)\n\n this.customRecorder = new WebRecorder({\n logger: this.logger,\n audioContext,\n source,\n recordingConfig,\n emitAudioEventCallback: this.customRecorderEventCallback.bind(this),\n emitAudioAnalysisCallback:\n this.customRecorderAnalysisCallback.bind(this),\n onInterruption: this.handleRecordingInterruption.bind(this),\n })\n await this.customRecorder.init()\n this.customRecorder.start()\n\n this.isRecording = true\n this.recordingStartTime = Date.now()\n this.pausedTime = 0\n this.isPaused = false\n this.lastEmittedSize = 0\n this.lastEmittedTime = 0\n this.lastEmittedCompressionSize = 0\n this.currentInterval = recordingConfig.interval ?? 1000\n this.currentIntervalAnalysis = recordingConfig.intervalAnalysis ?? 500\n this.lastEmittedAnalysisTime = Date.now()\n\n // Use custom filename if provided, otherwise fallback to timestamp\n if (recordingConfig.filename) {\n // Remove any existing extension from the filename\n this.streamUuid = recordingConfig.filename.replace(/\\.[^/.]+$/, '')\n } else {\n this.streamUuid = Date.now().toString()\n }\n\n const fileUri = `${this.streamUuid}.${this.extension}`\n const streamConfig: StartRecordingResult = {\n fileUri,\n mimeType: `audio/${this.extension}`,\n bitDepth: this.bitDepth,\n channels: recordingConfig.channels ?? 1,\n sampleRate: recordingConfig.sampleRate ?? 44100,\n compression: recordingConfig.output?.compressed?.enabled\n ? {\n ...recordingConfig.output.compressed,\n bitrate:\n recordingConfig.output.compressed.bitrate ?? 128000,\n size: 0,\n mimeType: 'audio/webm',\n format:\n recordingConfig.output.compressed.format ?? 'opus',\n compressedFileUri: '',\n }\n : undefined,\n }\n return streamConfig\n }\n\n /**\n * Centralized handler for recording interruptions\n */\n private handleRecordingInterruption(event: {\n reason: RecordingInterruptionReason | string\n isPaused: boolean\n timestamp: number\n message?: string\n }): void {\n this.logger?.debug(`Received recording interruption: ${event.reason}`)\n\n // Update local state if the interruption should pause recording\n if (event.isPaused) {\n this.isPaused = true\n\n // If this is a device disconnection, handle according to behavior setting\n if (event.reason === 'deviceDisconnected') {\n this.pausedTime = Date.now()\n\n // Check if we should try fallback to another device\n if (\n this.recordingConfig?.deviceDisconnectionBehavior ===\n 'fallback'\n ) {\n this.logger?.debug(\n 'Device disconnected with fallback behavior - attempting to switch to default device'\n )\n\n // Try to restart with default device\n this.handleDeviceFallback().catch((error) => {\n // If fallback fails, emit warning\n this.logger?.error('Device fallback failed:', error)\n this.emit('onRecordingInterrupted', {\n reason: 'deviceSwitchFailed',\n isPaused: true,\n timestamp: Date.now(),\n message:\n 'Failed to switch to fallback device. Recording paused.',\n })\n })\n } else {\n // Just warn about disconnection if fallback not enabled\n this.logger?.warn(\n 'Device disconnected - recording paused automatically'\n )\n this.emit('onRecordingInterrupted', event)\n }\n } else {\n // For other interruption types, just emit the event\n this.emit('onRecordingInterrupted', event)\n }\n } else {\n // If not causing a pause, just forward the event\n this.emit('onRecordingInterrupted', event)\n }\n }\n\n /**\n * Handler for audio events from the WebRecorder\n */\n private customRecorderEventCallback({\n data,\n position,\n compression,\n }: EmitAudioEventProps): void {\n // Keep only the latest chunks based on maxBufferSize\n this.audioChunks.push(new Float32Array(data))\n if (this.audioChunks.length > this.maxBufferSize) {\n this.audioChunks.shift() // Remove oldest chunk\n }\n this.currentSize += data.byteLength\n this.emitAudioEvent({ data, position, compression })\n this.lastEmittedTime = Date.now()\n this.lastEmittedSize = this.currentSize\n this.lastEmittedCompressionSize = compression?.size ?? 0\n }\n\n /**\n * Handler for audio analysis events from the WebRecorder\n */\n private customRecorderAnalysisCallback(\n audioAnalysisData: AudioAnalysis\n ): void {\n this.emit('AudioAnalysis', audioAnalysisData)\n }\n\n // Get recording duration\n private getRecordingDuration(): number {\n if (!this.isRecording) {\n return 0\n }\n\n return this.currentDurationMs\n }\n\n emitAudioEvent({ data, position, compression }: EmitAudioEventProps) {\n const fileUri = `${this.streamUuid}.${this.extension}`\n if (compression?.size) {\n this.lastEmittedCompressionSize = compression.size\n this.totalCompressedSize = compression.totalSize\n }\n\n // Update latest position for tracking\n this.latestPosition = position\n\n // Calculate duration of this chunk in ms\n const sampleRate = this.recordingConfig?.sampleRate || 44100\n const chunkDurationMs = (data.length / sampleRate) * 1000\n\n // Handle duration calculation\n if (this.customRecorder?.isFirstChunkAfterSwitch) {\n this.logger?.debug(\n `Processing first chunk after device switch, duration preserved at ${this.currentDurationMs}ms`\n )\n this.customRecorder.isFirstChunkAfterSwitch = false\n } else {\n this.currentDurationMs += chunkDurationMs\n }\n\n const audioEventPayload: AudioEventPayload = {\n fileUri,\n mimeType: `audio/${this.extension}`,\n lastEmittedSize: this.lastEmittedSize,\n deltaSize: data.byteLength,\n position,\n totalSize: this.currentSize,\n buffer: data,\n streamUuid: this.streamUuid ?? '',\n compression: compression\n ? {\n data: compression?.data,\n totalSize: this.totalCompressedSize,\n eventDataSize: compression?.size ?? 0,\n position,\n }\n : undefined,\n }\n\n this.emit('AudioData', audioEventPayload)\n }\n\n // Stop recording\n async stopRecording(): Promise<AudioRecording> {\n if (!this.customRecorder) {\n throw new Error('Recorder is not initialized')\n }\n\n this.logger?.debug('Starting stop process')\n\n try {\n const { compressedBlob, uncompressedBlob } =\n await this.customRecorder.stop()\n\n this.isRecording = false\n this.isPaused = false\n\n let compression: AudioRecording['compression']\n let fileUri = `${this.streamUuid}.${this.extension}`\n let mimeType = `audio/${this.extension}`\n\n // Handle both compressed and uncompressed blobs according to new output configuration\n const primaryEnabled =\n this.recordingConfig?.output?.primary?.enabled ?? true\n const compressedEnabled =\n this.recordingConfig?.output?.compressed?.enabled ?? false\n\n // Process compressed blob if available and enabled\n if (compressedBlob && compressedEnabled) {\n const compressedUri = URL.createObjectURL(compressedBlob)\n const compressedInfo = {\n compressedFileUri: compressedUri,\n size: compressedBlob.size,\n mimeType: 'audio/webm',\n format:\n this.recordingConfig?.output?.compressed?.format ??\n 'opus',\n bitrate:\n this.recordingConfig?.output?.compressed?.bitrate ??\n 128000,\n }\n\n // Store compression info\n compression = compressedInfo\n\n // If primary is disabled, use compressed as main file\n if (!primaryEnabled) {\n this.logger?.debug(\n 'Using compressed audio as primary output (primary disabled)'\n )\n fileUri = compressedUri\n mimeType = 'audio/webm'\n }\n }\n\n // Process uncompressed WAV if available and primary is enabled\n if (uncompressedBlob && primaryEnabled) {\n const wavUri = URL.createObjectURL(uncompressedBlob)\n fileUri = wavUri\n mimeType = 'audio/wav'\n } else if (!primaryEnabled && !compressedEnabled) {\n // No outputs enabled - streaming only mode\n this.logger?.debug('No outputs enabled - streaming only mode')\n fileUri = ''\n mimeType = 'audio/wav'\n }\n\n // Use the stored streamUuid for the final filename\n const filename = fileUri\n ? `${this.streamUuid}.${this.extension}`\n : 'stream-only'\n const result: AudioRecording = {\n fileUri,\n filename,\n bitDepth: this.bitDepth,\n createdAt: this.recordingStartTime,\n channels: this.recordingConfig?.channels ?? 1,\n sampleRate: this.recordingConfig?.sampleRate ?? 44100,\n durationMs: this.currentDurationMs,\n size: primaryEnabled ? this.currentSize : 0,\n mimeType,\n compression,\n }\n\n // Reset after creating the result\n this.streamUuid = null\n\n // Reset recording state variables to prepare for next recording\n this.currentDurationMs = 0\n this.currentSize = 0\n this.lastEmittedSize = 0\n this.totalCompressedSize = 0\n this.lastEmittedCompressionSize = 0\n this.audioChunks = []\n\n return result\n } catch (error) {\n this.logger?.error('Error stopping recording:', error)\n throw error\n }\n }\n\n // Pause recording\n async pauseRecording() {\n if (!this.isRecording) {\n throw new Error('Recording is not active')\n }\n\n if (this.isPaused) {\n this.logger?.debug('Recording already paused, skipping')\n return\n }\n\n try {\n if (this.customRecorder) {\n this.customRecorder.pause()\n }\n this.isPaused = true\n this.pausedTime = Date.now()\n } catch (error) {\n this.logger?.error('Error in pauseRecording', error)\n // Even if the pause operation failed, make sure our state is consistent\n this.isPaused = true\n this.pausedTime = Date.now()\n }\n }\n\n // Resume recording\n async resumeRecording() {\n if (!this.isPaused) {\n throw new Error('Recording is not paused')\n }\n\n this.logger?.debug('Resuming recording', {\n deviceDisconnectionBehavior:\n this.recordingConfig?.deviceDisconnectionBehavior,\n isDeviceDisconnected: this.customRecorder?.isDeviceDisconnected,\n })\n\n try {\n // If we have no recorder, or if the device is disconnected, always attempt fallback\n if (\n !this.customRecorder ||\n this.customRecorder.isDeviceDisconnected\n ) {\n this.logger?.debug(\n 'No recorder exists or device disconnected - attempting fallback on resume'\n )\n await this.handleDeviceFallback()\n // handleDeviceFallback will manage resuming if successful, or emit error if failed.\n return\n }\n\n // Normal resume path - device is still connected\n this.customRecorder.resume()\n this.isPaused = false\n\n // Adjust the recording start time to account for the pause duration\n const pauseDuration = Date.now() - this.pausedTime\n this.recordingStartTime += pauseDuration\n this.pausedTime = 0\n\n this.emit('onRecordingInterrupted', {\n reason: 'userResumed',\n isPaused: false,\n timestamp: Date.now(),\n })\n } catch (error) {\n this.logger?.error('Resume failed:', error)\n // Fallback to emitting a general failure if resume fails unexpectedly\n this.emit('onRecordingInterrupted', {\n reason: 'resumeFailed', // Use a more specific reason\n isPaused: true, // Remain paused if resume fails\n timestamp: Date.now(),\n message:\n 'Failed to resume recording. Please stop and start again.',\n })\n }\n }\n\n // Get current status\n status() {\n const durationMs = this.getRecordingDuration()\n\n const status: AudioStreamStatus = {\n isRecording: this.isRecording,\n isPaused: this.isPaused,\n durationMs,\n size: this.currentSize,\n interval: this.currentInterval,\n intervalAnalysis: this.currentIntervalAnalysis,\n mimeType: `audio/${this.extension}`,\n compression: this.recordingConfig?.output?.compressed?.enabled\n ? {\n size: this.totalCompressedSize,\n mimeType: 'audio/webm',\n format:\n this.recordingConfig.output.compressed.format ??\n 'opus',\n bitrate:\n this.recordingConfig.output.compressed.bitrate ??\n 128000,\n compressedFileUri: `${this.streamUuid}.webm`,\n }\n : undefined,\n }\n return status\n }\n\n /**\n * Handles device fallback when the current device is disconnected\n */\n private async handleDeviceFallback(): Promise<boolean> {\n this.logger?.debug('Starting device fallback procedure')\n\n if (!this.isRecording) {\n return false\n }\n\n try {\n // Save important state before switching\n const currentPosition = this.latestPosition\n const existingAudioChunks = [...this.audioChunks]\n\n // Save compressed chunks if available\n let compressedChunks: Blob[] = []\n if (this.customRecorder) {\n try {\n compressedChunks = this.customRecorder.getCompressedChunks()\n } catch (err) {\n this.logger?.warn('Failed to get compressed chunks:', err)\n }\n }\n\n // Save the current counter value for continuity\n let currentDataPointCounter = 0\n if (this.customRecorder) {\n currentDataPointCounter =\n this.customRecorder.getDataPointCounter()\n }\n\n // Clean up existing recorder\n if (this.customRecorder) {\n try {\n this.customRecorder.cleanup()\n } catch (cleanupError) {\n this.logger?.warn('Error during cleanup:', cleanupError)\n }\n }\n\n // Keep recording state true but mark as paused\n this.isPaused = true\n this.pausedTime = Date.now()\n\n // Store current size and other stats\n const previousTotalSize = this.currentSize\n const previousLastEmittedSize = this.lastEmittedSize\n const previousCompressedSize = this.totalCompressedSize\n\n // Try to get a fallback device\n const fallbackDeviceInfo = await this.getFallbackDevice()\n if (!fallbackDeviceInfo) {\n this.emit('onRecordingInterrupted', {\n reason: 'deviceSwitchFailed',\n isPaused: true,\n timestamp: Date.now(),\n message:\n 'Failed to switch to fallback device. Recording paused.',\n })\n return false\n }\n\n // Start recording with the new device\n try {\n const stream = await this.requestPermissionsAndGetUserMedia(\n fallbackDeviceInfo.deviceId\n )\n const audioContext = new (window.AudioContext ||\n // eslint-disable-next-line @typescript-eslint/ban-ts-comment\n // @ts-ignore - Allow webkitAudioContext for Safari\n window.webkitAudioContext)()\n\n const source = audioContext.createMediaStreamSource(stream)\n\n // Create a new recorder with the fallback device\n this.customRecorder = new WebRecorder({\n logger: this.logger,\n audioContext,\n source,\n recordingConfig: this.recordingConfig || {},\n emitAudioEventCallback:\n this.customRecorderEventCallback.bind(this),\n emitAudioAnalysisCallback:\n this.customRecorderAnalysisCallback.bind(this),\n onInterruption: this.handleRecordingInterruption.bind(this),\n })\n\n await this.customRecorder.init()\n\n // Set the initial position to continue from the previous device\n this.customRecorder.setPosition(currentPosition)\n\n // Reset the data point counter to continue from where the previous device left off\n if (currentDataPointCounter > 0) {\n this.customRecorder.resetDataPointCounter(\n currentDataPointCounter\n )\n }\n\n // Prepare the recorder to handle the device switch properly\n this.customRecorder.prepareForDeviceSwitch()\n\n // Restore the existing audio chunks\n if (existingAudioChunks.length > 0) {\n this.audioChunks = existingAudioChunks\n }\n\n // Restore compressed chunks if available\n if (compressedChunks.length > 0) {\n this.customRecorder.setCompressedChunks(compressedChunks)\n }\n\n // Start the new recorder while preserving counters\n this.customRecorder.start(true)\n\n // Update recording state\n this.isPaused = false\n this.recordingStartTime = Date.now()\n\n // Restore size counters to maintain continuity\n this.currentSize = previousTotalSize\n this.lastEmittedSize = previousLastEmittedSize\n this.totalCompressedSize = previousCompressedSize\n\n // Notify that we switched to a fallback device\n if (this.eventCallback) {\n this.eventCallback({\n type: 'deviceFallback',\n device: fallbackDeviceInfo.deviceId,\n timestamp: new Date(),\n })\n }\n return true\n } catch (error) {\n this.logger?.error(\n 'Failed to start recording with fallback device',\n error\n )\n this.isPaused = true\n this.emit('onRecordingInterrupted', {\n reason: 'deviceSwitchFailed',\n isPaused: true,\n timestamp: Date.now(),\n message:\n 'Failed to switch to fallback device. Recording paused.',\n })\n return false\n }\n } catch (error) {\n this.logger?.error('Failed to use fallback device', error)\n this.isPaused = true\n this.emit('onRecordingInterrupted', {\n reason: 'deviceSwitchFailed',\n isPaused: true,\n timestamp: Date.now(),\n message:\n 'Failed to switch to fallback device. Recording paused.',\n })\n return false\n }\n }\n\n /**\n * Attempts to get a fallback audio device\n */\n private async getFallbackDevice(): Promise<MediaDeviceInfo | null> {\n try {\n // Get list of available audio input devices\n const devices = await navigator.mediaDevices.enumerateDevices()\n const audioInputDevices = devices.filter(\n (device) => device.kind === 'audioinput'\n )\n\n if (audioInputDevices.length === 0) {\n return null\n }\n\n // Try to find a device that's not the current one\n if (this.customRecorder) {\n try {\n // Use mediaDevices.enumerateDevices to find the current active device\n const tracks = navigator.mediaDevices\n .getUserMedia({ audio: true })\n .then((stream) => {\n const track = stream.getAudioTracks()[0]\n return track ? track.label : ''\n })\n .catch(() => '')\n\n const currentTrackLabel = await tracks\n\n if (currentTrackLabel) {\n // Find a device with a different label\n const differentDevice = audioInputDevices.find(\n (device) =>\n device.label &&\n device.label !== currentTrackLabel\n )\n\n if (differentDevice) {\n return differentDevice\n }\n }\n } catch (err) {\n this.logger?.warn(\n 'Error determining current device, using default',\n err\n )\n }\n }\n\n // Return the first available device (default device)\n return audioInputDevices[0]\n } catch (error) {\n this.logger?.error('Error finding fallback device:', error)\n return null\n }\n }\n\n /**\n * Gets user media with specific device ID\n */\n private async requestPermissionsAndGetUserMedia(\n deviceId: string\n ): Promise<MediaStream> {\n try {\n // Request the specific device\n return await navigator.mediaDevices.getUserMedia({\n audio: {\n deviceId: { exact: deviceId },\n },\n })\n } catch (error) {\n this.logger?.error(\n `Failed to get media for device ${deviceId}`,\n error\n )\n // Try with default constraints as fallback\n return await navigator.mediaDevices.getUserMedia({ audio: true })\n }\n }\n\n init(options?: ExpoAudioStreamOptions): Promise<void> {\n try {\n this.logger = options?.logger\n this.eventCallback = options?.eventCallback\n return Promise.resolve()\n } catch (error) {\n this.logger?.error('Error initializing ExpoAudioStream', error)\n return Promise.reject(error)\n }\n }\n}\n"]}
|
|
@@ -97,7 +97,7 @@ class WebRecorder {
|
|
|
97
97
|
this.initFeatureExtractorWorker();
|
|
98
98
|
}
|
|
99
99
|
// Initialize compressed recording if enabled
|
|
100
|
-
if (recordingConfig.
|
|
100
|
+
if (recordingConfig.output?.compressed?.enabled) {
|
|
101
101
|
this.initializeCompressedRecorder();
|
|
102
102
|
}
|
|
103
103
|
this.mediaStream = source.mediaStream;
|
|
@@ -153,8 +153,8 @@ class WebRecorder {
|
|
|
153
153
|
const startPosition = Math.floor(i * bytesPerSample);
|
|
154
154
|
const endPosition = Math.floor((i + chunk.length) * bytesPerSample);
|
|
155
155
|
const samples = chunk.length; // Number of samples in this chunk
|
|
156
|
-
// Only store PCM data if
|
|
157
|
-
const shouldStoreUncompressed = this.config.
|
|
156
|
+
// Only store PCM data if primary output is enabled
|
|
157
|
+
const shouldStoreUncompressed = this.config.output?.primary?.enabled ?? true;
|
|
158
158
|
// Store PCM chunks when needed - this is for the final WAV file
|
|
159
159
|
if (shouldStoreUncompressed) {
|
|
160
160
|
// Store the original Float32Array data for later WAV creation
|
|
@@ -187,8 +187,10 @@ class WebRecorder {
|
|
|
187
187
|
size: this.pendingCompressedChunk.size,
|
|
188
188
|
totalSize: this.compressedSize,
|
|
189
189
|
mimeType: 'audio/webm',
|
|
190
|
-
format:
|
|
191
|
-
|
|
190
|
+
format: this.config.output?.compressed?.format ??
|
|
191
|
+
'opus',
|
|
192
|
+
bitrate: this.config.output?.compressed?.bitrate ??
|
|
193
|
+
128000,
|
|
192
194
|
}
|
|
193
195
|
: undefined;
|
|
194
196
|
// Emit chunk immediately - whether compressed or not
|
|
@@ -217,11 +219,11 @@ class WebRecorder {
|
|
|
217
219
|
interval,
|
|
218
220
|
position: this.position,
|
|
219
221
|
deviceId: this.config.deviceId ?? 'default',
|
|
220
|
-
compression: this.config.
|
|
222
|
+
compression: this.config.output?.compressed
|
|
221
223
|
? {
|
|
222
|
-
enabled: this.config.
|
|
223
|
-
format: this.config.
|
|
224
|
-
bitrate: this.config.
|
|
224
|
+
enabled: this.config.output.compressed.enabled,
|
|
225
|
+
format: this.config.output.compressed.format,
|
|
226
|
+
bitrate: this.config.output.compressed.bitrate,
|
|
225
227
|
}
|
|
226
228
|
: 'disabled',
|
|
227
229
|
});
|
|
@@ -644,7 +646,7 @@ class WebRecorder {
|
|
|
644
646
|
}
|
|
645
647
|
this.compressedMediaRecorder = new MediaRecorder(this.source.mediaStream, {
|
|
646
648
|
mimeType,
|
|
647
|
-
audioBitsPerSecond: this.config.
|
|
649
|
+
audioBitsPerSecond: this.config.output?.compressed?.bitrate ?? 128000,
|
|
648
650
|
});
|
|
649
651
|
this.compressedMediaRecorder.ondataavailable = (event) => {
|
|
650
652
|
if (event.data.size > 0) {
|