@mentra/bluetooth-sdk 3.4.0-dev.999 → 3.5.0-dev.1238

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 (140) hide show
  1. package/README.md +33 -11
  2. package/android/build.gradle +60 -51
  3. package/android/gradle.properties +3 -0
  4. package/android/settings.gradle +47 -3
  5. package/android/src/main/java/com/mentra/bluetoothsdk/BesCrashReportWaiters.kt +68 -0
  6. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkDefaults.kt +5 -2
  7. package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +76 -3
  8. package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +27 -0
  9. package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +98 -120
  10. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedChangelogCatalog.kt +2 -1
  11. package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +6 -6
  12. package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +24 -9
  13. package/android/src/main/java/com/mentra/bluetoothsdk/events/BluetoothEvents.kt +16 -0
  14. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.kt +170 -23
  15. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Nimo.kt +13 -316
  16. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinator.kt +0 -35
  17. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSession.kt +2 -10
  18. package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +6 -0
  19. package/android/src/main/java/com/mentra/bluetoothsdk/stt/BoundedAudioQueue.kt +92 -0
  20. package/android/src/main/java/com/mentra/bluetoothsdk/stt/OnDeviceRecognizerHost.kt +169 -0
  21. package/android/src/main/java/com/mentra/bluetoothsdk/stt/STTTools.kt +74 -115
  22. package/android/src/main/java/com/mentra/bluetoothsdk/stt/SherpaOnnxTranscriber.kt +348 -357
  23. package/android/src/main/java/com/mentra/bluetoothsdk/stt/SpeechActivityDetector.kt +211 -0
  24. package/android/src/main/java/com/mentra/bluetoothsdk/stt/SpeechActivityEngine.kt +137 -0
  25. package/android/src/main/java/com/mentra/bluetoothsdk/stt/SttTextFormatter.kt +52 -0
  26. package/android/src/main/java/com/mentra/bluetoothsdk/stt/WakeWordDetector.kt +235 -0
  27. package/android/src/main/java/com/mentra/bluetoothsdk/utils/AvifExifStripper.java +2 -2
  28. package/android/src/main/java/com/mentra/bluetoothsdk/utils/BlePhotoUploadService.java +3 -3
  29. package/android/src/main/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNaming.java +11 -0
  30. package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/AudioRouteWatcher.kt +120 -0
  31. package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PcmStreamPlayer.kt +181 -16
  32. package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PcmUrlPlayback.kt +177 -0
  33. package/android/src/test/java/com/mentra/bluetoothsdk/BesCrashReportWaitersTest.kt +112 -0
  34. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveGlassesReadyBurstTest.kt +141 -0
  35. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveIncidentDispatchTest.kt +183 -0
  36. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/MentraLiveRgbLedResponseTest.kt +76 -0
  37. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasCoordinatorTest.kt +1 -56
  38. package/android/src/test/java/com/mentra/bluetoothsdk/sgcs/NimoCanvasSessionTest.kt +0 -22
  39. package/android/src/test/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNamingTest.kt +23 -0
  40. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/BoundedAudioQueueTest.kt +81 -0
  41. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/OnDeviceRecognizerHostTest.kt +216 -0
  42. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/STTToolsExtractionTest.kt +108 -0
  43. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SpeechActivityDetectorTest.kt +126 -0
  44. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SpeechActivityEngineTest.kt +245 -0
  45. package/android/src/testDebug/java/com/mentra/bluetoothsdk/stt/SttTextFormatterTest.kt +67 -0
  46. package/android/src/testDebug/java/com/mentra/bluetoothsdk/utils/audio/PcmUrlPlaybackTest.kt +76 -0
  47. package/build/BluetoothSdk.types.d.ts +98 -1
  48. package/build/BluetoothSdk.types.d.ts.map +1 -1
  49. package/build/BluetoothSdk.types.js.map +1 -1
  50. package/build/_private/BluetoothSdkModule.d.ts +42 -7
  51. package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
  52. package/build/_private/BluetoothSdkModule.js +1 -0
  53. package/build/_private/BluetoothSdkModule.js.map +1 -1
  54. package/build/generated/changelogCatalog.d.ts +4 -1
  55. package/build/generated/changelogCatalog.d.ts.map +1 -1
  56. package/build/generated/changelogCatalog.js +5 -1
  57. package/build/generated/changelogCatalog.js.map +1 -1
  58. package/build/generated/releaseMetadata.js +6 -6
  59. package/build/generated/releaseMetadata.js.map +1 -1
  60. package/build/index.d.ts +1 -1
  61. package/build/index.d.ts.map +1 -1
  62. package/build/index.js +6 -0
  63. package/build/index.js.map +1 -1
  64. package/ios/BluetoothSdkModule.swift +66 -14
  65. package/ios/MentraBluetoothSDK.podspec +4 -0
  66. package/ios/Packages/SherpaOnnx/SherpaOnnx.swift +23 -5
  67. package/ios/Resources/SileroVad/silero_vad.onnx +0 -0
  68. package/ios/Source/BesCrashReportWaiters.swift +64 -0
  69. package/ios/Source/BluetoothSdkDefaults.swift +2 -2
  70. package/ios/Source/DeviceManager.swift +43 -22
  71. package/ios/Source/GeneratedChangelogCatalog.swift +2 -1
  72. package/ios/Source/GeneratedReleaseMetadata.swift +6 -6
  73. package/ios/Source/MentraBluetoothSDK.swift +27 -15
  74. package/ios/Source/audio/PcmStreamPlayer.swift +290 -57
  75. package/ios/Source/audio/PcmUrlPlayback.swift +231 -0
  76. package/ios/Source/audio/SpeechActivity.swift +277 -0
  77. package/ios/Source/events/BluetoothEvents.swift +41 -0
  78. package/ios/Source/internal/BluetoothAvailability.swift +15 -5
  79. package/ios/Source/sgcs/GlassesAudioSetupPolicy.swift +5 -0
  80. package/ios/Source/sgcs/MentraLive.swift +173 -42
  81. package/ios/Source/sgcs/Nimo.swift +39 -272
  82. package/ios/Source/sgcs/NimoCanvasCoordinator.swift +9 -38
  83. package/ios/Source/sgcs/NimoCanvasSession.swift +0 -1
  84. package/ios/Source/sgcs/SGCManager.swift +6 -0
  85. package/ios/Source/stt/STTTools.swift +13 -31
  86. package/ios/Source/stt/SherpaOnnxTranscriber.swift +204 -162
  87. package/ios/Source/stt/SileroSpeechActivity.swift +87 -0
  88. package/ios/Source/stt/WakeWordDetector.swift +145 -0
  89. package/ios/Source/utils/BoundedWait.swift +44 -0
  90. package/ios/Source/utils/DemandDrivenAudioWorker.swift +79 -0
  91. package/ios/Source/utils/SttModelTraits.swift +62 -0
  92. package/ios/Tests/BesCrashReportTests.swift +142 -0
  93. package/ios/Tests/DemandDrivenAudioWorkerTests.swift +171 -0
  94. package/ios/Tests/DeviceManagerReconnectTests.swift +0 -71
  95. package/ios/Tests/GlassesAudioSetupPolicyTests.swift +9 -3
  96. package/ios/Tests/IncidentLogDispatchTests.swift +158 -0
  97. package/ios/Tests/MentraLiveAudioSetupTests.swift +6 -12
  98. package/ios/Tests/MentraLiveCommandQueueTests.swift +35 -0
  99. package/ios/Tests/MentraLiveSessionReadinessTests.swift +179 -10
  100. package/ios/Tests/NimoCanvasTransportTests.swift +0 -89
  101. package/ios/Tests/PcmStreamTests.swift +299 -0
  102. package/ios/Tests/SpeechActivityTests.swift +238 -0
  103. package/ios/Tests/SttModelTraitsTests.swift +62 -0
  104. package/package.json +2 -2
  105. package/plugin/build/withAndroid.js +9 -11
  106. package/plugin/build/withKotlinVersion.d.ts +2 -0
  107. package/plugin/build/withKotlinVersion.js +46 -0
  108. package/src/BluetoothSdk.types.ts +102 -1
  109. package/src/_private/BluetoothSdkModule.ts +45 -7
  110. package/src/generated/changelogCatalog.ts +5 -1
  111. package/src/generated/releaseMetadata.ts +6 -6
  112. package/src/index.ts +12 -0
  113. package/android/silero/LICENSE.md +0 -17
  114. package/android/silero/build.gradle +0 -50
  115. package/android/silero/proguard-rules.pro +0 -24
  116. package/android/silero/src/androidTest/assets/hello.wav +0 -0
  117. package/android/silero/src/androidTest/java/com/konovalov/vad/silero/VadSileroTest.kt +0 -79
  118. package/android/silero/src/main/java/com/konovalov/vad/silero/Vad.kt +0 -160
  119. package/android/silero/src/main/java/com/konovalov/vad/silero/VadSilero.kt +0 -449
  120. package/android/silero/src/main/java/com/konovalov/vad/silero/config/FrameSize.kt +0 -15
  121. package/android/silero/src/main/java/com/konovalov/vad/silero/config/Mode.kt +0 -14
  122. package/android/silero/src/main/java/com/konovalov/vad/silero/config/SampleRate.kt +0 -12
  123. package/android/silero/src/main/java/com/konovalov/vad/silero/utils/AudioUtils.kt +0 -47
  124. package/android/silero/src/main/java/com/konovalov/vad/silero/utils/TensorMap.kt +0 -41
  125. package/android/silero/src/test/java/com/konovalov/vad/silero/utils/AudioUtilsTest.kt +0 -44
  126. package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +0 -368
  127. package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocol.kt +0 -156
  128. package/android/src/debug/java/com/mentra/bluetoothsdk/sgcs/NimoResourceDiagnostics.kt +0 -274
  129. package/android/src/main/java/com/mentra/bluetoothsdk/stt/VadGateSpeechPolicy.kt +0 -229
  130. package/android/src/release/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnostics.kt +0 -20
  131. package/android/src/release/java/com/mentra/bluetoothsdk/sgcs/NimoResourceDiagnostics.kt +0 -16
  132. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoDiagnosticsTest.kt +0 -287
  133. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoFramebufferProtocolTest.kt +0 -127
  134. package/android/src/testDebug/java/com/mentra/bluetoothsdk/sgcs/NimoLifecycleTest.kt +0 -851
  135. package/ios/Source/sgcs/NimoMacResourceTransport.swift +0 -217
  136. package/ios/Source/sgcs/NimoResourceFixture.swift +0 -384
  137. package/ios/Source/sgcs/NimoResourceSession.swift +0 -406
  138. package/ios/Tests/NimoResourceSessionTests.swift +0 -476
  139. /package/android/{silero/src/main/assets/LICENSE → src/main/assets/vad/LICENSE.silero_vad} +0 -0
  140. /package/android/{silero/src/main/assets → src/main/assets/vad}/silero_vad.onnx +0 -0
package/README.md CHANGED
@@ -46,6 +46,8 @@ changes. Adding this JS package alone cannot reroute logs in an older binary.
46
46
  - React Native `0.72+`.
47
47
  - Expo `49+` when using Expo.
48
48
  - Android min SDK `28+`.
49
+ - Android source builds use Kotlin `2.3.0+`; the Expo config plugin selects it
50
+ automatically. The public Maven SDK still targets Kotlin 2.1 consumers.
49
51
  - iOS deployment target `15.1+`.
50
52
  - Native macOS deployment target `13+`. The Starter Kit's separate
51
53
  `react-native-macos` host requires macOS `14+` and a matching React Native / Expo
@@ -664,7 +666,7 @@ Engine coordinator:
664
666
 
665
667
  Release CI embeds an immutable manifest URL and checksum into every published
666
668
  SDK distribution. The completed coordinated release record correlates the SDK
667
- package with its exact manifest and OTA bundle. A completed release is available at
669
+ package with its exact manifest and, for beta and stable releases, its OTA bundle. A completed release is available at
668
670
  `https://github.com/Mentra-Community/MentraOS/releases/tag/mentra-v<releaseIdentity>`
669
671
  and contains `mentra-release-<releaseIdentity>.json`, which records the exact
670
672
  package coordinates, asset URLs, sizes, checksums, and build provenance.
@@ -679,10 +681,11 @@ Android/iOS OTA contract or infrastructure beneath a coordinator. React Native
679
681
  application pages should render Mentra Engine's semantic controller state
680
682
  instead of sequencing raw events.
681
683
 
682
- Each coordinated prerelease publishes a portable OTA bundle. Stable releases
683
- promote the exact beta-tested OTA bytes, so always resolve the bundle coordinate
684
- and URL from `mentra-release-<releaseIdentity>.json` rather than constructing a
685
- filename. The selected archive contains
684
+ Each beta release publishes a portable OTA bundle; development releases do not.
685
+ A stable release publishes byte-identical copies of the promoted beta's OTA
686
+ manifest and bundle under its own names, so always resolve the bundle
687
+ coordinate and URL from `mentra-release-<releaseIdentity>.json` rather than
688
+ constructing a filename. The selected archive contains
686
689
  `version.template.json`, every referenced ASG/MTK/BES artifact, `SHA256SUMS`,
687
690
  and a dependency-free configuration script. After unpacking it, generate the
688
691
  final manifest for its exact hosting URL:
@@ -865,10 +868,28 @@ MentraOS repo root:
865
868
  ./scripts/check-android-compile.sh bluetooth-sdk
866
869
  ```
867
870
 
868
- The `android/` folder in this package is source for the generated Expo Android
869
- project, not the local Gradle entrypoint. The check script prepares
870
- `mobile/android` and uses its Gradle wrapper with `-PmentraPublicSdk=true`,
871
- matching the CI release workflow's public SDK dependency mode.
871
+ The check script prepares `mobile/android` and uses its Gradle wrapper with
872
+ `-PmentraPublicSdk=true`, matching the CI release workflow's public SDK
873
+ dependency mode. Inside an Expo app, the `android/` folder in this package is
874
+ included by autolinking as `:mentra-bluetooth-sdk`.
875
+
876
+ A plain Android app can also build the native SDK from a MentraOS checkout,
877
+ without publishing it to Maven local, through a Gradle composite build. In the
878
+ app's `settings.gradle.kts`:
879
+
880
+ ```kotlin
881
+ includeBuild("/path/to/MentraOS/mobile/modules/bluetooth-sdk/android") {
882
+ dependencySubstitution {
883
+ substitute(module("com.mentraglass:bluetooth-sdk")).using(project(":"))
884
+ }
885
+ }
886
+ ```
887
+
888
+ The app keeps its `com.mentraglass:bluetooth-sdk` dependency; Gradle replaces it
889
+ with the source build. This standalone build has the same dependencies as the
890
+ Maven Central artifact (`-PmentraPublicSdk=true` is its default) and leaves out
891
+ the Expo adapter classes, which need an Expo host. It needs the Android NDK for
892
+ `lc3Lib`.
872
893
 
873
894
  For bare native iOS or macOS apps, use the public SwiftPM repository:
874
895
 
@@ -878,7 +899,7 @@ https://github.com/Mentra-Community/mentra-bluetooth-sdk-ios.git
878
899
 
879
900
  Select a coordinated SDK version that includes your target platform, then add
880
901
  the `MentraBluetoothSDK` product to your app target. Native macOS support is new
881
- on `dev`; use the local source override until a supporting release is published.
902
+ on `dev`; use the local package below until a supporting release is published.
882
903
 
883
904
  For local SDK development, add this package folder directly in Xcode:
884
905
 
@@ -894,7 +915,8 @@ permission/audio-input capability for host microphone capture and network-server
894
915
  capability for local SDK servers. macOS uses CoreAudio instead of
895
916
  `AVAudioSession`; it does not provide iOS background modes or ANCS relay. See
896
917
  [the macOS integration guide](../../../mintlify-docs/bluetooth-sdk/macos.mdx)
897
- and the Starter Kit's `examples/macos` and `examples/react-native-macos` hosts.
918
+ and the [`examples/bluetooth/macos`](../../../examples/bluetooth/macos/README.md) and
919
+ [`examples/bluetooth/react-native-macos`](../../../examples/bluetooth/react-native-macos/README.md) hosts.
898
920
 
899
921
  Maintainers publishing the public SwiftPM mirror should follow
900
922
  [RELEASING_IOS_SPM.md](./RELEASING_IOS_SPM.md).
@@ -8,7 +8,14 @@ apply plugin: 'signing'
8
8
  def packageJson = new JsonSlurper().parse(file("../package.json"))
9
9
  def mavenGroupId = 'com.mentraglass'
10
10
  def mavenPublishVersion = (findProperty('mentraMavenVersion') ?: System.getenv('MENTRA_MAVEN_VERSION') ?: packageJson.version).toString()
11
- def publicMavenSdk = (findProperty('mentraPublicSdk') ?: System.getenv('MENTRA_PUBLIC_SDK') ?: 'false').toString().toBoolean()
11
+ // Inside an Expo host such as the MentraOS app, autolinking provides
12
+ // :expo-modules-core. Without it, this directory is the root of a standalone
13
+ // build (settings.gradle), for example a composite build in a plain Android app.
14
+ // expo-modules-core has no prebuilt Android artifact to resolve instead, so a
15
+ // standalone build leaves out the Expo adapter classes and defaults to the
16
+ // public Maven artifact's dependency shape.
17
+ def standaloneBuild = findProject(':expo-modules-core') == null
18
+ def publicMavenSdk = (findProperty('mentraPublicSdk') ?: System.getenv('MENTRA_PUBLIC_SDK') ?: standaloneBuild.toString()).toString().toBoolean()
12
19
 
13
20
  // Download Sherpa-ONNX Android AAR from the upstream GitHub release and stage
14
21
  // it as a Maven artifact in a tiny on-disk repository under libs/maven/.
@@ -88,7 +95,7 @@ if (!sherpaOnnxAar.exists()) {
88
95
  }
89
96
 
90
97
  // Minimal POM so the Maven resolver is happy. No transitive deps — the AAR
91
- // ships its own native libs and we already pin onnxruntime separately below.
98
+ // ships its own native libs, including its own libonnxruntime.so.
92
99
  if (!sherpaOnnxPom.exists()) {
93
100
  sherpaOnnxPom.text = """<?xml version="1.0" encoding="UTF-8"?>
94
101
  <project xmlns="http://maven.apache.org/POM/4.0.0">
@@ -181,13 +188,38 @@ gradle.taskGraph.whenReady {
181
188
  }
182
189
  }
183
190
 
184
- def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
185
- apply from: expoModulesCorePlugin
186
- applyKotlinExpoModulesCorePlugin()
187
- useExpoPublishing()
191
+ if (standaloneBuild) {
192
+ apply plugin: 'kotlin-android'
193
+ // Java 17 bytecode, as in the MentraOS app build.
194
+ android {
195
+ compileOptions {
196
+ sourceCompatibility JavaVersion.VERSION_17
197
+ targetCompatibility JavaVersion.VERSION_17
198
+ }
199
+ }
200
+ kotlin {
201
+ compilerOptions {
202
+ jvmTarget = org.jetbrains.kotlin.gradle.dsl.JvmTarget.JVM_17
203
+ }
204
+ }
205
+ // Expo adapters, compiled only inside an Expo host (see expo-module.config.json).
206
+ tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).configureEach {
207
+ exclude(
208
+ '**/com/mentra/bluetoothsdk/BluetoothSdkModule.kt',
209
+ '**/com/mentra/bluetoothsdk/MentraLocalNetworkModule.kt',
210
+ '**/com/mentra/bluetoothsdk/otaserver/MentraOtaServerModule.kt',
211
+ '**/com/mentra/bluetoothsdk/photoreceiver/MentraPhotoReceiverModule.kt'
212
+ )
213
+ }
214
+ } else {
215
+ def expoModulesCorePlugin = new File(project(":expo-modules-core").projectDir.absolutePath, "ExpoModulesCorePlugin.gradle")
216
+ apply from: expoModulesCorePlugin
217
+ applyKotlinExpoModulesCorePlugin()
218
+ useExpoPublishing()
219
+ }
188
220
 
189
- // Hosts that embed @mentra/crust compile with Kotlin 2.3 (its QuickJS library
190
- // requires it). Keep the public Maven artifact usable from Kotlin 2.1 builds:
221
+ // Source builds use Kotlin 2.3 for avif-coder (and Crust's QuickJS when present).
222
+ // Keep the public Maven artifact usable from Kotlin 2.1 builds:
191
223
  // 2.2 metadata (a 2.1 compiler reads one version ahead; 2.2 is also the lowest
192
224
  // language version that reads the 2.3 expo-modules-core classes compiled here),
193
225
  // 2.1 stdlib APIs, and a kotlin-stdlib 2.1.20 dependency in the POM.
@@ -225,6 +257,9 @@ if (useManagedAndroidSdkVersions) {
225
257
 
226
258
  android {
227
259
  namespace "com.mentra.bluetoothsdk"
260
+ buildFeatures {
261
+ buildConfig true
262
+ }
228
263
  defaultConfig {
229
264
  versionCode 1
230
265
  versionName project.version
@@ -255,7 +290,9 @@ android {
255
290
  dependencies {
256
291
  // Expo adapter class is compiled into the MentraOS module, but the bare SDK
257
292
  // artifact should not expose Expo as a runtime dependency.
258
- compileOnly project(':expo-modules-core')
293
+ if (!standaloneBuild) {
294
+ compileOnly project(':expo-modules-core')
295
+ }
259
296
 
260
297
  // Kotlin standard library (explicitly added for IDE support)
261
298
  // Version is managed by Expo modules, but explicit dependency helps IDE indexing
@@ -278,13 +315,15 @@ dependencies {
278
315
  implementation 'androidx.exifinterface:exifinterface:1.3.7'
279
316
 
280
317
  // AVIF decode for BLE photo fallback. Public Maven artifacts omit this
281
- // JitPack-only decoder from runtime metadata; Android 12+ can still use the
282
- // platform decoder, while MentraOS app builds keep HeifCoder for broader
283
- // fallback support.
284
- // Pinned to the JitPack 1.7.3 build (same as asg_client): the Maven Central
285
- // 2.2.x releases transitively pull kotlin-stdlib 2.3.0, which breaks this
286
- // project's Kotlin 2.1 compile of :expo.
287
- dependencies.add(publicMavenSdk ? 'compileOnly' : 'implementation', 'com.github.awxkee:avif-coder:1.7.3')
318
+ // decoder from runtime metadata; Android 12+ can still use the platform
319
+ // decoder, while MentraOS app builds keep Coder for broader fallback.
320
+ // 3.0.0 ships 16 KB-aligned libcoder.so (1.7.3 was 4 KB). Its POM depends
321
+ // on kotlin-stdlib 2.3.0. Exclude it to keep the public SDK's runtime
322
+ // dependencies on 2.1; the Expo plugin selects a 2.3 source compiler to
323
+ // read the decoder's metadata, independently of this stdlib exclusion.
324
+ dependencies.add(publicMavenSdk ? 'compileOnly' : 'implementation', 'io.github.awxkee:avif-coder:3.0.0') {
325
+ exclude group: 'org.jetbrains.kotlin', module: 'kotlin-stdlib'
326
+ }
288
327
 
289
328
  testImplementation 'junit:junit:4.13.2'
290
329
  testImplementation 'org.robolectric:robolectric:4.11.1'
@@ -308,28 +347,18 @@ dependencies {
308
347
  // Maven Central/Google repositories for normal SDK use.
309
348
  def optionalMentraOsIntegrationDependency = publicMavenSdk ? 'compileOnly' : 'implementation'
310
349
 
311
- // Sherpa-ONNX for local transcription. Jitpack's v1.13.2 build failed
312
- // upstream, so we stage the prebuilt AAR into libs/maven/ (see top of file)
313
- // and consume it as a Maven coord — AGP rejects raw files() .aar deps in
314
- // library modules.
350
+ // Sherpa-ONNX for on-device transcription, the wake word and Silero speech
351
+ // activity (com.k2fsa.sherpa.onnx.Vad, model in src/main/assets/vad/).
352
+ // Jitpack's v1.13.2 build failed upstream, so we stage the prebuilt AAR into
353
+ // libs/maven/ (see top of file) and consume it as a Maven coord — AGP rejects
354
+ // raw files() .aar deps in library modules.
315
355
  dependencies.add(optionalMentraOsIntegrationDependency, "${sherpaOnnxGroup}:${sherpaOnnxArtifact}:${sherpaOnnxVersion}@aar")
316
356
 
317
357
  if (!publicMavenSdk) {
318
- // Silero VAD — vendored source under silero/, wired as :silero
319
- // sub-project (see settings.gradle). This replaces the previous Jitpack AAR
320
- // (com.github.gkonovalov:android-vad:2.0.9) whose prebuilt JNI was bound to
321
- // an ORT version incompatible with the one bundled by sherpa-onnx, causing a
322
- // dlopen UnsatisfiedLinkError for OrtGetApiBase at VAD startup. By owning the
323
- // source we control both the Java API surface and the ORT version it links
324
- // against; today both consumers (Silero VAD and sherpa-onnx) load their own
325
- // libonnxruntime.so — see packagingOptions pickFirst above.
326
- implementation project(':silero')
327
-
328
358
  // Vuzix Z100
329
359
  implementation 'com.vuzix:ultralite-sdk-android:1.8'
330
360
  implementation 'com.squareup.picasso:picasso:2.8'
331
361
  } else {
332
- compileOnly project(':silero')
333
362
  compileOnly 'com.vuzix:ultralite-sdk-android:1.8'
334
363
  compileOnly 'com.squareup.picasso:picasso:2.8'
335
364
  }
@@ -338,26 +367,6 @@ dependencies {
338
367
  implementation 'com.google.protobuf:protobuf-java-util:4.32.0'
339
368
  }
340
369
 
341
- // Pin onnxruntime-android to 1.24.3 — the version sherpa-onnx 1.13.2 was built
342
- // against (its libonnxruntime.so exports OrtGetApiBase@@VERS_1.24.3). Matching
343
- // this lets the :silero VAD module share a single libonnxruntime.so with
344
- // sherpa-onnx, resolving the ELF symbol-versioning conflict that crashed VAD
345
- // startup on previous mismatched versions.
346
- configurations.all {
347
- resolutionStrategy {
348
- eachDependency { DependencyResolveDetails details ->
349
- if (details.requested.group == 'com.microsoft.onnxruntime') {
350
- details.useVersion '1.24.3'
351
- details.because('Match sherpa-onnx 1.13.2 ORT 1.24.3')
352
- }
353
- if (details.requested.name == 'onnxruntime-android') {
354
- details.useVersion '1.24.3'
355
- details.because('Match sherpa-onnx 1.13.2 ORT 1.24.3')
356
- }
357
- }
358
- }
359
- }
360
-
361
370
  afterEvaluate {
362
371
  publishing {
363
372
  publications {
@@ -0,0 +1,3 @@
1
+ # Used when this directory is the root of a standalone build (settings.gradle).
2
+ # Inside an Expo host, the host's own gradle.properties sets the same value.
3
+ android.useAndroidX=true
@@ -1,4 +1,48 @@
1
- include ':lc3Lib'
1
+ // Standalone build of the Bluetooth SDK's Android library, used when this
2
+ // directory is the root of a Gradle build: for example a plain Android app that
3
+ // consumes the SDK from source through a composite build,
4
+ // includeBuild("<MentraOS>/mobile/modules/bluetooth-sdk/android")
5
+ // with com.mentraglass:bluetooth-sdk substituted by project(":").
6
+ // The MentraOS app (an Expo host) ignores this file: Expo autolinking adds this
7
+ // directory as :mentra-bluetooth-sdk, and the SDK's config plugin adds :lc3Lib
8
+ // to the host's own settings.gradle.
9
+
10
+ gradle.rootProject { project ->
11
+ // Same versions as the MentraOS app's generated Android project. AGP refuses
12
+ // two versions in one composite build, so when this build is included in an
13
+ // app, use the AGP version on that app's root build classpath.
14
+ def androidGradlePluginVersion = '8.12.0'
15
+ def appGradle = gradle.parent
16
+ if (appGradle != null) {
17
+ try {
18
+ androidGradlePluginVersion = appGradle.rootProject.buildscript.classLoader
19
+ .loadClass('com.android.Version')
20
+ .getField('ANDROID_GRADLE_PLUGIN_VERSION')
21
+ .get(null)
22
+ } catch (ClassNotFoundException ignored) {
23
+ // The app does not load AGP in its root build; keep the default.
24
+ }
25
+ }
26
+
27
+ project.buildscript {
28
+ repositories {
29
+ google()
30
+ mavenCentral()
31
+ }
32
+ dependencies {
33
+ classpath "com.android.tools.build:gradle:${androidGradlePluginVersion}"
34
+ classpath 'org.jetbrains.kotlin:kotlin-gradle-plugin:2.3.0'
35
+ }
36
+ }
37
+ }
2
38
 
3
- include ':silero'
4
- project(':silero').projectDir = new File(rootDir, 'silero')
39
+ gradle.beforeProject { project ->
40
+ project.repositories {
41
+ google()
42
+ mavenCentral()
43
+ }
44
+ }
45
+
46
+ rootProject.name = 'mentra-bluetooth-sdk'
47
+
48
+ include ':lc3Lib'
@@ -0,0 +1,68 @@
1
+ package com.mentra.bluetoothsdk
2
+
3
+ import kotlinx.coroutines.CompletableDeferred
4
+ import kotlinx.coroutines.withTimeoutOrNull
5
+
6
+ /**
7
+ * Correlates `bes_crash_reported` commands with the glasses' `bes_crash_reported_ack`.
8
+ *
9
+ * Each call owns one waiter keyed by (incidentKey, reportId), so concurrent reports for
10
+ * different incidents, or a stale ack for an earlier reportId, never settle each other.
11
+ */
12
+ internal class BesCrashReportWaiters {
13
+ private class Waiter(val incidentKey: String, val reportId: String) {
14
+ val result = CompletableDeferred<Unit>()
15
+ }
16
+
17
+ private val waiters = mutableListOf<Waiter>()
18
+
19
+ /** Registers before [send] so an immediate ack cannot be missed. */
20
+ suspend fun await(incidentKey: String, reportId: String, timeoutMs: Long, send: () -> Unit) {
21
+ val waiter = Waiter(incidentKey, reportId)
22
+ synchronized(waiters) { waiters.add(waiter) }
23
+ try {
24
+ send()
25
+ withTimeoutOrNull(timeoutMs) { waiter.result.await() }
26
+ ?: throw BluetoothSdkException(
27
+ "request_timeout",
28
+ "bes_crash_reported for $incidentKey timed out waiting for the glasses ack.",
29
+ )
30
+ } finally {
31
+ synchronized(waiters) { waiters.remove(waiter) }
32
+ }
33
+ }
34
+
35
+ /**
36
+ * Settles the waiters this ack answers. `ok:true` must echo the reportId; an `ok:false`
37
+ * without a reportId rejects every waiter for that incidentKey. Returns the number settled.
38
+ */
39
+ fun onAck(values: Map<String, Any>): Int {
40
+ val incidentKey = values["incidentKey"] as? String ?: return 0
41
+ val reportId = (values["reportId"] as? String)?.takeIf { it.isNotEmpty() }
42
+ val ok = values["ok"] == true
43
+ val matched = synchronized(waiters) {
44
+ waiters.filter {
45
+ it.incidentKey == incidentKey && (it.reportId == reportId || (!ok && reportId == null))
46
+ }
47
+ }
48
+ if (ok) {
49
+ matched.forEach { it.result.complete(Unit) }
50
+ } else {
51
+ val error = (values["error"] as? String)?.takeIf { it.isNotEmpty() } ?: "unknown_error"
52
+ matched.forEach {
53
+ it.result.completeExceptionally(
54
+ BluetoothSdkException(
55
+ "bes_crash_report_rejected",
56
+ "Glasses rejected bes_crash_reported for $incidentKey: $error",
57
+ )
58
+ )
59
+ }
60
+ }
61
+ return matched.size
62
+ }
63
+
64
+ fun rejectAll(error: Throwable) {
65
+ val snapshot = synchronized(waiters) { waiters.toList() }
66
+ snapshot.forEach { it.result.completeExceptionally(error) }
67
+ }
68
+ }
@@ -5,6 +5,9 @@ object BluetoothSdkDefaults {
5
5
  const val VOICE_ACTIVITY_DETECTION_ENABLED = false
6
6
  const val LOUDNESS_GATE_ENABLED = true
7
7
 
8
- /** Off until someone turns it on in Super Mode. Re-pushed on connect. */
9
- const val AUTO_POWER_OFF_ENABLED = false
8
+ /**
9
+ * Must match the firmware default (on). Re-pushed on connect, so a false
10
+ * value here would silently turn it off on every pair the app touches.
11
+ */
12
+ const val AUTO_POWER_OFF_ENABLED = true
10
13
  }
@@ -271,6 +271,10 @@ class BluetoothSdkModule : Module() {
271
271
  sendEvent("ota_status", event.values)
272
272
  }
273
273
 
274
+ override fun onBesCrashDetected(event: BesCrashDetectedEvent) {
275
+ sendEvent("bes_crash_detected", event.toEventMap())
276
+ }
277
+
274
278
  override fun onSettingsAck(event: SettingsAckEvent) {
275
279
  sendEvent("settings_ack", event.values)
276
280
  }
@@ -351,6 +355,8 @@ class BluetoothSdkModule : Module() {
351
355
  "speaking_status",
352
356
  "battery_status",
353
357
  "local_transcription",
358
+ "wake_word",
359
+ "speech_activity",
354
360
  "wifi_status_change",
355
361
  "wifi_scan_result",
356
362
  "wifi_forget_result",
@@ -406,6 +412,7 @@ class BluetoothSdkModule : Module() {
406
412
  "ota_start_ack",
407
413
  "ota_status",
408
414
  "ar99_ota_status",
415
+ "bes_crash_detected",
409
416
  // Nex / BLE debug (NexEventUtils —Bridge.sendTypedMessage)
410
417
  "send_command_to_ble",
411
418
  "receive_command_from_ble",
@@ -567,6 +574,12 @@ class BluetoothSdkModule : Module() {
567
574
  sdk?.startScan(DeviceModel.fromDeviceType(model))
568
575
  }
569
576
 
577
+ SdkAsyncFunction("getBondedGlasses") { ->
578
+ com.mentra.bluetoothsdk.sgcs.MentraLive.soleBondedMentraLive(Bridge.getContext())?.let {
579
+ mapOf("name" to (it.name ?: ""), "address" to it.address)
580
+ }
581
+ }
582
+
570
583
  SdkAsyncFunction("getScanDiagnostic") { model: String ->
571
584
  sdk?.connectedDeviceScanDiagnostic(DeviceModel.fromDeviceType(model))?.let {
572
585
  mapOf("code" to it.code, "message" to it.message)
@@ -626,6 +639,10 @@ class BluetoothSdkModule : Module() {
626
639
  requireSdk().sendIncidentId(incidentId, apiBaseUrl)
627
640
  }
628
641
 
642
+ SdkCoroutineFunction("sendBesCrashReported") { incidentKey: String, reportId: String ->
643
+ requireSdk().sendBesCrashReported(incidentKey, reportId)
644
+ }
645
+
629
646
  // MARK: - Native Notification Centre
630
647
 
631
648
  // Public controls use the SDK facade; phone payload delivery uses DeviceManager.
@@ -885,13 +902,42 @@ class BluetoothSdkModule : Module() {
885
902
  sdk?.setMicSourcePin(source)
886
903
  }
887
904
 
888
- // Runs on Dispatchers.IO, not the shared Expo AsyncFunctionQueue: restart()
889
- // does a synchronous JNI model reload that would otherwise block every other
890
- // native call in the app until it completes.
905
+ // MARK: - On-device voice
906
+ //
907
+ // Everything that can wait on a model load or a worker runs on Dispatchers.IO,
908
+ // never on the shared Expo AsyncFunctionQueue, which every other native call
909
+ // (and every miniapp) waits behind.
910
+
911
+ AsyncFunction("setWakeWordDetection") Coroutine { enabled: Boolean, modelDir: String? ->
912
+ withContext(Dispatchers.IO) {
913
+ com.mentra.bluetoothsdk.stt.WakeWordDetector.configure(enabled, modelDir)
914
+ }
915
+ }
916
+
917
+ // Lock-free: never waits on a model load.
918
+ AsyncFunction("isSttModelLoaded") { path: String ->
919
+ deviceManager?.isSttModelLoaded(path) ?: false
920
+ }
921
+
922
+ // Resolves with the final text, "" when nothing was pending, or null when no
923
+ // streaming model is active, the model can't finalize early, or after 3 s.
924
+ AsyncFunction("finishTranscription") Coroutine { ->
925
+ withContext(Dispatchers.IO) { deviceManager?.finishTranscription() }
926
+ }
927
+
891
928
  AsyncFunction("restartTranscriber") Coroutine { ->
892
929
  withContext(Dispatchers.IO) { deviceManager?.restartTranscriber() }
893
930
  }
894
931
 
932
+ AsyncFunction("setSpeechActivityDetection") Coroutine { enabled: Boolean, options: Map<String, Any?>? ->
933
+ val minSilenceMs =
934
+ (options?.get("minSilenceMs") as? Number)?.toInt()
935
+ ?: com.mentra.bluetoothsdk.stt.SpeechActivityEngine.DEFAULT_MIN_SILENCE_MS
936
+ withContext(Dispatchers.IO) {
937
+ com.mentra.bluetoothsdk.stt.SpeechActivityDetector.configure(enabled, minSilenceMs)
938
+ }
939
+ }
940
+
895
941
  // MARK: - Audio Playback Monitoring
896
942
 
897
943
  SdkAsyncFunction("setOwnAppAudioPlaying") { playing: Boolean ->
@@ -933,6 +979,33 @@ class BluetoothSdkModule : Module() {
933
979
  PcmStreamManager.abort(streamId)
934
980
  }
935
981
 
982
+ // Native HTTP GET of raw s16le mono PCM, played as it arrives. Blocks a
983
+ // Dispatchers.IO thread (never the shared queue) until the body has played.
984
+ AsyncFunction("pcmStreamPlayUrl") Coroutine {
985
+ streamId: String,
986
+ url: String,
987
+ sampleRate: Int,
988
+ volume: Double,
989
+ jitterMs: Int?,
990
+ ->
991
+ withContext(Dispatchers.IO) {
992
+ try {
993
+ mapOf(
994
+ "durationMs" to
995
+ PcmStreamManager.playUrl(
996
+ streamId,
997
+ url,
998
+ sampleRate,
999
+ volume.toFloat(),
1000
+ jitterMs,
1001
+ )
1002
+ )
1003
+ } catch (error: com.mentra.bluetoothsdk.utils.audio.PcmUrlPlaybackException) {
1004
+ throw CodedException(error.code, error.message ?: error.code, error)
1005
+ }
1006
+ }
1007
+ }
1008
+
936
1009
  // *Blocking on Dispatchers.IO, not the shared AsyncFunctionQueue: these wait on
937
1010
  // a CountDownLatch (up to 5s) for a BLE round-trip, which would otherwise stall
938
1011
  // every other native call queued behind them.
@@ -255,6 +255,33 @@ public class Bridge private constructor() {
255
255
  sendTypedMessage("speaking_status", body as Map<String, Any>)
256
256
  }
257
257
 
258
+ /**
259
+ * Send a phone-side speech activity transition from the on-device Silero detector.
260
+ * [silentForMs] is 0 while speaking; on a silence transition, how long it has been quiet.
261
+ */
262
+ @JvmStatic
263
+ fun sendSpeechActivity(speaking: Boolean, silentForMs: Long) {
264
+ val body = HashMap<String, Any>()
265
+ body["speaking"] = speaking
266
+ body["silentForMs"] = silentForMs
267
+ body["timestamp"] = System.currentTimeMillis()
268
+ sendTypedMessage("speech_activity", body as Map<String, Any>)
269
+ }
270
+
271
+ /**
272
+ * Send on-device keyword spotter state or a detection. [kind] is "loading", "ready",
273
+ * "detected" or "error"; it describes only the wake-word model.
274
+ */
275
+ @JvmStatic
276
+ fun sendWakeWord(kind: String, phrase: String, message: String? = null) {
277
+ val body = HashMap<String, Any>()
278
+ body["kind"] = kind
279
+ body["phrase"] = phrase
280
+ body["timestamp"] = System.currentTimeMillis()
281
+ if (message != null) body["message"] = message
282
+ sendTypedMessage("wake_word", body as Map<String, Any>)
283
+ }
284
+
258
285
  /** Send battery status */
259
286
  @JvmStatic
260
287
  fun sendBatteryStatus(level: Int, charging: Boolean) {