@mentra/bluetooth-sdk 3.4.0-dev.999 → 3.4.1-beta.1409
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/MIGRATION.md +16 -7
- package/README.md +41 -14
- package/android/build.gradle +60 -51
- package/android/gradle.properties +3 -0
- package/android/settings.gradle +47 -3
- package/android/src/main/assets/nimo/nimo-firmware-0.1.1.1-537cf1.bin +0 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BesCrashReportWaiters.kt +68 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkDefaults.kt +5 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +77 -6
- package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +41 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +131 -122
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedChangelogCatalog.kt +3 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +6 -6
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +31 -10
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraLocalNetworkModule.kt +57 -196
- package/android/src/main/java/com/mentra/bluetoothsdk/OtaManifest.kt +1 -16
- package/android/src/main/java/com/mentra/bluetoothsdk/debug/BleTraceLogger.kt +10 -1
- package/android/src/main/java/com/mentra/bluetoothsdk/events/BluetoothEvents.kt +16 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/Ipv4Prefix.kt +51 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/NetworkFacts.kt +81 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkError.kt +108 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkReadiness.kt +103 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkRequestSpec.kt +44 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkState.kt +117 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/ScopedSoftApNetwork.kt +598 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/hotspot/SoftApTrace.kt +143 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/otaserver/MentraOtaServerModule.kt +0 -7
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioConnectionTracker.kt +15 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +308 -60
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicy.kt +14 -5
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Nimo.kt +210 -325
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinator.kt +0 -35
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSession.kt +2 -10
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoFirmwareUpdater.kt +213 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoOtaProtocol.kt +112 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +6 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/streaming/StreamModels.kt +17 -6
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/BoundedAudioQueue.kt +92 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/OnDeviceRecognizerHost.kt +169 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/STTTools.kt +74 -115
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SherpaOnnxTranscriber.kt +348 -357
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SpeechActivityDetector.kt +211 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SpeechActivityEngine.kt +137 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SttTextFormatter.kt +52 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/WakeWordDetector.kt +235 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/AvifExifStripper.java +2 -2
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/BlePhotoUploadService.java +3 -3
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNaming.java +11 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/AudioRouteWatcher.kt +120 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PcmStreamPlayer.kt +181 -16
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PcmUrlPlayback.kt +177 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/BesCrashReportWaitersTest.kt +112 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/StreamRequestCaptureAudioTest.kt +23 -4
- package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/Ipv4PrefixTest.kt +59 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/NetworkFactsTest.kt +59 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/ScopedLocalNetworkPermissionTest.kt +35 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkErrorTest.kt +85 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkLifecycleTest.kt +164 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkReadinessTest.kt +141 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/ScopedNetworkRequestSpecTest.kt +56 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/SoftApTraceTest.kt +97 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/hotspot/UnavailableRetryTest.kt +47 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/ClassicAudioConnectionTrackerTest.kt +26 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveGlassesReadyBurstTest.kt +141 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveIncidentDispatchTest.kt +183 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveOwnerLossPolicyTest.kt +9 -3
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveRgbLedResponseTest.kt +76 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinatorTest.kt +1 -56
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSessionTest.kt +0 -22
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoFirmwareTargetTest.kt +15 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoFirmwareUpdaterTest.kt +76 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoOtaProtocolTest.kt +77 -0
- package/android/src/test/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNamingTest.kt +23 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoReadinessDriverTest.kt +31 -1
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/BoundedAudioQueueTest.kt +81 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/OnDeviceRecognizerHostTest.kt +216 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/STTToolsExtractionTest.kt +108 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SpeechActivityDetectorTest.kt +126 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SpeechActivityEngineTest.kt +245 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SttTextFormatterTest.kt +67 -0
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/utils/audio/PcmUrlPlaybackTest.kt +76 -0
- package/build/BluetoothSdk.types.d.ts +103 -5
- package/build/BluetoothSdk.types.d.ts.map +1 -1
- package/build/BluetoothSdk.types.js.map +1 -1
- package/build/_private/BluetoothSdkModule.d.ts +42 -8
- package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
- package/build/_private/BluetoothSdkModule.js +1 -0
- package/build/_private/BluetoothSdkModule.js.map +1 -1
- package/build/_private/MentraLocalNetworkModule.d.ts +1 -1
- package/build/_private/MentraLocalNetworkModule.d.ts.map +1 -1
- package/build/_private/MentraLocalNetworkModule.js.map +1 -1
- package/build/generated/changelogCatalog.d.ts +5 -2
- package/build/generated/changelogCatalog.d.ts.map +1 -1
- package/build/generated/changelogCatalog.js +6 -2
- package/build/generated/changelogCatalog.js.map +1 -1
- package/build/generated/releaseMetadata.js +6 -6
- package/build/generated/releaseMetadata.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +7 -1
- package/build/index.js.map +1 -1
- package/build/ota-server/MentraOtaServerModule.d.ts +0 -2
- package/build/ota-server/MentraOtaServerModule.d.ts.map +1 -1
- package/build/ota-server/MentraOtaServerModule.js.map +1 -1
- package/build/ota-server/MentraOtaServerModule.web.d.ts +0 -1
- package/build/ota-server/MentraOtaServerModule.web.d.ts.map +1 -1
- package/build/ota-server/MentraOtaServerModule.web.js +0 -3
- package/build/ota-server/MentraOtaServerModule.web.js.map +1 -1
- package/build/ota-transport/index.d.ts +3 -3
- package/build/ota-transport/index.d.ts.map +1 -1
- package/build/ota-transport/index.js +4 -4
- package/build/ota-transport/index.js.map +1 -1
- package/build/react/useGlassesConnection.d.ts +1 -1
- package/build/react/useGlassesConnection.d.ts.map +1 -1
- package/build/react/useGlassesConnection.js +3 -3
- package/build/react/useGlassesConnection.js.map +1 -1
- package/build/react/useMentraBluetooth.d.ts +1 -1
- package/build/react/useMentraBluetooth.d.ts.map +1 -1
- package/build/react/useMentraBluetooth.js +1 -1
- package/build/react/useMentraBluetooth.js.map +1 -1
- package/ios/BluetoothSdkModule.swift +73 -22
- package/ios/LocalIPv4.swift +0 -61
- package/ios/MentraBluetoothSDK.podspec +7 -1
- package/ios/MentraOtaServerModule.swift +0 -16
- package/ios/Packages/SherpaOnnx/SherpaOnnx.swift +23 -5
- package/ios/Resources/NimoFirmware/nimo-firmware-0.1.1.1-537cf1.bin +0 -0
- package/ios/Resources/SileroVad/silero_vad.onnx +0 -0
- package/ios/Source/BesCrashReportWaiters.swift +64 -0
- package/ios/Source/BluetoothSdkDefaults.swift +4 -4
- package/ios/Source/Bridge.swift +14 -0
- package/ios/Source/DeviceManager.swift +52 -22
- package/ios/Source/GeneratedChangelogCatalog.swift +3 -2
- package/ios/Source/GeneratedReleaseMetadata.swift +6 -6
- package/ios/Source/MentraBluetoothSDK.swift +35 -16
- package/ios/Source/OtaManifest.swift +1 -17
- package/ios/Source/audio/PcmStreamPlayer.swift +290 -57
- package/ios/Source/audio/PcmUrlPlayback.swift +231 -0
- package/ios/Source/audio/SpeechActivity.swift +277 -0
- package/ios/Source/events/BluetoothEvents.swift +41 -0
- package/ios/Source/internal/BleTraceLogger.swift +14 -1
- package/ios/Source/internal/BluetoothAvailability.swift +15 -5
- package/ios/Source/sgcs/GlassesAudioSetupPolicy.swift +5 -0
- package/ios/Source/sgcs/MentraLive.swift +207 -66
- package/ios/Source/sgcs/Nimo.swift +249 -276
- package/ios/Source/sgcs/NimoCanvasCoordinator.swift +9 -38
- package/ios/Source/sgcs/NimoCanvasSession.swift +0 -1
- package/ios/Source/sgcs/NimoFirmwareUpdater.swift +260 -0
- package/ios/Source/sgcs/NimoOtaProtocol.swift +159 -0
- package/ios/Source/sgcs/SGCManager.swift +6 -0
- package/ios/Source/streaming/StreamModels.swift +15 -6
- package/ios/Source/stt/STTTools.swift +13 -31
- package/ios/Source/stt/SherpaOnnxTranscriber.swift +204 -162
- package/ios/Source/stt/SileroSpeechActivity.swift +87 -0
- package/ios/Source/stt/WakeWordDetector.swift +145 -0
- package/ios/Source/utils/BoundedWait.swift +44 -0
- package/ios/Source/utils/DemandDrivenAudioWorker.swift +79 -0
- package/ios/Source/utils/SttModelTraits.swift +62 -0
- package/ios/Tests/BesCrashReportTests.swift +142 -0
- package/ios/Tests/DemandDrivenAudioWorkerTests.swift +171 -0
- package/ios/Tests/DeviceManagerReconnectTests.swift +0 -71
- package/ios/Tests/GlassesAudioSetupPolicyTests.swift +9 -3
- package/ios/Tests/IncidentLogDispatchTests.swift +158 -0
- package/ios/Tests/MentraLiveAudioSetupTests.swift +6 -12
- package/ios/Tests/MentraLiveCommandQueueTests.swift +35 -0
- package/ios/Tests/MentraLiveSessionReadinessTests.swift +179 -10
- package/ios/Tests/NimoCanvasTransportTests.swift +0 -89
- package/ios/Tests/NimoOtaProtocolTests.swift +78 -0
- package/ios/Tests/PcmStreamTests.swift +299 -0
- package/ios/Tests/SpeechActivityTests.swift +238 -0
- package/ios/Tests/StreamRequestTests.swift +18 -0
- package/ios/Tests/SttModelTraitsTests.swift +62 -0
- package/package.json +2 -2
- package/plugin/build/withAndroid.js +9 -11
- package/plugin/build/withKotlinVersion.d.ts +2 -0
- package/plugin/build/withKotlinVersion.js +46 -0
- package/src/BluetoothSdk.types.ts +107 -5
- package/src/_private/BluetoothSdkModule.ts +45 -8
- package/src/_private/MentraLocalNetworkModule.ts +5 -1
- package/src/generated/changelogCatalog.ts +6 -2
- package/src/generated/releaseMetadata.ts +6 -6
- package/src/index.ts +13 -1
- package/src/ota-server/MentraOtaServerModule.ts +0 -2
- package/src/ota-server/MentraOtaServerModule.web.ts +0 -4
- package/src/ota-transport/index.ts +4 -5
- package/src/react/useGlassesConnection.ts +4 -4
- package/src/react/useMentraBluetooth.ts +2 -2
- package/android/silero/LICENSE.md +0 -17
- package/android/silero/build.gradle +0 -50
- package/android/silero/proguard-rules.pro +0 -24
- package/android/silero/src/androidTest/assets/hello.wav +0 -0
- package/android/silero/src/androidTest/java/com/konovalov/vad/silero/VadSileroTest.kt +0 -79
- package/android/silero/src/main/java/com/konovalov/vad/silero/Vad.kt +0 -160
- package/android/silero/src/main/java/com/konovalov/vad/silero/VadSilero.kt +0 -449
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/FrameSize.kt +0 -15
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/Mode.kt +0 -14
- package/android/silero/src/main/java/com/konovalov/vad/silero/config/SampleRate.kt +0 -12
- package/android/silero/src/main/java/com/konovalov/vad/silero/utils/AudioUtils.kt +0 -47
- package/android/silero/src/main/java/com/konovalov/vad/silero/utils/TensorMap.kt +0 -41
- package/android/silero/src/test/java/com/konovalov/vad/silero/utils/AudioUtilsTest.kt +0 -44
- package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +0 -368
- package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocol.kt +0 -156
- package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoResourceDiagnostics.kt +0 -274
- package/android/src/main/java/com/mentra/bluetoothsdk/ScopedNetworkReadiness.kt +0 -17
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/VadGateSpeechPolicy.kt +0 -229
- package/android/src/release/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +0 -20
- package/android/src/release/java/com/mentra/bluetoothsdk/sgcs/NimoResourceDiagnostics.kt +0 -16
- package/android/src/test/java/com/mentra/bluetoothsdk/ScopedNetworkReadinessTest.kt +0 -39
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnosticsTest.kt +0 -287
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocolTest.kt +0 -127
- package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoLifecycleTest.kt +0 -851
- package/ios/Source/sgcs/NimoMacResourceTransport.swift +0 -217
- package/ios/Source/sgcs/NimoResourceFixture.swift +0 -384
- package/ios/Source/sgcs/NimoResourceSession.swift +0 -406
- package/ios/Tests/NimoResourceSessionTests.swift +0 -476
- /package/android/{silero/src/main/assets/LICENSE → src/main/assets/vad/LICENSE.silero_vad} +0 -0
- /package/android/{silero/src/main/assets → src/main/assets/vad}/silero_vad.onnx +0 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
@testable import MentraBluetoothSDK
|
|
3
|
+
import XCTest
|
|
4
|
+
|
|
5
|
+
/// Stands in for Silero: speech is any frame with a loud sample, and like Silero it keeps
|
|
6
|
+
/// reporting speech until it has heard `minSilenceMs` of quiet.
|
|
7
|
+
private final class FakeSpeechClassifier: SpeechActivityClassifier {
|
|
8
|
+
let minSilenceFrames: Int
|
|
9
|
+
private(set) var frames: [[Float]] = []
|
|
10
|
+
private var quietFrames = 0
|
|
11
|
+
private var speaking = false
|
|
12
|
+
|
|
13
|
+
init(minSilenceMs: Int) {
|
|
14
|
+
minSilenceFrames = max(1, Int((Double(minSilenceMs) / 32.0).rounded(.up)))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
func isSpeech(afterAccepting frame: [Float]) -> Bool {
|
|
18
|
+
frames.append(frame)
|
|
19
|
+
if frame.contains(where: { abs($0) > 0.1 }) {
|
|
20
|
+
speaking = true
|
|
21
|
+
quietFrames = 0
|
|
22
|
+
} else if speaking {
|
|
23
|
+
quietFrames += 1
|
|
24
|
+
if quietFrames >= minSilenceFrames { speaking = false }
|
|
25
|
+
}
|
|
26
|
+
return speaking
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
private func pcm(samples: [Int16]) -> Data {
|
|
31
|
+
var data = Data(capacity: samples.count * 2)
|
|
32
|
+
for sample in samples {
|
|
33
|
+
let bits = UInt16(bitPattern: sample)
|
|
34
|
+
data.append(UInt8(bits & 0xFF))
|
|
35
|
+
data.append(UInt8(bits >> 8))
|
|
36
|
+
}
|
|
37
|
+
return data
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
private func loud(_ count: Int) -> Data {
|
|
41
|
+
pcm(samples: (0 ..< count).map { $0.isMultiple(of: 2) ? 16000 : -16000 })
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
private func quiet(_ count: Int) -> Data {
|
|
45
|
+
pcm(samples: [Int16](repeating: 0, count: count))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
final class SpeechActivityTrackerTests: XCTestCase {
|
|
49
|
+
func testChunksOfAnySizeAreFullyAnalyzedInWholeFrames() {
|
|
50
|
+
let classifier = FakeSpeechClassifier(minSilenceMs: 300)
|
|
51
|
+
let tracker = SpeechActivityTracker(classifier: classifier)
|
|
52
|
+
let samples = (0 ..< 5000).map { Int16(truncatingIfNeeded: $0 * 7 - 9000) }
|
|
53
|
+
let bytes = pcm(samples: samples)
|
|
54
|
+
// Odd byte counts split samples across chunks; none of the sizes divide 512 samples.
|
|
55
|
+
let chunkSizes = [1, 3, 7, 160, 333, 1023, 2, 999, 1, 640]
|
|
56
|
+
var offset = 0
|
|
57
|
+
var index = 0
|
|
58
|
+
while offset < bytes.count {
|
|
59
|
+
let size = min(chunkSizes[index % chunkSizes.count], bytes.count - offset)
|
|
60
|
+
_ = tracker.accept(bytes.subdata(in: offset ..< offset + size), nowMs: 0)
|
|
61
|
+
offset += size
|
|
62
|
+
index += 1
|
|
63
|
+
}
|
|
64
|
+
let wholeFrames = samples.count / SpeechActivityTracker.frameSamples
|
|
65
|
+
XCTAssertEqual(classifier.frames.count, wholeFrames)
|
|
66
|
+
XCTAssertTrue(classifier.frames.allSatisfy { $0.count == SpeechActivityTracker.frameSamples })
|
|
67
|
+
XCTAssertEqual(tracker.analyzedSamples, Int64(wholeFrames * SpeechActivityTracker.frameSamples))
|
|
68
|
+
let analyzed = classifier.frames.flatMap { $0 }
|
|
69
|
+
let expected = samples.prefix(analyzed.count).map { Float($0) / 32768 }
|
|
70
|
+
XCTAssertEqual(analyzed, Array(expected))
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
func testReportsEachTransitionOnce() {
|
|
74
|
+
let classifier = FakeSpeechClassifier(minSilenceMs: 300)
|
|
75
|
+
let tracker = SpeechActivityTracker(classifier: classifier, minSilenceMs: 300)
|
|
76
|
+
var transitions = tracker.accept(loud(512 * 10), nowMs: 0)
|
|
77
|
+
transitions += tracker.accept(loud(512 * 10), nowMs: 320)
|
|
78
|
+
XCTAssertEqual(transitions, [SpeechActivityTransition(speaking: true, silentForMs: 0)])
|
|
79
|
+
transitions = tracker.accept(quiet(512 * 30), nowMs: 1300)
|
|
80
|
+
XCTAssertEqual(transitions, [SpeechActivityTransition(speaking: false, silentForMs: 300)])
|
|
81
|
+
XCTAssertFalse(tracker.speaking)
|
|
82
|
+
XCTAssertEqual(tracker.accept(quiet(512 * 30), nowMs: 2300), [])
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
func testSpeechToSilenceIsReportedWithinTheConfiguredGap() {
|
|
86
|
+
let minSilenceMs = 300
|
|
87
|
+
let classifier = FakeSpeechClassifier(minSilenceMs: minSilenceMs)
|
|
88
|
+
let tracker = SpeechActivityTracker(classifier: classifier, minSilenceMs: minSilenceMs)
|
|
89
|
+
_ = tracker.accept(loud(512 * 4), nowMs: 0)
|
|
90
|
+
XCTAssertTrue(tracker.speaking)
|
|
91
|
+
// Feed real quiet audio one frame at a time and note when silence is reported.
|
|
92
|
+
var quietMs = 0
|
|
93
|
+
var reported: SpeechActivityTransition?
|
|
94
|
+
for _ in 0 ..< 100 {
|
|
95
|
+
let transitions = tracker.accept(quiet(512), nowMs: Int64(quietMs))
|
|
96
|
+
quietMs += 32
|
|
97
|
+
if let transition = transitions.first {
|
|
98
|
+
reported = transition
|
|
99
|
+
break
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
XCTAssertEqual(reported, SpeechActivityTransition(speaking: false, silentForMs: minSilenceMs))
|
|
103
|
+
XCTAssertGreaterThanOrEqual(quietMs, minSilenceMs)
|
|
104
|
+
XCTAssertLessThanOrEqual(quietMs, minSilenceMs + 32)
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
func testAudioThatStopsMidSessionIsFilledWithSilenceInRealTime() throws {
|
|
108
|
+
let minSilenceMs = 300
|
|
109
|
+
let classifier = FakeSpeechClassifier(minSilenceMs: minSilenceMs)
|
|
110
|
+
let tracker = SpeechActivityTracker(classifier: classifier, minSilenceMs: minSilenceMs)
|
|
111
|
+
// 0.5 s of speech plus a partial frame, then the loudness gate stops sending audio.
|
|
112
|
+
XCTAssertEqual(tracker.accept(loud(8000 + 100), nowMs: 1000), [SpeechActivityTransition(speaking: true, silentForMs: 0)])
|
|
113
|
+
XCTAssertTrue(tracker.needsGapFill)
|
|
114
|
+
XCTAssertEqual(tracker.nextGapFillDueMs(nowMs: 1000), 1100)
|
|
115
|
+
|
|
116
|
+
// Under the 100 ms gap threshold: nothing is filled.
|
|
117
|
+
XCTAssertEqual(tracker.fillGap(nowMs: 1099), [])
|
|
118
|
+
XCTAssertEqual(tracker.filledSamples, 0)
|
|
119
|
+
|
|
120
|
+
// From then on silence is fed for the elapsed time, never ahead of the clock.
|
|
121
|
+
var now: Int64 = 1100
|
|
122
|
+
var silentAt: Int64?
|
|
123
|
+
while now < 3000, silentAt == nil {
|
|
124
|
+
let transitions = tracker.fillGap(nowMs: now)
|
|
125
|
+
XCTAssertLessThanOrEqual(tracker.filledSamples, (now - 1000) * 16)
|
|
126
|
+
if transitions == [SpeechActivityTransition(speaking: false, silentForMs: minSilenceMs)] {
|
|
127
|
+
silentAt = now
|
|
128
|
+
} else {
|
|
129
|
+
XCTAssertEqual(transitions, [])
|
|
130
|
+
}
|
|
131
|
+
now += 32
|
|
132
|
+
}
|
|
133
|
+
let reportedAt = try XCTUnwrap(silentAt)
|
|
134
|
+
// Silence is reported once `minSilenceMs` of gap has been fed, give or take a frame.
|
|
135
|
+
XCTAssertGreaterThanOrEqual(reportedAt - 1000, Int64(minSilenceMs))
|
|
136
|
+
XCTAssertLessThanOrEqual(reportedAt - 1000, Int64(minSilenceMs + 64))
|
|
137
|
+
XCTAssertTrue(classifier.frames.allSatisfy { $0.count == SpeechActivityTracker.frameSamples })
|
|
138
|
+
|
|
139
|
+
// Once silent, a silent detector needs no more filling.
|
|
140
|
+
XCTAssertFalse(tracker.needsGapFill)
|
|
141
|
+
XCTAssertNil(tracker.nextGapFillDueMs(nowMs: now))
|
|
142
|
+
let filled = tracker.filledSamples
|
|
143
|
+
XCTAssertEqual(tracker.fillGap(nowMs: now + 5000), [])
|
|
144
|
+
XCTAssertEqual(tracker.filledSamples, filled)
|
|
145
|
+
|
|
146
|
+
// Audio resuming is analyzed normally again.
|
|
147
|
+
XCTAssertEqual(tracker.accept(loud(1024), nowMs: now + 6000), [SpeechActivityTransition(speaking: true, silentForMs: 0)])
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
func testNoAudioYetMeansNoGapFill() {
|
|
151
|
+
let tracker = SpeechActivityTracker(classifier: FakeSpeechClassifier(minSilenceMs: 300))
|
|
152
|
+
XCTAssertFalse(tracker.needsGapFill)
|
|
153
|
+
XCTAssertEqual(tracker.fillGap(nowMs: 10000), [])
|
|
154
|
+
XCTAssertEqual(tracker.analyzedSamples, 0)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
final class SpeechActivityMonitorTests: XCTestCase {
|
|
159
|
+
private final class Recorder: @unchecked Sendable {
|
|
160
|
+
private let lock = NSLock()
|
|
161
|
+
private var stored: [SpeechActivityMonitor.Event] = []
|
|
162
|
+
var events: [SpeechActivityMonitor.Event] {
|
|
163
|
+
lock.lock()
|
|
164
|
+
defer { lock.unlock() }
|
|
165
|
+
return stored
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
func append(_ event: SpeechActivityMonitor.Event) {
|
|
169
|
+
lock.lock()
|
|
170
|
+
stored.append(event)
|
|
171
|
+
lock.unlock()
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
func testEnablingLoadsTheModelAndDisablingReleasesIt() async throws {
|
|
176
|
+
weak var created: FakeSpeechClassifier?
|
|
177
|
+
var requestedSilence: [Int] = []
|
|
178
|
+
let recorder = Recorder()
|
|
179
|
+
let monitor = SpeechActivityMonitor(makeClassifier: { minSilenceMs in
|
|
180
|
+
requestedSilence.append(minSilenceMs)
|
|
181
|
+
let classifier = FakeSpeechClassifier(minSilenceMs: minSilenceMs)
|
|
182
|
+
created = classifier
|
|
183
|
+
return classifier
|
|
184
|
+
}, emit: recorder.append)
|
|
185
|
+
|
|
186
|
+
XCTAssertFalse(monitor.hasClassifier())
|
|
187
|
+
try await monitor.setEnabled(true, minSilenceMs: nil)
|
|
188
|
+
XCTAssertEqual(requestedSilence, [SpeechActivityTracker.defaultMinSilenceMs])
|
|
189
|
+
XCTAssertTrue(monitor.hasClassifier())
|
|
190
|
+
XCTAssertNotNil(created)
|
|
191
|
+
|
|
192
|
+
try await monitor.setEnabled(true, minSilenceMs: 1250)
|
|
193
|
+
XCTAssertEqual(requestedSilence, [300, 1250])
|
|
194
|
+
|
|
195
|
+
try await monitor.setEnabled(false, minSilenceMs: nil)
|
|
196
|
+
XCTAssertFalse(monitor.isEnabled)
|
|
197
|
+
XCTAssertFalse(monitor.hasClassifier())
|
|
198
|
+
XCTAssertNil(created, "Disabling must release the model")
|
|
199
|
+
|
|
200
|
+
monitor.accept(loud(4096))
|
|
201
|
+
XCTAssertFalse(monitor.hasClassifier())
|
|
202
|
+
XCTAssertTrue(recorder.events.isEmpty)
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
func testEnablingFailsWhenTheModelIsUnavailable() async {
|
|
206
|
+
let monitor = SpeechActivityMonitor(makeClassifier: { _ in nil }, emit: { _ in })
|
|
207
|
+
do {
|
|
208
|
+
try await monitor.setEnabled(true, minSilenceMs: 300)
|
|
209
|
+
XCTFail("Expected the missing model to fail enabling")
|
|
210
|
+
} catch {
|
|
211
|
+
XCTAssertEqual(error.localizedDescription, "Could not load the speech activity model")
|
|
212
|
+
}
|
|
213
|
+
XCTAssertFalse(monitor.isEnabled)
|
|
214
|
+
XCTAssertFalse(monitor.hasClassifier())
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
func testAudioThatStopsProducesASilentEventInRealTime() async throws {
|
|
218
|
+
let recorder = Recorder()
|
|
219
|
+
let silent = expectation(description: "silent event")
|
|
220
|
+
let monitor = SpeechActivityMonitor(makeClassifier: { FakeSpeechClassifier(minSilenceMs: $0) }, emit: { event in
|
|
221
|
+
recorder.append(event)
|
|
222
|
+
if !event.speaking { silent.fulfill() }
|
|
223
|
+
})
|
|
224
|
+
try await monitor.setEnabled(true, minSilenceMs: 150)
|
|
225
|
+
let started = Date()
|
|
226
|
+
monitor.accept(loud(1600))
|
|
227
|
+
// No more audio arrives, as when the glasses' loudness gate closes.
|
|
228
|
+
await fulfillment(of: [silent], timeout: 3)
|
|
229
|
+
let elapsedMs = Date().timeIntervalSince(started) * 1000
|
|
230
|
+
XCTAssertEqual(recorder.events.map(\.speaking), [true, false])
|
|
231
|
+
XCTAssertEqual(recorder.events.last?.silentForMs, 150)
|
|
232
|
+
// Gap threshold (100 ms) plus the configured silence, filled at the pace of the clock.
|
|
233
|
+
XCTAssertGreaterThanOrEqual(elapsedMs, 140)
|
|
234
|
+
XCTAssertLessThan(elapsedMs, 2000)
|
|
235
|
+
XCTAssertGreaterThan(recorder.events.last?.timestamp ?? 0, 1_600_000_000_000)
|
|
236
|
+
try await monitor.setEnabled(false, minSilenceMs: nil)
|
|
237
|
+
}
|
|
238
|
+
}
|
|
@@ -14,6 +14,24 @@ final class StreamRequestTests: XCTestCase {
|
|
|
14
14
|
XCTAssertNil(request.values["tl"])
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
+
func testWhipWithoutIceSendsTheDefaultStunServer() {
|
|
18
|
+
let request = StreamRequest(streamUrl: "https://example.com/whip", streamId: "s-1")
|
|
19
|
+
let ice = request.values["ice"] as? [String: Any]
|
|
20
|
+
XCTAssertEqual(ice?["stun"] as? String, "stun:stun.cloudflare.com:3478")
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
func testWhipKeepsHostOnlyAndNamedStunServers() {
|
|
24
|
+
let hostOnly = StreamRequest(values: ["streamUrl": "http://192.168.43.79:8080/whip", "ice": ["stun": ""]])
|
|
25
|
+
XCTAssertEqual((hostOnly.values["ice"] as? [String: Any])?["stun"] as? String, "")
|
|
26
|
+
let named = StreamRequest(values: ["streamUrl": "https://example.com/whip", "i": ["s": "stun:stun.example.com:3478"]])
|
|
27
|
+
XCTAssertEqual((named.values["ice"] as? [String: Any])?["stun"] as? String, "stun:stun.example.com:3478")
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
func testRtmpAndSrtSendNoIce() {
|
|
31
|
+
XCTAssertNil(StreamRequest(streamUrl: "rtmp://example.com/live", streamId: "s-1").values["ice"])
|
|
32
|
+
XCTAssertNil(StreamRequest(streamUrl: "srt://example.com:9000", streamId: "s-1").values["ice"])
|
|
33
|
+
}
|
|
34
|
+
|
|
17
35
|
func testInitFromValuesPreservesOmissionWhenKeyAbsent() {
|
|
18
36
|
let request = StreamRequest(values: [
|
|
19
37
|
"streamUrl": "https://example.com/whip",
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
@testable import MentraBluetoothSDK
|
|
2
|
+
import XCTest
|
|
3
|
+
|
|
4
|
+
final class SttModelTraitsTests: XCTestCase {
|
|
5
|
+
private let zipformerTokens = "<blk> 0\n<sos/eos> 1\n<unk> 2\n▁THE 3\nS 4\n▁AND 5\n'S 6\n"
|
|
6
|
+
private let krokoTokens = "<blk> 0\n▁the 1\n▁The 2\n, 3\n. 4\n▁Paris 5\n"
|
|
7
|
+
|
|
8
|
+
func testStreamingTransducersFinalizeEarlyAndUseFourThreadsWhateverTheFolder() {
|
|
9
|
+
let traits = SttModelTraits(kind: .transducer, tokensFileContents: krokoTokens)
|
|
10
|
+
XCTAssertTrue(traits.canFinalizeEarly)
|
|
11
|
+
XCTAssertEqual(traits.numThreads, 4)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
func testCtcModelsCannotFinalizeEarlyAndUseOneThread() {
|
|
15
|
+
let traits = SttModelTraits(kind: .ctc, tokensFileContents: krokoTokens)
|
|
16
|
+
XCTAssertFalse(traits.canFinalizeEarly)
|
|
17
|
+
XCTAssertEqual(traits.numThreads, 1)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
func testUppercaseOnlyVocabularyIsLowercased() {
|
|
21
|
+
let traits = SttModelTraits(kind: .transducer, tokensFileContents: zipformerTokens)
|
|
22
|
+
XCTAssertTrue(traits.uppercaseOnlyVocabulary)
|
|
23
|
+
XCTAssertEqual(traits.format("HELLO WORLD"), "hello world")
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
func testMixedCaseVocabularyKeepsModelFormatting() {
|
|
27
|
+
let traits = SttModelTraits(kind: .transducer, tokensFileContents: krokoTokens)
|
|
28
|
+
XCTAssertFalse(traits.uppercaseOnlyVocabulary)
|
|
29
|
+
XCTAssertEqual(traits.format("Hello, Paris."), "Hello, Paris.")
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
func testSpecialTokensAndCaselessScriptsAreNotUppercaseOnly() {
|
|
33
|
+
XCTAssertFalse(SttModelTraits.isUppercaseOnly(tokensFileContents: "<blk> 0\n<unk> 1\n<0x41> 2\n"))
|
|
34
|
+
XCTAssertFalse(SttModelTraits.isUppercaseOnly(tokensFileContents: "<blk> 0\n你 1\n好 2\n"))
|
|
35
|
+
XCTAssertTrue(SttModelTraits.isUppercaseOnly(tokensFileContents: "<blk> 0\n你 1\nA 2\n"))
|
|
36
|
+
XCTAssertFalse(SttModelTraits.isUppercaseOnly(tokensFileContents: ""))
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
final class BoundedWaitTests: XCTestCase {
|
|
41
|
+
func testResolvesWithTheWorkResultBeforeTheTimeout() async {
|
|
42
|
+
let value: String? = await withBoundedWait(timeout: 2, timeoutValue: nil) { resolver in
|
|
43
|
+
DispatchQueue.global().async { resolver.resolve("final text") }
|
|
44
|
+
}
|
|
45
|
+
XCTAssertEqual(value, "final text")
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
func testTimeoutResolvesWithTheTimeoutValueAndLateWorkSeesItSettled() async {
|
|
49
|
+
let late = expectation(description: "late work")
|
|
50
|
+
var settledWhenLate = false
|
|
51
|
+
let value: String? = await withBoundedWait(timeout: 0.05, timeoutValue: nil) { resolver in
|
|
52
|
+
DispatchQueue.global().asyncAfter(deadline: .now() + 0.2) {
|
|
53
|
+
settledWhenLate = resolver.isSettled
|
|
54
|
+
resolver.resolve("too late")
|
|
55
|
+
late.fulfill()
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
XCTAssertNil(value)
|
|
59
|
+
await fulfillment(of: [late], timeout: 2)
|
|
60
|
+
XCTAssertTrue(settledWhenLate)
|
|
61
|
+
}
|
|
62
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mentra/bluetooth-sdk",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.1-beta.1409",
|
|
4
4
|
"description": "SDK for communicating with smart glasses",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"react-native": "src/index.ts",
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
"registry": "https://registry.npmjs.org/"
|
|
116
116
|
},
|
|
117
117
|
"dependencies": {
|
|
118
|
-
"@mentra/cloud-protocol": "3.4.
|
|
118
|
+
"@mentra/cloud-protocol": "3.4.1-beta.1409"
|
|
119
119
|
},
|
|
120
120
|
"devDependencies": {
|
|
121
121
|
"@types/node": "^25.9.3",
|
|
@@ -8,6 +8,7 @@ const child_process_1 = require("child_process");
|
|
|
8
8
|
const path_1 = __importDefault(require("path"));
|
|
9
9
|
const config_plugins_1 = require("expo/config-plugins");
|
|
10
10
|
const analyticsProps_1 = require("./analyticsProps");
|
|
11
|
+
const withKotlinVersion_1 = require("./withKotlinVersion");
|
|
11
12
|
const META_ANALYTICS_DISABLED = "com.mentra.bluetoothsdk.analytics.disabled";
|
|
12
13
|
const META_ANALYTICS_ENVIRONMENT = "com.mentra.bluetoothsdk.analytics.environment";
|
|
13
14
|
const STALE_META_POSTHOG_API_KEY = "com.mentra.bluetoothsdk.analytics.posthog_api_key";
|
|
@@ -25,7 +26,7 @@ function toGroovyString(value) {
|
|
|
25
26
|
return JSON.stringify(value);
|
|
26
27
|
}
|
|
27
28
|
/**
|
|
28
|
-
* Modify settings.gradle to include lc3Lib
|
|
29
|
+
* Modify settings.gradle to include the lc3Lib module
|
|
29
30
|
*/
|
|
30
31
|
function withSettingsGradleModifications(config) {
|
|
31
32
|
return (0, config_plugins_1.withSettingsGradle)(config, (config) => {
|
|
@@ -53,16 +54,12 @@ function withSettingsGradleModifications(config) {
|
|
|
53
54
|
project(':lc3Lib').projectDir = new File(${bluetoothSdkRootExpression}, 'android/lc3Lib')
|
|
54
55
|
`;
|
|
55
56
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
settingsGradle += `
|
|
63
|
-
project(':silero').projectDir = new File(${bluetoothSdkRootExpression}, 'android/silero')
|
|
64
|
-
`;
|
|
65
|
-
}
|
|
57
|
+
// Earlier versions of this plugin added a `:silero` module, which no longer exists. Prebuild
|
|
58
|
+
// runs without --clean, so remove those lines from an already generated settings.gradle.
|
|
59
|
+
settingsGradle = settingsGradle
|
|
60
|
+
.split("\n")
|
|
61
|
+
.filter((line) => !line.includes("include ':silero'") && !line.includes("project(':silero')"))
|
|
62
|
+
.join("\n");
|
|
66
63
|
config.modResults.contents = settingsGradle;
|
|
67
64
|
return config;
|
|
68
65
|
});
|
|
@@ -173,6 +170,7 @@ function withAnalyticsManifestMetadata(config, props) {
|
|
|
173
170
|
});
|
|
174
171
|
}
|
|
175
172
|
const withAndroidConfiguration = (config, props) => {
|
|
173
|
+
config = (0, withKotlinVersion_1.withKotlinVersion)(config);
|
|
176
174
|
config = withSettingsGradleModifications(config);
|
|
177
175
|
config = withSherpaOnnxLocalMavenRepo(config);
|
|
178
176
|
config = withAnalyticsManifestMetadata(config, props);
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.withKotlinVersion = void 0;
|
|
4
|
+
const config_plugins_1 = require("expo/config-plugins");
|
|
5
|
+
// avif-coder 3.0.0 contains Kotlin 2.3 metadata. Match the standalone SDK
|
|
6
|
+
// compiler and @mentra/crust; Expo SDK 55 also has a KSP mapping for 2.3.0.
|
|
7
|
+
const MIN_KOTLIN_VERSION = "2.3.0";
|
|
8
|
+
const UNVERSIONED_KOTLIN_PLUGIN = "classpath('org.jetbrains.kotlin:kotlin-gradle-plugin')";
|
|
9
|
+
const PINNED_KOTLIN_PLUGIN = `classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:\${findProperty('android.kotlinVersion')}")`;
|
|
10
|
+
const ROOT_KOTLIN_VERSION = "ext.kotlinVersion = findProperty('android.kotlinVersion')";
|
|
11
|
+
const EXPO_ROOT_PROJECT = 'apply plugin: "expo-root-project"';
|
|
12
|
+
function isOlderVersion(version) {
|
|
13
|
+
const actual = version.split(".").map(Number);
|
|
14
|
+
const minimum = MIN_KOTLIN_VERSION.split(".").map(Number);
|
|
15
|
+
for (let index = 0; index < minimum.length; index++) {
|
|
16
|
+
if ((actual[index] ?? 0) !== minimum[index])
|
|
17
|
+
return (actual[index] ?? 0) < minimum[index];
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const withKotlinVersion = (config) => {
|
|
22
|
+
config = (0, config_plugins_1.withGradleProperties)(config, (cfg) => {
|
|
23
|
+
const property = cfg.modResults.find((item) => item.type === "property" && item.key === "android.kotlinVersion");
|
|
24
|
+
if (property?.type !== "property") {
|
|
25
|
+
cfg.modResults.push({ type: "property", key: "android.kotlinVersion", value: MIN_KOTLIN_VERSION });
|
|
26
|
+
}
|
|
27
|
+
else if (isOlderVersion(property.value)) {
|
|
28
|
+
property.value = MIN_KOTLIN_VERSION;
|
|
29
|
+
}
|
|
30
|
+
return cfg;
|
|
31
|
+
});
|
|
32
|
+
return (0, config_plugins_1.withProjectBuildGradle)(config, (cfg) => {
|
|
33
|
+
if (cfg.modResults.language !== "groovy")
|
|
34
|
+
return cfg;
|
|
35
|
+
// Expo 55's unversioned classpath resolves React Native's Kotlin 2.1.20
|
|
36
|
+
// compiler even when android.kotlinVersion is set. Pin the actual plugin
|
|
37
|
+
// and Expo's version catalog, as @mentra/crust does for QuickJS.
|
|
38
|
+
let gradle = cfg.modResults.contents.replace(UNVERSIONED_KOTLIN_PLUGIN, PINNED_KOTLIN_PLUGIN);
|
|
39
|
+
if (!gradle.includes(ROOT_KOTLIN_VERSION)) {
|
|
40
|
+
gradle = gradle.replace(EXPO_ROOT_PROJECT, `// Kotlin compiler required by @mentra/bluetooth-sdk's AVIF decoder.\n${ROOT_KOTLIN_VERSION}\n${EXPO_ROOT_PROJECT}`);
|
|
41
|
+
}
|
|
42
|
+
cfg.modResults.contents = gradle;
|
|
43
|
+
return cfg;
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
exports.withKotlinVersion = withKotlinVersion;
|
|
@@ -100,6 +100,28 @@ export type GlassesMediaVolumeSetResult = {
|
|
|
100
100
|
statusCode: number
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
/** On-device keyword spotter state and detections. Describes only the wake-word model. */
|
|
104
|
+
export type WakeWordEvent = {
|
|
105
|
+
kind: "loading" | "ready" | "detected" | "error"
|
|
106
|
+
phrase: string
|
|
107
|
+
/** Unix epoch milliseconds. */
|
|
108
|
+
timestamp: number
|
|
109
|
+
message?: string
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Phone-side speech activity from the on-device Silero detector
|
|
114
|
+
* ([setSpeechActivityDetection]). Sent on transitions only. A gap in incoming
|
|
115
|
+
* microphone audio counts as silence.
|
|
116
|
+
*/
|
|
117
|
+
export type SpeechActivityEvent = {
|
|
118
|
+
speaking: boolean
|
|
119
|
+
/** 0 while speaking; on a silence transition, how long the audio has been silent. */
|
|
120
|
+
silentForMs: number
|
|
121
|
+
/** Unix epoch milliseconds. */
|
|
122
|
+
timestamp: number
|
|
123
|
+
}
|
|
124
|
+
|
|
103
125
|
export type LocalTranscriptionEvent = {
|
|
104
126
|
text: string
|
|
105
127
|
isFinal?: boolean
|
|
@@ -840,11 +862,10 @@ export type StreamIceConfig = {
|
|
|
840
862
|
/**
|
|
841
863
|
* STUN server the glasses should use while gathering candidates.
|
|
842
864
|
*
|
|
843
|
-
* Omit to
|
|
865
|
+
* Omit to send the default Cloudflare STUN server. Pass an empty string to force host-only
|
|
844
866
|
* gathering, which is what SoftAP calling needs: the WHIP server runs on the phone across the
|
|
845
867
|
* glasses' own hotspot, so a server-reflexive candidate is meaningless and there is no route to
|
|
846
|
-
* a STUN server anyway.
|
|
847
|
-
* kept, so a malformed override cannot silently disable ICE.
|
|
868
|
+
* a STUN server anyway. The glasses treat a value that is not a `stun:`/`stuns:` URI as host-only.
|
|
848
869
|
*/
|
|
849
870
|
stun?: string
|
|
850
871
|
}
|
|
@@ -916,7 +937,8 @@ export type PairingStateChangedEvent = {
|
|
|
916
937
|
* - `not_applicable`: no user step for audio. Android attaches Classic audio from the BLE bond,
|
|
917
938
|
* and glasses without Classic audio have nothing to set up.
|
|
918
939
|
* - `connecting`: the glasses are connected, audio is not, and the SDK still expects audio to
|
|
919
|
-
* come up on its own (for example iPhone audio derived from the BLE pair).
|
|
940
|
+
* come up on its own (for example iPhone audio derived from the BLE pair). After setup, Mentra
|
|
941
|
+
* Live firmware that reports `classic_link` reconnects audio itself and stays here.
|
|
920
942
|
* - `connected`: Classic audio (A2DP or HFP) to the glasses is up.
|
|
921
943
|
* - `needs_user`: audio did not come up on its own. Ask the user to connect the glasses in the
|
|
922
944
|
* system Bluetooth settings (iPhone: Settings > Bluetooth). The state moves to `connected`
|
|
@@ -1192,6 +1214,54 @@ export type OtaStatusEvent = {
|
|
|
1192
1214
|
|
|
1193
1215
|
export type OtaQueryResult = OtaStatusEvent
|
|
1194
1216
|
|
|
1217
|
+
/** Lifecycle of a BES crash incident bundle on Mentra Live glasses. */
|
|
1218
|
+
export type BesCrashIncidentState = "COLLECTING" | "STORED" | "REPORTED" | "UPLOADED" | "EVICTED"
|
|
1219
|
+
|
|
1220
|
+
/** One incident bundle the glasses dropped to stay within their storage budget. */
|
|
1221
|
+
export type BesCrashEviction = {
|
|
1222
|
+
incidentKey: string
|
|
1223
|
+
reason: string
|
|
1224
|
+
bytes: number
|
|
1225
|
+
ms: number
|
|
1226
|
+
}
|
|
1227
|
+
|
|
1228
|
+
/**
|
|
1229
|
+
* Glasses-side summary of a BES crash incident. Fields the glasses could not
|
|
1230
|
+
* determine (for example `dumpId` of a reset without a dump) may be absent or null.
|
|
1231
|
+
*/
|
|
1232
|
+
export type BesCrashSummary = {
|
|
1233
|
+
attribution: "match" | "older" | "unknown"
|
|
1234
|
+
dumpId?: string | null
|
|
1235
|
+
bootId?: string | null
|
|
1236
|
+
resetHw?: number | null
|
|
1237
|
+
resetSw?: number | null
|
|
1238
|
+
crashUnixMs?: number | null
|
|
1239
|
+
coveredFromMs?: number | null
|
|
1240
|
+
coveredToMs?: number | null
|
|
1241
|
+
traceGaps: number
|
|
1242
|
+
truncated: boolean
|
|
1243
|
+
torn: boolean
|
|
1244
|
+
tailCaptured: boolean
|
|
1245
|
+
dumpGap: boolean
|
|
1246
|
+
evictedCount: number
|
|
1247
|
+
recentEvictions: BesCrashEviction[]
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
/**
|
|
1251
|
+
* Mentra Live stored a BES crash or unexpected-reset incident. Sent when the
|
|
1252
|
+
* incident becomes `STORED`, and again on every reconnect while it is `STORED`
|
|
1253
|
+
* or `REPORTED`, so handlers must be idempotent per `incidentKey`.
|
|
1254
|
+
*/
|
|
1255
|
+
export type BesCrashDetectedEvent = {
|
|
1256
|
+
type: "bes_crash_detected"
|
|
1257
|
+
incidentKey: string
|
|
1258
|
+
reason: "bes_crash" | "bes_unexpected_reset"
|
|
1259
|
+
state: BesCrashIncidentState
|
|
1260
|
+
/** Cloud report already recorded for this incident, or null before one is reported. */
|
|
1261
|
+
reportId: string | null
|
|
1262
|
+
summary: BesCrashSummary
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1195
1265
|
/** Nex BLE protobuf trace (NexEventUtils); payload matches native Map keys. */
|
|
1196
1266
|
export type BleCommandTraceEvent = {
|
|
1197
1267
|
command: string
|
|
@@ -1223,6 +1293,8 @@ export type BluetoothSdkModuleEvents = {
|
|
|
1223
1293
|
voice_activity_detection_status: (event: VoiceActivityDetectionStatusEvent) => void
|
|
1224
1294
|
speaking_status: (event: SpeakingStatusEvent) => void
|
|
1225
1295
|
battery_status: (event: BatteryStatusEvent) => void
|
|
1296
|
+
wake_word: (event: WakeWordEvent) => void
|
|
1297
|
+
speech_activity: (event: SpeechActivityEvent) => void
|
|
1226
1298
|
local_transcription: (event: LocalTranscriptionEvent) => void
|
|
1227
1299
|
native_notification_status: (event: NativeNotificationStatus) => void
|
|
1228
1300
|
native_notification_delivery: (event: NativeNotificationDelivery) => void
|
|
@@ -1276,6 +1348,7 @@ export type BluetoothSdkModuleEvents = {
|
|
|
1276
1348
|
ota_start_ack: (event: OtaStartAckEvent) => void
|
|
1277
1349
|
ota_status: (event: OtaStatusEvent) => void
|
|
1278
1350
|
ar99_ota_status: (event: Ar99OtaStatusEvent) => void
|
|
1351
|
+
bes_crash_detected: (event: BesCrashDetectedEvent) => void
|
|
1279
1352
|
version_info: (event: VersionInfoEvent) => void
|
|
1280
1353
|
send_command_to_ble: (event: BleCommandTraceEvent) => void
|
|
1281
1354
|
receive_command_from_ble: (event: BleCommandTraceEvent) => void
|
|
@@ -1397,6 +1470,8 @@ export type BluetoothSdkEventMap = {
|
|
|
1397
1470
|
voice_activity_detection_status: VoiceActivityDetectionStatusEvent
|
|
1398
1471
|
speaking_status: SpeakingStatusEvent
|
|
1399
1472
|
battery_status: BatteryStatusEvent
|
|
1473
|
+
wake_word: WakeWordEvent
|
|
1474
|
+
speech_activity: SpeechActivityEvent
|
|
1400
1475
|
local_transcription: LocalTranscriptionEvent
|
|
1401
1476
|
wifi_status_change: WifiStatusChangeEvent
|
|
1402
1477
|
wifi_scan_result: WifiScanResultEvent
|
|
@@ -1442,6 +1517,8 @@ export type BluetoothSdkEventMap = {
|
|
|
1442
1517
|
ota_start_ack: OtaStartAckEvent
|
|
1443
1518
|
ota_status: OtaStatusEvent
|
|
1444
1519
|
ar99_ota_status: Ar99OtaStatusEvent
|
|
1520
|
+
/** Mentra Live stored a BES crash incident for the phone to report. */
|
|
1521
|
+
bes_crash_detected: BesCrashDetectedEvent
|
|
1445
1522
|
version_info: VersionInfoEvent
|
|
1446
1523
|
extraction_progress: ExtractionProgressEvent
|
|
1447
1524
|
}
|
|
@@ -1477,7 +1554,6 @@ export interface BluetoothSdkPublicModule {
|
|
|
1477
1554
|
|
|
1478
1555
|
getDefaultDevice(): Promise<Device | null>
|
|
1479
1556
|
setDefaultDevice(device: Device | null): Promise<void>
|
|
1480
|
-
clearDefaultDevice(): Promise<void>
|
|
1481
1557
|
|
|
1482
1558
|
startScan(model: DeviceModel): Promise<void>
|
|
1483
1559
|
stopScan(): Promise<void>
|
|
@@ -1488,6 +1564,9 @@ export interface BluetoothSdkPublicModule {
|
|
|
1488
1564
|
cancelConnectionAttempt(): Promise<void>
|
|
1489
1565
|
disconnect(): Promise<void>
|
|
1490
1566
|
forget(): Promise<void>
|
|
1567
|
+
/** Unpair the glasses: disconnect, forget them as the default device and, on Mentra Live, remove the phone's Bluetooth
|
|
1568
|
+
* bond, so the next pairing starts from pairing mode. */
|
|
1569
|
+
unpair(): Promise<void>
|
|
1491
1570
|
|
|
1492
1571
|
displayText(text: string, x?: number, y?: number, size?: number): Promise<void>
|
|
1493
1572
|
clearDisplay(): Promise<void>
|
|
@@ -1647,7 +1726,30 @@ export interface BluetoothSdkPublicModule {
|
|
|
1647
1726
|
checkSttModelAvailable(): Promise<boolean>
|
|
1648
1727
|
validateSttModel(path: string): Promise<boolean>
|
|
1649
1728
|
extractTarBz2(sourcePath: string, destinationPath: string): Promise<boolean>
|
|
1729
|
+
/**
|
|
1730
|
+
* Start or stop on-device keyword spotting on microphone PCM. `modelDir` must contain
|
|
1731
|
+
* `encoder.int8.onnx`, `decoder.onnx`, `joiner.int8.onnx`, `tokens.txt` and `keywords.txt`;
|
|
1732
|
+
* it is required when enabling. Disabling releases the model.
|
|
1733
|
+
*/
|
|
1734
|
+
setWakeWordDetection(enabled: boolean, modelDir?: string | null): Promise<void>
|
|
1735
|
+
/**
|
|
1736
|
+
* Finalize the active on-device recognizer's current utterance now. Resolves after the final
|
|
1737
|
+
* `local_transcription` event for it has been emitted, with that final text (empty when nothing
|
|
1738
|
+
* was pending). Resolves `null` when no streaming model is active or the loaded model can't
|
|
1739
|
+
* finalize early.
|
|
1740
|
+
*/
|
|
1741
|
+
finishTranscription(): Promise<string | null>
|
|
1742
|
+
/**
|
|
1743
|
+
* Reload the selected speech model when on-device transcription is in demand. Resolves after
|
|
1744
|
+
* it is loaded; rejects when loading fails; resolves immediately when there is no demand.
|
|
1745
|
+
*/
|
|
1650
1746
|
restartTranscriber(): Promise<void>
|
|
1747
|
+
/**
|
|
1748
|
+
* Start or stop the on-device Silero speech detector on microphone PCM. While enabled it emits
|
|
1749
|
+
* `speech_activity` transitions; `minSilenceMs` (default 300) is the quiet gap before a silence
|
|
1750
|
+
* transition. Disabling releases the model.
|
|
1751
|
+
*/
|
|
1752
|
+
setSpeechActivityDetection(enabled: boolean, options?: {minSilenceMs?: number}): Promise<void>
|
|
1651
1753
|
|
|
1652
1754
|
// TTS Commands (TODO: MOVE TO CRUST)
|
|
1653
1755
|
setTtsModelDetails(path: string, languageCode: string): Promise<void>
|