@siteed/expo-audio-studio 2.4.1 → 2.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/CHANGELOG.md +14 -1
  2. package/README.md +25 -0
  3. package/android/src/main/java/net/siteed/audiostream/AudioAnalysisData.kt +22 -0
  4. package/android/src/main/java/net/siteed/audiostream/AudioDeviceManager.kt +1501 -0
  5. package/android/src/main/java/net/siteed/audiostream/AudioFileHandler.kt +10 -5
  6. package/android/src/main/java/net/siteed/audiostream/AudioNotificationsManager.kt +27 -25
  7. package/android/src/main/java/net/siteed/audiostream/AudioProcessor.kt +73 -71
  8. package/android/src/main/java/net/siteed/audiostream/AudioRecorderManager.kt +576 -252
  9. package/android/src/main/java/net/siteed/audiostream/Constants.kt +17 -1
  10. package/android/src/main/java/net/siteed/audiostream/ExpoAudioStreamModule.kt +419 -155
  11. package/android/src/main/java/net/siteed/audiostream/LogUtils.kt +65 -0
  12. package/android/src/main/java/net/siteed/audiostream/RecordingConfig.kt +9 -1
  13. package/build/AudioAnalysis/AudioAnalysis.types.js.map +1 -1
  14. package/build/AudioDeviceManager.d.ts +107 -0
  15. package/build/AudioDeviceManager.d.ts.map +1 -0
  16. package/build/AudioDeviceManager.js +493 -0
  17. package/build/AudioDeviceManager.js.map +1 -0
  18. package/build/AudioRecorder.provider.d.ts.map +1 -1
  19. package/build/AudioRecorder.provider.js +3 -0
  20. package/build/AudioRecorder.provider.js.map +1 -1
  21. package/build/ExpoAudioStream.types.d.ts +104 -1
  22. package/build/ExpoAudioStream.types.d.ts.map +1 -1
  23. package/build/ExpoAudioStream.types.js +7 -1
  24. package/build/ExpoAudioStream.types.js.map +1 -1
  25. package/build/ExpoAudioStream.web.d.ts +37 -0
  26. package/build/ExpoAudioStream.web.d.ts.map +1 -1
  27. package/build/ExpoAudioStream.web.js +478 -62
  28. package/build/ExpoAudioStream.web.js.map +1 -1
  29. package/build/ExpoAudioStreamModule.d.ts.map +1 -1
  30. package/build/ExpoAudioStreamModule.js +20 -0
  31. package/build/ExpoAudioStreamModule.js.map +1 -1
  32. package/build/WebRecorder.web.d.ts +74 -11
  33. package/build/WebRecorder.web.d.ts.map +1 -1
  34. package/build/WebRecorder.web.js +390 -74
  35. package/build/WebRecorder.web.js.map +1 -1
  36. package/build/hooks/useAudioDevices.d.ts +14 -0
  37. package/build/hooks/useAudioDevices.d.ts.map +1 -0
  38. package/build/hooks/useAudioDevices.js +151 -0
  39. package/build/hooks/useAudioDevices.js.map +1 -0
  40. package/build/index.d.ts +2 -0
  41. package/build/index.d.ts.map +1 -1
  42. package/build/index.js +4 -0
  43. package/build/index.js.map +1 -1
  44. package/build/useAudioRecorder.d.ts +1 -0
  45. package/build/useAudioRecorder.d.ts.map +1 -1
  46. package/build/useAudioRecorder.js +20 -1
  47. package/build/useAudioRecorder.js.map +1 -1
  48. package/build/utils/BlobFix.d.ts.map +1 -1
  49. package/build/utils/BlobFix.js +2 -2
  50. package/build/utils/BlobFix.js.map +1 -1
  51. package/build/utils/writeWavHeader.d.ts +3 -18
  52. package/build/utils/writeWavHeader.d.ts.map +1 -1
  53. package/build/utils/writeWavHeader.js +19 -26
  54. package/build/utils/writeWavHeader.js.map +1 -1
  55. package/build/workers/InlineFeaturesExtractor.web.d.ts +1 -1
  56. package/build/workers/InlineFeaturesExtractor.web.d.ts.map +1 -1
  57. package/build/workers/InlineFeaturesExtractor.web.js +27 -26
  58. package/build/workers/InlineFeaturesExtractor.web.js.map +1 -1
  59. package/build/workers/inlineAudioWebWorker.web.d.ts +1 -1
  60. package/build/workers/inlineAudioWebWorker.web.d.ts.map +1 -1
  61. package/build/workers/inlineAudioWebWorker.web.js +25 -1
  62. package/build/workers/inlineAudioWebWorker.web.js.map +1 -1
  63. package/ios/AudioDeviceManager.swift +654 -0
  64. package/ios/AudioStreamManager.swift +964 -760
  65. package/ios/ExpoAudioStreamModule.swift +174 -19
  66. package/ios/Features.swift +1 -1
  67. package/ios/ISSUE_IOS.md +45 -0
  68. package/ios/Logger.swift +13 -1
  69. package/ios/RecordingSettings.swift +12 -0
  70. package/package.json +2 -2
  71. package/src/AudioAnalysis/AudioAnalysis.types.ts +2 -2
  72. package/src/AudioDeviceManager.ts +571 -0
  73. package/src/AudioRecorder.provider.tsx +3 -0
  74. package/src/ExpoAudioStream.types.ts +113 -1
  75. package/src/ExpoAudioStream.web.ts +609 -69
  76. package/src/ExpoAudioStreamModule.ts +23 -0
  77. package/src/WebRecorder.web.ts +482 -92
  78. package/src/hooks/useAudioDevices.ts +180 -0
  79. package/src/index.ts +6 -0
  80. package/src/types/crc-32.d.ts +6 -6
  81. package/src/useAudioRecorder.tsx +27 -1
  82. package/src/utils/BlobFix.ts +6 -4
  83. package/src/utils/writeWavHeader.ts +26 -25
  84. package/src/workers/InlineFeaturesExtractor.web.tsx +27 -26
  85. package/src/workers/inlineAudioWebWorker.web.tsx +25 -1
@@ -0,0 +1,65 @@
1
+ package net.siteed.audiostream
2
+
3
+ import android.util.Log
4
+
5
+ /**
6
+ * Utility class for standardized logging across the ExpoAudioStream library.
7
+ * Provides consistent logging format and tags for easier filtering in logcat.
8
+ */
9
+ object LogUtils {
10
+ // Format: [ExpoAudioStream:ClassName]
11
+ private const val TAG_PREFIX = "ExpoAudioStream"
12
+
13
+ /**
14
+ * Logs a debug message with a consistent format.
15
+ *
16
+ * @param className The name of the class generating the log
17
+ * @param message The message to log
18
+ */
19
+ fun d(className: String, message: String) {
20
+ Log.d("$TAG_PREFIX:$className", message)
21
+ }
22
+
23
+ /**
24
+ * Logs an error message with a consistent format.
25
+ *
26
+ * @param className The name of the class generating the log
27
+ * @param message The message to log
28
+ * @param throwable Optional throwable to include in the log
29
+ */
30
+ fun e(className: String, message: String, throwable: Throwable? = null) {
31
+ Log.e("$TAG_PREFIX:$className", message, throwable)
32
+ }
33
+
34
+ /**
35
+ * Logs a warning message with a consistent format.
36
+ *
37
+ * @param className The name of the class generating the log
38
+ * @param message The message to log
39
+ * @param throwable Optional throwable to include in the log
40
+ */
41
+ fun w(className: String, message: String, throwable: Throwable? = null) {
42
+ Log.w("$TAG_PREFIX:$className", message, throwable)
43
+ }
44
+
45
+ /**
46
+ * Logs an info message with a consistent format.
47
+ *
48
+ * @param className The name of the class generating the log
49
+ * @param message The message to log
50
+ */
51
+ fun i(className: String, message: String) {
52
+ Log.i("$TAG_PREFIX:$className", message)
53
+ }
54
+
55
+ /**
56
+ * Creates a formatted tag for direct use with Android Log methods.
57
+ * Use this if you need to use the Android Log methods directly.
58
+ *
59
+ * @param className The name of the class generating the log
60
+ * @return A formatted tag string
61
+ */
62
+ fun tag(className: String): String {
63
+ return "$TAG_PREFIX:$className"
64
+ }
65
+ }
@@ -23,6 +23,8 @@ data class RecordingConfig(
23
23
  val autoResumeAfterInterruption: Boolean = false,
24
24
  val outputDirectory: String? = null,
25
25
  val filename: String? = null,
26
+ val deviceId: String? = null,
27
+ val deviceDisconnectionBehavior: String? = null,
26
28
  ) {
27
29
  companion object {
28
30
  fun fromMap(options: Map<String, Any?>?): Result<Pair<RecordingConfig, AudioFormatInfo>> {
@@ -82,6 +84,10 @@ data class RecordingConfig(
82
84
  }
83
85
  }
84
86
 
87
+ // Get device-related settings
88
+ val deviceId = options["deviceId"] as? String
89
+ val deviceDisconnectionBehavior = options["deviceDisconnectionBehavior"] as? String
90
+
85
91
  // Initialize the recording configuration with cleaned directory path
86
92
  val tempRecordingConfig = RecordingConfig(
87
93
  sampleRate = options.getNumberOrDefault("sampleRate", Constants.DEFAULT_SAMPLE_RATE),
@@ -105,7 +111,9 @@ data class RecordingConfig(
105
111
  .trim('/')
106
112
  .replace("//", "/")
107
113
  },
108
- filename = options["filename"] as? String
114
+ filename = options["filename"] as? String,
115
+ deviceId = deviceId,
116
+ deviceDisconnectionBehavior = deviceDisconnectionBehavior
109
117
  )
110
118
 
111
119
  // Validate sample rate and channels
@@ -1 +1 @@
1
- {"version":3,"file":"AudioAnalysis.types.js","sourceRoot":"","sources":["../../src/AudioAnalysis/AudioAnalysis.types.ts"],"names":[],"mappings":"AAAA,sEAAsE","sourcesContent":["// packages/expo-audio-stream/src/AudioAnalysis/AudioAnalysis.types.ts\n\nimport { BitDepth, ConsoleLike } from '../ExpoAudioStream.types'\n\n/**\n * Represents the configuration for decoding audio data.\n */\nexport interface DecodingConfig {\n /** Target sample rate for decoded audio (Android and Web) */\n targetSampleRate?: number\n /** Target number of channels (Android and Web) */\n targetChannels?: number\n /** Target bit depth (Android and Web) */\n targetBitDepth?: BitDepth\n /** Whether to normalize audio levels (Android and Web) */\n normalizeAudio?: boolean\n}\n\n/**\n * Represents speech-related features extracted from audio.\n */\nexport interface SpeechFeatures {\n isActive: boolean // Whether speech is detected in this segment\n speakerId?: number // Optional speaker identification\n // Could add more speech-related features here like:\n // confidence: number\n // language?: string\n // sentiment?: number\n // etc.\n}\n\n/**\n * Represents various audio features extracted from an audio signal.\n */\nexport interface AudioFeatures {\n energy?: number // The infinite integral of the squared signal, representing the overall energy of the audio.\n mfcc?: number[] // Mel-frequency cepstral coefficients, describing the short-term power spectrum of a sound.\n rms?: number // Root mean square value, indicating the amplitude of the audio signal.\n minAmplitude?: number // Minimum amplitude value in the audio signal.\n maxAmplitude?: number // Maximum amplitude value in the audio signal.\n zcr?: number // Zero-crossing rate, indicating the rate at which the signal changes sign.\n spectralCentroid?: number // The center of mass of the spectrum, indicating the brightness of the sound.\n spectralFlatness?: number // Measure of the flatness of the spectrum, indicating how noise-like the signal is.\n spectralRolloff?: number // The frequency below which a specified percentage (usually 85%) of the total spectral energy lies.\n spectralBandwidth?: number // The width of the spectrum, indicating the range of frequencies present.\n chromagram?: number[] // Chromagram, representing the 12 different pitch classes of the audio.\n tempo?: number // Estimated tempo of the audio signal, measured in beats per minute (BPM).\n hnr?: number // Harmonics-to-noise ratio, indicating the proportion of harmonics to noise in the audio signal.\n melSpectrogram?: number[] // Mel-scaled spectrogram representation of the audio.\n spectralContrast?: number[] // Spectral contrast features representing the difference between peaks and valleys.\n tonnetz?: number[] // Tonal network features representing harmonic relationships.\n pitch?: number // Pitch of the audio signal, measured in Hertz (Hz).\n crc32?: number // crc32 checksum of the audio signal, used to verify the integrity of the audio.\n}\n\n/**\n * Options to specify which audio features to extract.\n */\nexport interface AudioFeaturesOptions {\n energy?: boolean\n mfcc?: boolean\n rms?: boolean\n zcr?: boolean\n spectralCentroid?: boolean\n spectralFlatness?: boolean\n spectralRolloff?: boolean\n spectralBandwidth?: boolean\n chromagram?: boolean\n tempo?: boolean\n hnr?: boolean\n melSpectrogram?: boolean\n spectralContrast?: boolean\n tonnetz?: boolean\n pitch?: boolean\n crc32?: boolean\n}\n\n/**\n * Represents a single data point in the audio analysis.\n */\nexport interface DataPoint {\n id: number\n amplitude: number // Peak amplitude for the segment\n rms: number // Root mean square value\n dB: number // dBFS (decibels relative to full scale) computed from RMS value\n silent: boolean // Always computed\n features?: AudioFeatures\n speech?: SpeechFeatures\n startTime?: number\n endTime?: number\n // start / end position in bytes\n startPosition?: number\n endPosition?: number\n // number of audio samples for this point (samples size depends on bit depth)\n samples?: number\n}\n\n/**\n * Represents the complete data from the audio analysis.\n */\nexport interface AudioAnalysis {\n segmentDurationMs: number // Duration of each segment in milliseconds\n durationMs: number // Duration of the audio in milliseconds\n bitDepth: number // Bit depth of the audio\n samples: number // Size of the audio in bytes\n numberOfChannels: number // Number of audio channels\n sampleRate: number // Sample rate of the audio\n dataPoints: DataPoint[] // Array of data points from the analysis.\n amplitudeRange: {\n min: number\n max: number\n }\n rmsRange: {\n min: number\n max: number\n }\n // TODO: speaker changes into a broader speech analysis section\n speechAnalysis?: {\n speakerChanges: {\n timestamp: number\n speakerId: number\n }[]\n // Could add more speech analysis data here like:\n // dominantSpeaker?: number\n // totalSpeechDuration?: number\n // speakerStats?: { [speakerId: number]: { duration: number, segments: number } }\n }\n}\n\n/**\n * Options for specifying a time range within an audio file.\n */\nexport interface AudioRangeOptions {\n /** Start time in milliseconds */\n startTimeMs?: number\n /** End time in milliseconds */\n endTimeMs?: number\n}\n\n/**\n * Options for generating a quick preview of audio waveform.\n * This is optimized for UI rendering with a specified number of points.\n */\nexport interface PreviewOptions extends AudioRangeOptions {\n /** URI of the audio file to analyze */\n fileUri: string\n /**\n * Total number of points to generate for the preview.\n * @default 100\n */\n numberOfPoints?: number\n /**\n * Optional logger for debugging.\n */\n logger?: ConsoleLike\n /**\n * Optional configuration for decoding the audio file.\n * Defaults to:\n * - targetSampleRate: undefined (keep original)\n * - targetChannels: undefined (keep original)\n * - targetBitDepth: 16\n * - normalizeAudio: false\n */\n decodingOptions?: DecodingConfig\n}\n\n/**\n * Options for mel-spectrogram extraction\n * \n * @experimental This feature is experimental and currently only available on Android.\n * The API may change in future versions.\n */\nexport interface ExtractMelSpectrogramOptions {\n fileUri?: string // Path to audio file\n arrayBuffer?: ArrayBuffer // Raw audio buffer\n windowSizeMs: number // Window size in ms (e.g., 25)\n hopLengthMs: number // Hop length in ms (e.g., 10)\n nMels: number // Number of mel filters (e.g., 60)\n fMin?: number // Min frequency (default: 0)\n fMax?: number // Max frequency (default: sampleRate / 2)\n windowType?: 'hann' | 'hamming' // Window function (default: 'hann')\n normalize?: boolean // Mean normalization (default: false)\n logScale?: boolean // Log scaling of mel energies (default: true)\n decodingOptions?: DecodingConfig // Audio decoding settings\n startTimeMs?: number // Optional start time\n endTimeMs?: number // Optional end time\n logger?: ConsoleLike\n}\n\n/**\n * Return type for mel spectrogram extraction\n * \n * @experimental This feature is experimental and currently only available on Android.\n * The API may change in future versions.\n */\nexport interface MelSpectrogram {\n spectrogram: number[][] // 2D array [time][mel]\n sampleRate: number // Audio sample rate\n nMels: number // Number of mel filters\n timeSteps: number // Number of time frames\n durationMs: number // Audio duration in ms\n}\n"]}
1
+ {"version":3,"file":"AudioAnalysis.types.js","sourceRoot":"","sources":["../../src/AudioAnalysis/AudioAnalysis.types.ts"],"names":[],"mappings":"AAAA,sEAAsE","sourcesContent":["// packages/expo-audio-stream/src/AudioAnalysis/AudioAnalysis.types.ts\n\nimport { BitDepth, ConsoleLike } from '../ExpoAudioStream.types'\n\n/**\n * Represents the configuration for decoding audio data.\n */\nexport interface DecodingConfig {\n /** Target sample rate for decoded audio (Android and Web) */\n targetSampleRate?: number\n /** Target number of channels (Android and Web) */\n targetChannels?: number\n /** Target bit depth (Android and Web) */\n targetBitDepth?: BitDepth\n /** Whether to normalize audio levels (Android and Web) */\n normalizeAudio?: boolean\n}\n\n/**\n * Represents speech-related features extracted from audio.\n */\nexport interface SpeechFeatures {\n isActive: boolean // Whether speech is detected in this segment\n speakerId?: number // Optional speaker identification\n // Could add more speech-related features here like:\n // confidence: number\n // language?: string\n // sentiment?: number\n // etc.\n}\n\n/**\n * Represents various audio features extracted from an audio signal.\n */\nexport interface AudioFeatures {\n energy?: number // The infinite integral of the squared signal, representing the overall energy of the audio.\n mfcc?: number[] // Mel-frequency cepstral coefficients, describing the short-term power spectrum of a sound.\n rms?: number // Root mean square value, indicating the amplitude of the audio signal.\n minAmplitude?: number // Minimum amplitude value in the audio signal.\n maxAmplitude?: number // Maximum amplitude value in the audio signal.\n zcr?: number // Zero-crossing rate, indicating the rate at which the signal changes sign.\n spectralCentroid?: number // The center of mass of the spectrum, indicating the brightness of the sound.\n spectralFlatness?: number // Measure of the flatness of the spectrum, indicating how noise-like the signal is.\n spectralRolloff?: number // The frequency below which a specified percentage (usually 85%) of the total spectral energy lies.\n spectralBandwidth?: number // The width of the spectrum, indicating the range of frequencies present.\n chromagram?: number[] // Chromagram, representing the 12 different pitch classes of the audio.\n tempo?: number // Estimated tempo of the audio signal, measured in beats per minute (BPM).\n hnr?: number // Harmonics-to-noise ratio, indicating the proportion of harmonics to noise in the audio signal.\n melSpectrogram?: number[] // Mel-scaled spectrogram representation of the audio.\n spectralContrast?: number[] // Spectral contrast features representing the difference between peaks and valleys.\n tonnetz?: number[] // Tonal network features representing harmonic relationships.\n pitch?: number // Pitch of the audio signal, measured in Hertz (Hz).\n crc32?: number // crc32 checksum of the audio signal, used to verify the integrity of the audio.\n}\n\n/**\n * Options to specify which audio features to extract.\n */\nexport interface AudioFeaturesOptions {\n energy?: boolean\n mfcc?: boolean\n rms?: boolean\n zcr?: boolean\n spectralCentroid?: boolean\n spectralFlatness?: boolean\n spectralRolloff?: boolean\n spectralBandwidth?: boolean\n chromagram?: boolean\n tempo?: boolean\n hnr?: boolean\n melSpectrogram?: boolean\n spectralContrast?: boolean\n tonnetz?: boolean\n pitch?: boolean\n crc32?: boolean\n}\n\n/**\n * Represents a single data point in the audio analysis.\n */\nexport interface DataPoint {\n id: number\n amplitude: number // Peak amplitude for the segment\n rms: number // Root mean square value\n dB: number // dBFS (decibels relative to full scale) computed from RMS value\n silent: boolean // Always computed\n features?: AudioFeatures\n speech?: SpeechFeatures\n startTime?: number\n endTime?: number\n // start / end position in bytes\n startPosition?: number\n endPosition?: number\n // number of audio samples for this point (samples size depends on bit depth)\n samples?: number\n}\n\n/**\n * Represents the complete data from the audio analysis.\n */\nexport interface AudioAnalysis {\n segmentDurationMs: number // Duration of each segment in milliseconds\n durationMs: number // Duration of the audio in milliseconds\n bitDepth: number // Bit depth of the audio\n samples: number // Size of the audio in bytes\n numberOfChannels: number // Number of audio channels\n sampleRate: number // Sample rate of the audio\n dataPoints: DataPoint[] // Array of data points from the analysis.\n amplitudeRange: {\n min: number\n max: number\n }\n rmsRange: {\n min: number\n max: number\n }\n // TODO: speaker changes into a broader speech analysis section\n speechAnalysis?: {\n speakerChanges: {\n timestamp: number\n speakerId: number\n }[]\n // Could add more speech analysis data here like:\n // dominantSpeaker?: number\n // totalSpeechDuration?: number\n // speakerStats?: { [speakerId: number]: { duration: number, segments: number } }\n }\n}\n\n/**\n * Options for specifying a time range within an audio file.\n */\nexport interface AudioRangeOptions {\n /** Start time in milliseconds */\n startTimeMs?: number\n /** End time in milliseconds */\n endTimeMs?: number\n}\n\n/**\n * Options for generating a quick preview of audio waveform.\n * This is optimized for UI rendering with a specified number of points.\n */\nexport interface PreviewOptions extends AudioRangeOptions {\n /** URI of the audio file to analyze */\n fileUri: string\n /**\n * Total number of points to generate for the preview.\n * @default 100\n */\n numberOfPoints?: number\n /**\n * Optional logger for debugging.\n */\n logger?: ConsoleLike\n /**\n * Optional configuration for decoding the audio file.\n * Defaults to:\n * - targetSampleRate: undefined (keep original)\n * - targetChannels: undefined (keep original)\n * - targetBitDepth: 16\n * - normalizeAudio: false\n */\n decodingOptions?: DecodingConfig\n}\n\n/**\n * Options for mel-spectrogram extraction\n *\n * @experimental This feature is experimental and currently only available on Android.\n * The API may change in future versions.\n */\nexport interface ExtractMelSpectrogramOptions {\n fileUri?: string // Path to audio file\n arrayBuffer?: ArrayBuffer // Raw audio buffer\n windowSizeMs: number // Window size in ms (e.g., 25)\n hopLengthMs: number // Hop length in ms (e.g., 10)\n nMels: number // Number of mel filters (e.g., 60)\n fMin?: number // Min frequency (default: 0)\n fMax?: number // Max frequency (default: sampleRate / 2)\n windowType?: 'hann' | 'hamming' // Window function (default: 'hann')\n normalize?: boolean // Mean normalization (default: false)\n logScale?: boolean // Log scaling of mel energies (default: true)\n decodingOptions?: DecodingConfig // Audio decoding settings\n startTimeMs?: number // Optional start time\n endTimeMs?: number // Optional end time\n logger?: ConsoleLike\n}\n\n/**\n * Return type for mel spectrogram extraction\n *\n * @experimental This feature is experimental and currently only available on Android.\n * The API may change in future versions.\n */\nexport interface MelSpectrogram {\n spectrogram: number[][] // 2D array [time][mel]\n sampleRate: number // Audio sample rate\n nMels: number // Number of mel filters\n timeSteps: number // Number of time frames\n durationMs: number // Audio duration in ms\n}\n"]}
@@ -0,0 +1,107 @@
1
+ import { AudioDevice, DeviceDisconnectionBehavior, ConsoleLike } from './ExpoAudioStream.types';
2
+ /**
3
+ * Class that provides a cross-platform API for managing audio input devices
4
+ */
5
+ export declare class AudioDeviceManager {
6
+ private eventEmitter;
7
+ private currentDeviceId;
8
+ private availableDevices;
9
+ private deviceChangeListeners;
10
+ private deviceListeners;
11
+ private lastRefreshTime;
12
+ private refreshInProgress;
13
+ private refreshDebounceMs;
14
+ private logger?;
15
+ constructor(options?: {
16
+ logger?: ConsoleLike;
17
+ });
18
+ /**
19
+ * Initialize the device manager with a logger
20
+ * @param logger A logger instance that implements the ConsoleLike interface
21
+ * @returns The manager instance for chaining
22
+ */
23
+ initWithLogger(logger: ConsoleLike): AudioDeviceManager;
24
+ /**
25
+ * Set the logger instance
26
+ * @param logger A logger instance that implements the ConsoleLike interface
27
+ */
28
+ setLogger(logger: ConsoleLike): void;
29
+ /**
30
+ * Get all available audio input devices
31
+ * @param options Optional settings to force refresh the device list. Can include a refresh flag.
32
+ * @returns Promise resolving to an array of audio devices conforming to AudioDevice interface
33
+ */
34
+ getAvailableDevices(options?: {
35
+ refresh?: boolean;
36
+ }): Promise<AudioDevice[]>;
37
+ /**
38
+ * Get the currently selected audio input device
39
+ * @returns Promise resolving to the current device (conforming to AudioDevice) or null
40
+ */
41
+ getCurrentDevice(): Promise<AudioDevice | null>;
42
+ /**
43
+ * Select a specific audio input device for recording
44
+ * @param deviceId The ID of the device to select
45
+ * @returns Promise resolving to a boolean indicating success
46
+ */
47
+ selectDevice(deviceId: string): Promise<boolean>;
48
+ /**
49
+ * Reset to the default audio input device
50
+ * @returns Promise resolving to a boolean indicating success
51
+ */
52
+ resetToDefaultDevice(): Promise<boolean>;
53
+ /**
54
+ * Register a listener for device changes
55
+ * @param listener Function to call when devices change (receives AudioDevice[])
56
+ * @returns Function to remove the listener
57
+ */
58
+ addDeviceChangeListener(listener: (devices: AudioDevice[]) => void): () => void;
59
+ /**
60
+ * Refresh the list of available devices with debouncing and notify listeners.
61
+ * @returns Promise resolving to the updated device list (AudioDevice[])
62
+ */
63
+ refreshDevices(): Promise<AudioDevice[]>;
64
+ /**
65
+ * Get audio input devices using the Web Audio API
66
+ * @returns Promise resolving to an array of AudioDevice objects
67
+ */
68
+ private getWebAudioDevices;
69
+ /**
70
+ * Check the current microphone permission status
71
+ * @returns Permission state ('prompt', 'granted', or 'denied')
72
+ */
73
+ private checkMicrophonePermission;
74
+ /**
75
+ * Setup listener for device changes in web environment
76
+ */
77
+ private setupWebDeviceChangeListener;
78
+ /**
79
+ * Check if the current browser is Safari or iOS WebKit
80
+ */
81
+ private isSafariOrIOS;
82
+ /**
83
+ * Create enhanced device information for Safari and privacy-restricted browsers
84
+ * @param devices Array of AudioDevice objects, potentially unlabeled
85
+ * @returns Array of enhanced AudioDevice objects
86
+ */
87
+ private enhanceDevicesForSafari;
88
+ /**
89
+ * Map a Web MediaDeviceInfo to our AudioDevice format
90
+ * @param device The MediaDeviceInfo object from the browser
91
+ * @returns An object conforming to the AudioDevice interface
92
+ */
93
+ private mapWebDeviceToAudioDevice;
94
+ /**
95
+ * Try to infer the device type from its name
96
+ * @param deviceName The label of the device
97
+ * @returns A string representing the inferred device type
98
+ */
99
+ private inferDeviceType;
100
+ /**
101
+ * Notify all registered listeners about device changes.
102
+ */
103
+ private notifyListeners;
104
+ }
105
+ export declare const audioDeviceManager: AudioDeviceManager;
106
+ export { DeviceDisconnectionBehavior };
107
+ //# sourceMappingURL=AudioDeviceManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AudioDeviceManager.d.ts","sourceRoot":"","sources":["../src/AudioDeviceManager.ts"],"names":[],"mappings":"AAGA,OAAO,EACH,WAAW,EAEX,2BAA2B,EAC3B,WAAW,EACd,MAAM,yBAAyB,CAAA;AA0ChC;;GAEG;AACH,qBAAa,kBAAkB;IAC3B,OAAO,CAAC,YAAY,CAAmC;IACvD,OAAO,CAAC,eAAe,CAAsB;IAC7C,OAAO,CAAC,gBAAgB,CAAoB;IAC5C,OAAO,CAAC,qBAAqB,CAChB;IACb,OAAO,CAAC,eAAe,CAA6B;IACpD,OAAO,CAAC,eAAe,CAAY;IACnC,OAAO,CAAC,iBAAiB,CAAiB;IAC1C,OAAO,CAAC,iBAAiB,CAAc;IACvC,OAAO,CAAC,MAAM,CAAC,CAAa;gBAEhB,OAAO,CAAC,EAAE;QAAE,MAAM,CAAC,EAAE,WAAW,CAAA;KAAE;IA+C9C;;;;OAIG;IACH,cAAc,CAAC,MAAM,EAAE,WAAW,GAAG,kBAAkB;IAKvD;;;OAGG;IACH,SAAS,CAAC,MAAM,EAAE,WAAW;IAI7B;;;;OAIG;IACG,mBAAmB,CAAC,OAAO,CAAC,EAAE;QAChC,OAAO,CAAC,EAAE,OAAO,CAAA;KACpB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IA0B1B;;;OAGG;IACG,gBAAgB,IAAI,OAAO,CAAC,WAAW,GAAG,IAAI,CAAC;IA6BrD;;;;OAIG;IACG,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAgCtD;;;OAGG;IACG,oBAAoB,IAAI,OAAO,CAAC,OAAO,CAAC;IAsB9C;;;;OAIG;IACH,uBAAuB,CACnB,QAAQ,EAAE,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,IAAI,GAC3C,MAAM,IAAI;IAcb;;;OAGG;IACG,cAAc,IAAI,OAAO,CAAC,WAAW,EAAE,CAAC;IAuC9C;;;OAGG;YACW,kBAAkB;IAsEhC;;;OAGG;YACW,yBAAyB;IAmBvC;;OAEG;IACH,OAAO,CAAC,4BAA4B;IAuBpC;;OAEG;IACH,OAAO,CAAC,aAAa;IAUrB;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;IAqC/B;;;;OAIG;IACH,OAAO,CAAC,yBAAyB;IAyBjC;;;;OAIG;IACH,OAAO,CAAC,eAAe;IAYvB;;OAEG;IACH,OAAO,CAAC,eAAe;CAc1B;AAGD,eAAO,MAAM,kBAAkB,oBAA2B,CAAA;AAE1D,OAAO,EAAE,2BAA2B,EAAE,CAAA"}