@siteed/expo-audio-studio 2.10.6 โ 2.11.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.
- package/CHANGELOG.md +9 -1
- package/android/src/androidTest/java/net/siteed/audiostream/integration/DeviceDisconnectionFallbackTest.kt +218 -0
- package/android/src/androidTest/java/net/siteed/audiostream/integration/EventEmissionIntervalTest.kt +120 -0
- package/android/src/androidTest/java/net/siteed/audiostream/integration/M4aFormatTest.kt +345 -0
- package/android/src/main/java/net/siteed/audiostream/AudioProcessor.kt +44 -32
- package/android/src/main/java/net/siteed/audiostream/AudioRecorderManager.kt +25 -4
- package/android/src/main/java/net/siteed/audiostream/RecordingConfig.kt +7 -4
- package/android/src/test/java/net/siteed/audiostream/AudioFormatTest.kt +151 -0
- package/android/src/test/java/net/siteed/audiostream/DeviceDisconnectionFallbackUnitTest.kt +140 -0
- package/build/cjs/ExpoAudioStream.types.js.map +1 -1
- package/build/esm/ExpoAudioStream.types.js.map +1 -1
- package/build/types/ExpoAudioStream.types.d.ts +9 -2
- package/build/types/ExpoAudioStream.types.d.ts.map +1 -1
- package/ios/AudioStreamManager.swift +6 -3
- package/ios/ExpoAudioStudioTests/EventEmissionIntervalTests.swift +105 -0
- package/ios/tests/README.md +41 -0
- package/ios/tests/opus_support_test_macos.swift +154 -0
- package/package.json +2 -2
- package/src/ExpoAudioStream.types.ts +9 -2
package/CHANGELOG.md
CHANGED
|
@@ -8,6 +8,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
10
|
|
|
11
|
+
## [2.11.0] - 2025-06-05
|
|
12
|
+
### Changed
|
|
13
|
+
- refactor(expo-audio-studio): remove android/build.gradle and add device disconnection fallback tests ([36fe9a9](https://github.com/deeeed/expo-audio-stream/commit/36fe9a921505e136ea50406d4b664c597293ffd8))
|
|
14
|
+
- fix(expo-audio-studio): enforce 10ms minimum interval on both platforms (#262) ([035fc07](https://github.com/deeeed/expo-audio-stream/commit/035fc076334c169a2371527bad0ca60f222d10ee))
|
|
15
|
+
- fix(expo-audio-studio): add proper MediaCodec resource cleanup in AudioProcessor ([2b069b6](https://github.com/deeeed/expo-audio-stream/commit/2b069b6ae512f97fae80df1b8cb38bb3a14538e5))
|
|
16
|
+
- feat(expo-audio-studio): add audio format enhancement specification and tests ([ace22a2](https://github.com/deeeed/expo-audio-stream/commit/ace22a22cf6c94ec58ddd4f6cb44f77dd383d6bc))
|
|
17
|
+
- feat\!: Add M4A support with preferRawStream option (#261) ([c9faeb0](https://github.com/deeeed/expo-audio-stream/commit/c9faeb01cd5dcd7407f73a0f7e6d5822adb862a4))
|
|
11
18
|
## [2.10.6] - 2025-06-04
|
|
12
19
|
### Changed
|
|
13
20
|
- fix(expo-audio-studio): prevent durationMs returning 0 on iOS (#244) (#260) ([595e5d5](https://github.com/deeeed/expo-audio-stream/commit/595e5d56991c9fa88c2fa4e39efb197916cb8b84))
|
|
@@ -282,7 +289,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
282
289
|
- Feature: Audio features extraction during recording.
|
|
283
290
|
- Feature: Consistent WAV PCM recording format across all platforms.
|
|
284
291
|
|
|
285
|
-
[unreleased]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-studio@2.
|
|
292
|
+
[unreleased]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-studio@2.11.0...HEAD
|
|
293
|
+
[2.11.0]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-studio@2.10.6...@siteed/expo-audio-studio@2.11.0
|
|
286
294
|
[2.10.6]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-studio@2.10.5...@siteed/expo-audio-studio@2.10.6
|
|
287
295
|
[2.10.5]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-studio@2.10.4...@siteed/expo-audio-studio@2.10.5
|
|
288
296
|
[2.10.4]: https://github.com/deeeed/expo-audio-stream/compare/@siteed/expo-audio-studio@2.10.3...@siteed/expo-audio-studio@2.10.4
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
package net.siteed.audiostream.integration
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
5
|
+
import androidx.test.platform.app.InstrumentationRegistry
|
|
6
|
+
import net.siteed.audiostream.OutputConfig
|
|
7
|
+
import net.siteed.audiostream.RecordingConfig
|
|
8
|
+
import org.junit.After
|
|
9
|
+
import org.junit.Assert.*
|
|
10
|
+
import org.junit.Before
|
|
11
|
+
import org.junit.Test
|
|
12
|
+
import org.junit.runner.RunWith
|
|
13
|
+
import java.io.File
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Integration test for device disconnection fallback behavior.
|
|
17
|
+
* Tests various scenarios when audio devices are disconnected during recording.
|
|
18
|
+
*/
|
|
19
|
+
@RunWith(AndroidJUnit4::class)
|
|
20
|
+
class DeviceDisconnectionFallbackTest {
|
|
21
|
+
|
|
22
|
+
private lateinit var context: Context
|
|
23
|
+
private lateinit var testDir: File
|
|
24
|
+
|
|
25
|
+
@Before
|
|
26
|
+
fun setup() {
|
|
27
|
+
context = InstrumentationRegistry.getInstrumentation().targetContext
|
|
28
|
+
|
|
29
|
+
// Create test directory
|
|
30
|
+
testDir = File(context.getExternalFilesDir(null), "fallback_test")
|
|
31
|
+
testDir.mkdirs()
|
|
32
|
+
|
|
33
|
+
// Clear any existing test files
|
|
34
|
+
testDir.listFiles()?.forEach { it.delete() }
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@After
|
|
38
|
+
fun tearDown() {
|
|
39
|
+
// Clean up test files
|
|
40
|
+
testDir.listFiles()?.forEach { it.delete() }
|
|
41
|
+
testDir.delete()
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
@Test
|
|
45
|
+
fun testDeviceDisconnectionBehavior_Fallback() {
|
|
46
|
+
println("๐งช Test: Device Disconnection with Fallback Behavior")
|
|
47
|
+
println("--------------------------------------------------")
|
|
48
|
+
|
|
49
|
+
// Create recording config with fallback behavior
|
|
50
|
+
val config = RecordingConfig(
|
|
51
|
+
sampleRate = 44100,
|
|
52
|
+
channels = 1,
|
|
53
|
+
encoding = "pcm_16bit",
|
|
54
|
+
deviceDisconnectionBehavior = "fallback",
|
|
55
|
+
output = OutputConfig(
|
|
56
|
+
primary = OutputConfig.PrimaryOutput(
|
|
57
|
+
enabled = true,
|
|
58
|
+
format = "wav"
|
|
59
|
+
)
|
|
60
|
+
),
|
|
61
|
+
outputDirectory = testDir.absolutePath,
|
|
62
|
+
filename = "fallback_test.wav"
|
|
63
|
+
)
|
|
64
|
+
|
|
65
|
+
// Verify device disconnection behavior is set
|
|
66
|
+
assertEquals("Device disconnection behavior should be fallback",
|
|
67
|
+
"fallback", config.deviceDisconnectionBehavior)
|
|
68
|
+
|
|
69
|
+
println("โ
RecordingConfig correctly configured with fallback behavior")
|
|
70
|
+
|
|
71
|
+
// Note: Actual device disconnection simulation would require running the full
|
|
72
|
+
// ExpoAudioStreamModule with device connection/disconnection events
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@Test
|
|
76
|
+
fun testDeviceDisconnectionBehavior_Pause() {
|
|
77
|
+
println("๐งช Test: Device Disconnection with Pause Behavior")
|
|
78
|
+
println("-----------------------------------------------")
|
|
79
|
+
|
|
80
|
+
val config = RecordingConfig(
|
|
81
|
+
sampleRate = 44100,
|
|
82
|
+
channels = 1,
|
|
83
|
+
encoding = "pcm_16bit",
|
|
84
|
+
deviceDisconnectionBehavior = "pause",
|
|
85
|
+
output = OutputConfig(
|
|
86
|
+
primary = OutputConfig.PrimaryOutput(
|
|
87
|
+
enabled = true,
|
|
88
|
+
format = "wav"
|
|
89
|
+
)
|
|
90
|
+
),
|
|
91
|
+
outputDirectory = testDir.absolutePath,
|
|
92
|
+
filename = "pause_test.wav"
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
// Verify device disconnection behavior is set to pause
|
|
96
|
+
assertEquals("Device disconnection behavior should be pause",
|
|
97
|
+
"pause", config.deviceDisconnectionBehavior)
|
|
98
|
+
|
|
99
|
+
println("โ
RecordingConfig correctly configured with pause behavior")
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
@Test
|
|
103
|
+
fun testDefaultDeviceDisconnectionBehavior() {
|
|
104
|
+
println("๐งช Test: Default Device Disconnection Behavior")
|
|
105
|
+
println("--------------------------------------------")
|
|
106
|
+
|
|
107
|
+
// Create config without specifying deviceDisconnectionBehavior
|
|
108
|
+
val config = RecordingConfig(
|
|
109
|
+
sampleRate = 44100,
|
|
110
|
+
channels = 1,
|
|
111
|
+
encoding = "pcm_16bit",
|
|
112
|
+
output = OutputConfig(
|
|
113
|
+
primary = OutputConfig.PrimaryOutput(
|
|
114
|
+
enabled = true,
|
|
115
|
+
format = "wav"
|
|
116
|
+
)
|
|
117
|
+
),
|
|
118
|
+
outputDirectory = testDir.absolutePath,
|
|
119
|
+
filename = "default_test.wav"
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
// Default behavior should be null (handled as pause in implementation)
|
|
123
|
+
assertNull("Default device disconnection behavior should be null",
|
|
124
|
+
config.deviceDisconnectionBehavior)
|
|
125
|
+
|
|
126
|
+
println("โ
Default device disconnection behavior is null (treated as 'pause')")
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
@Test
|
|
130
|
+
fun testInterruptionEventReasons() {
|
|
131
|
+
println("๐งช Test: Interruption Event Reasons")
|
|
132
|
+
println("----------------------------------")
|
|
133
|
+
|
|
134
|
+
// Test that the expected event reasons are valid
|
|
135
|
+
val fallbackReasons = listOf("deviceFallback", "deviceSwitchFailed")
|
|
136
|
+
val pauseReasons = listOf("deviceDisconnected")
|
|
137
|
+
|
|
138
|
+
println("๐ Expected reasons for fallback behavior:")
|
|
139
|
+
fallbackReasons.forEach { reason ->
|
|
140
|
+
println(" - $reason")
|
|
141
|
+
assertNotNull("Reason should not be null", reason)
|
|
142
|
+
assertTrue("Reason should not be empty", reason.isNotEmpty())
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
println("๐ Expected reasons for pause behavior:")
|
|
146
|
+
pauseReasons.forEach { reason ->
|
|
147
|
+
println(" - $reason")
|
|
148
|
+
assertNotNull("Reason should not be null", reason)
|
|
149
|
+
assertTrue("Reason should not be empty", reason.isNotEmpty())
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
println("โ
All interruption event reasons are valid")
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@Test
|
|
156
|
+
fun testAllDeviceDisconnectionBehaviors() {
|
|
157
|
+
println("๐งช Test: All Device Disconnection Behaviors")
|
|
158
|
+
println("-----------------------------------------")
|
|
159
|
+
|
|
160
|
+
val behaviors = listOf("fallback", "pause")
|
|
161
|
+
|
|
162
|
+
behaviors.forEach { behavior ->
|
|
163
|
+
val config = RecordingConfig(
|
|
164
|
+
sampleRate = 44100,
|
|
165
|
+
channels = 1,
|
|
166
|
+
encoding = "pcm_16bit",
|
|
167
|
+
deviceDisconnectionBehavior = behavior,
|
|
168
|
+
output = OutputConfig(
|
|
169
|
+
primary = OutputConfig.PrimaryOutput(
|
|
170
|
+
enabled = true,
|
|
171
|
+
format = "wav"
|
|
172
|
+
)
|
|
173
|
+
),
|
|
174
|
+
outputDirectory = testDir.absolutePath,
|
|
175
|
+
filename = "${behavior}_test.wav"
|
|
176
|
+
)
|
|
177
|
+
|
|
178
|
+
// Verify configuration
|
|
179
|
+
assertEquals("Device disconnection behavior should be $behavior",
|
|
180
|
+
behavior, config.deviceDisconnectionBehavior)
|
|
181
|
+
|
|
182
|
+
println("โ
Behavior '$behavior' correctly configured")
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
@Test
|
|
187
|
+
fun testDeviceDisconnectionWithCompressedOutput() {
|
|
188
|
+
println("๐งช Test: Device Disconnection with Compressed Output")
|
|
189
|
+
println("--------------------------------------------------")
|
|
190
|
+
|
|
191
|
+
// Test fallback behavior with compressed output enabled
|
|
192
|
+
val config = RecordingConfig(
|
|
193
|
+
sampleRate = 44100,
|
|
194
|
+
channels = 1,
|
|
195
|
+
encoding = "pcm_16bit",
|
|
196
|
+
deviceDisconnectionBehavior = "fallback",
|
|
197
|
+
output = OutputConfig(
|
|
198
|
+
primary = OutputConfig.PrimaryOutput(
|
|
199
|
+
enabled = false
|
|
200
|
+
),
|
|
201
|
+
compressed = OutputConfig.CompressedOutput(
|
|
202
|
+
enabled = true,
|
|
203
|
+
format = "aac",
|
|
204
|
+
bitrate = 128000
|
|
205
|
+
)
|
|
206
|
+
),
|
|
207
|
+
outputDirectory = testDir.absolutePath,
|
|
208
|
+
filename = "compressed_fallback_test"
|
|
209
|
+
)
|
|
210
|
+
|
|
211
|
+
assertEquals("Device disconnection behavior should be fallback",
|
|
212
|
+
"fallback", config.deviceDisconnectionBehavior)
|
|
213
|
+
assertTrue("Compressed output should be enabled", config.output.compressed.enabled)
|
|
214
|
+
assertFalse("Primary output should be disabled", config.output.primary.enabled)
|
|
215
|
+
|
|
216
|
+
println("โ
Fallback behavior configured with compressed-only output")
|
|
217
|
+
}
|
|
218
|
+
}
|
package/android/src/androidTest/java/net/siteed/audiostream/integration/EventEmissionIntervalTest.kt
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
package net.siteed.audiostream.integration
|
|
2
|
+
|
|
3
|
+
import android.os.Bundle
|
|
4
|
+
import android.util.Log
|
|
5
|
+
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
6
|
+
import androidx.test.platform.app.InstrumentationRegistry
|
|
7
|
+
import org.junit.Test
|
|
8
|
+
import org.junit.runner.RunWith
|
|
9
|
+
import org.junit.Assert.*
|
|
10
|
+
import java.io.File
|
|
11
|
+
import kotlin.math.abs
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Integration test to validate event emission interval enforcement.
|
|
15
|
+
*
|
|
16
|
+
* This test verifies that the configured intervals respect platform
|
|
17
|
+
* minimums to prevent excessive CPU usage.
|
|
18
|
+
*/
|
|
19
|
+
@RunWith(AndroidJUnit4::class)
|
|
20
|
+
class EventEmissionIntervalTest {
|
|
21
|
+
|
|
22
|
+
private val TAG = "EventEmissionIntervalTest"
|
|
23
|
+
private val context = InstrumentationRegistry.getInstrumentation().targetContext
|
|
24
|
+
|
|
25
|
+
@Test
|
|
26
|
+
fun testMinimumIntervalEnforcement() {
|
|
27
|
+
println("๐งช Test: Minimum Interval Enforcement")
|
|
28
|
+
println("------------------------------------")
|
|
29
|
+
|
|
30
|
+
// Test cases for different requested intervals
|
|
31
|
+
val testCases = listOf(
|
|
32
|
+
5 to 10, // 5ms should be clamped to MIN_INTERVAL (10ms)
|
|
33
|
+
10 to 10, // 10ms should remain 10ms
|
|
34
|
+
50 to 50, // 50ms should remain 50ms
|
|
35
|
+
100 to 100 // 100ms should remain 100ms
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
for ((requested, expected) in testCases) {
|
|
39
|
+
val config = Bundle().apply {
|
|
40
|
+
putInt("sampleRate", 48000)
|
|
41
|
+
putInt("channels", 1)
|
|
42
|
+
putLong("interval", requested.toLong())
|
|
43
|
+
putLong("intervalAnalysis", requested.toLong())
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
// Parse the config to validate interval enforcement
|
|
47
|
+
val configMap = bundleToMap(config)
|
|
48
|
+
val result = net.siteed.audiostream.RecordingConfig.fromMap(configMap)
|
|
49
|
+
|
|
50
|
+
assertTrue("Config parsing should succeed", result.isSuccess)
|
|
51
|
+
val (recordingConfig, _) = result.getOrNull()!!
|
|
52
|
+
|
|
53
|
+
println("Requested interval: ${requested}ms")
|
|
54
|
+
println("Actual interval: ${recordingConfig.interval}ms")
|
|
55
|
+
println("Expected interval: ${expected}ms")
|
|
56
|
+
|
|
57
|
+
assertEquals(
|
|
58
|
+
"Interval should be clamped to minimum if below MIN_INTERVAL",
|
|
59
|
+
expected.toLong(),
|
|
60
|
+
recordingConfig.interval
|
|
61
|
+
)
|
|
62
|
+
|
|
63
|
+
assertEquals(
|
|
64
|
+
"Analysis interval should be clamped to minimum if below MIN_INTERVAL",
|
|
65
|
+
expected.toLong(),
|
|
66
|
+
recordingConfig.intervalAnalysis
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
println("โ Passed\n")
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
@Test
|
|
74
|
+
fun testIntervalConsistencyAcrossPlatforms() {
|
|
75
|
+
println("๐งช Test: Platform Consistency Check")
|
|
76
|
+
println("----------------------------------")
|
|
77
|
+
|
|
78
|
+
// Document the expected behavior across platforms
|
|
79
|
+
println("Expected behavior after fix:")
|
|
80
|
+
println("- iOS: Minimum interval = 10ms")
|
|
81
|
+
println("- Android: Minimum interval = 10ms (enforced)")
|
|
82
|
+
println("")
|
|
83
|
+
|
|
84
|
+
// Verify Android enforces the minimum
|
|
85
|
+
val intervals = listOf(1, 5, 10, 50, 100)
|
|
86
|
+
for (interval in intervals) {
|
|
87
|
+
val config = Bundle().apply {
|
|
88
|
+
putLong("interval", interval.toLong())
|
|
89
|
+
putLong("intervalAnalysis", interval.toLong())
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
val configMap = bundleToMap(config)
|
|
93
|
+
val result = net.siteed.audiostream.RecordingConfig.fromMap(configMap)
|
|
94
|
+
val (recordingConfig, _) = result.getOrNull()!!
|
|
95
|
+
|
|
96
|
+
val expectedInterval = maxOf(10, interval).toLong()
|
|
97
|
+
assertEquals(
|
|
98
|
+
"Android should enforce MIN_INTERVAL of 10ms",
|
|
99
|
+
expectedInterval,
|
|
100
|
+
recordingConfig.interval
|
|
101
|
+
)
|
|
102
|
+
|
|
103
|
+
println("โ Interval ${interval}ms -> ${recordingConfig.interval}ms")
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Helper to convert Bundle to Map for RecordingConfig
|
|
109
|
+
*/
|
|
110
|
+
private fun bundleToMap(bundle: Bundle): Map<String, Any?> {
|
|
111
|
+
val map = mutableMapOf<String, Any?>()
|
|
112
|
+
for (key in bundle.keySet()) {
|
|
113
|
+
when (val value = bundle.get(key)) {
|
|
114
|
+
is Bundle -> map[key] = bundleToMap(value)
|
|
115
|
+
else -> map[key] = value
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
return map
|
|
119
|
+
}
|
|
120
|
+
}
|