@mentra/bluetooth-sdk 3.4.0-dev.1166 → 3.4.0-dev.1170
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/android/build.gradle +6 -36
- package/android/settings.gradle +1 -4
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +61 -3
- package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +27 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +89 -104
- package/android/src/main/java/com/mentra/bluetoothsdk/GeneratedReleaseMetadata.kt +5 -5
- 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/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/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 +49 -0
- package/build/BluetoothSdk.types.d.ts.map +1 -1
- package/build/BluetoothSdk.types.js.map +1 -1
- package/build/_private/BluetoothSdkModule.d.ts +31 -4
- package/build/_private/BluetoothSdkModule.d.ts.map +1 -1
- package/build/_private/BluetoothSdkModule.js.map +1 -1
- package/build/generated/releaseMetadata.js +5 -5
- 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 +5 -0
- package/build/index.js.map +1 -1
- package/ios/BluetoothSdkModule.swift +58 -8
- package/ios/MentraBluetoothSDK.podspec +4 -0
- package/ios/Packages/SherpaOnnx/SherpaOnnx.swift +23 -5
- package/ios/Resources/SileroVad/silero_vad.onnx +0 -0
- package/ios/Source/BluetoothSdkDefaults.swift +1 -1
- package/ios/Source/DeviceManager.swift +30 -12
- package/ios/Source/GeneratedReleaseMetadata.swift +5 -5
- 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/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/DemandDrivenAudioWorkerTests.swift +171 -0
- package/ios/Tests/PcmStreamTests.swift +299 -0
- package/ios/Tests/SpeechActivityTests.swift +238 -0
- package/ios/Tests/SttModelTraitsTests.swift +62 -0
- package/package.json +2 -2
- package/plugin/build/withAndroid.js +7 -11
- package/src/BluetoothSdk.types.ts +49 -0
- package/src/_private/BluetoothSdkModule.ts +33 -4
- package/src/generated/releaseMetadata.ts +5 -5
- package/src/index.ts +7 -0
- 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/main/java/com/mentra/bluetoothsdk/stt/VadGateSpeechPolicy.kt +0 -229
- /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
|
@@ -78,6 +78,8 @@ public class BluetoothSdkModule: Module, MentraBluetoothSDKDelegate {
|
|
|
78
78
|
"audio_disconnected",
|
|
79
79
|
"save_setting",
|
|
80
80
|
"local_transcription",
|
|
81
|
+
"wake_word",
|
|
82
|
+
"speech_activity",
|
|
81
83
|
"phone_notification",
|
|
82
84
|
"native_notification_status",
|
|
83
85
|
"native_notification_delivery",
|
|
@@ -753,16 +755,16 @@ public class BluetoothSdkModule: Module, MentraBluetoothSDKDelegate {
|
|
|
753
755
|
|
|
754
756
|
// MARK: - Live PCM output stream (miniapp speaker.createStream)
|
|
755
757
|
|
|
756
|
-
// jitterMs
|
|
757
|
-
//
|
|
758
|
-
// knob here that would mean the same thing.
|
|
758
|
+
// jitterMs (default 500, 80-500 as on Android): playback starts once that much audio is
|
|
759
|
+
// queued, or on close, so a sound shorter than the cushion still plays.
|
|
759
760
|
AsyncFunction("pcmStreamOpen") {
|
|
760
|
-
(streamId: String, sampleRate: Int, channels: Int, volume: Double,
|
|
761
|
+
(streamId: String, sampleRate: Int, channels: Int, volume: Double, jitterMs: Int?) async throws in
|
|
761
762
|
try PcmStreamManager.open(
|
|
762
763
|
streamId: streamId,
|
|
763
764
|
sampleRate: sampleRate,
|
|
764
765
|
channels: channels,
|
|
765
|
-
volume: Float(volume)
|
|
766
|
+
volume: Float(volume),
|
|
767
|
+
jitterMs: jitterMs
|
|
766
768
|
)
|
|
767
769
|
}
|
|
768
770
|
|
|
@@ -780,6 +782,19 @@ public class BluetoothSdkModule: Module, MentraBluetoothSDKDelegate {
|
|
|
780
782
|
await PcmStreamManager.abort(streamId: streamId)
|
|
781
783
|
}
|
|
782
784
|
|
|
785
|
+
// Native HTTP GET of raw s16le mono PCM, played as it downloads. Async, so the download
|
|
786
|
+
// and playback never hold Expo's shared module queue.
|
|
787
|
+
AsyncFunction("pcmStreamPlayUrl") {
|
|
788
|
+
(streamId: String, url: String, sampleRate: Int, volume: Double, jitterMs: Int?) async throws -> [String: Int64] in
|
|
789
|
+
try ["durationMs": await PcmStreamManager.playUrl(
|
|
790
|
+
streamId: streamId,
|
|
791
|
+
url: url,
|
|
792
|
+
sampleRate: sampleRate,
|
|
793
|
+
volume: Float(volume),
|
|
794
|
+
jitterMs: jitterMs
|
|
795
|
+
)]
|
|
796
|
+
}
|
|
797
|
+
|
|
783
798
|
AsyncFunction("getGlassesMediaVolume") { () async throws -> [String: Any] in
|
|
784
799
|
try await DeviceManager.shared.getGlassesMediaVolume()
|
|
785
800
|
}
|
|
@@ -838,12 +853,47 @@ public class BluetoothSdkModule: Module, MentraBluetoothSDKDelegate {
|
|
|
838
853
|
}
|
|
839
854
|
}
|
|
840
855
|
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
856
|
+
// Loads the keyword spotter from the Speech-page model directory; disabling releases it.
|
|
857
|
+
AsyncFunction("setWakeWordDetection") { (enabled: Bool, modelDir: String?) async throws in
|
|
858
|
+
#if !os(macOS)
|
|
859
|
+
try await WakeWordDetector.shared.configure(enabled: enabled, modelDir: modelDir)
|
|
860
|
+
#else
|
|
861
|
+
if enabled {
|
|
862
|
+
throw NSError(domain: "WakeWordDetector", code: 1,
|
|
863
|
+
userInfo: [NSLocalizedDescriptionKey: "Native wake-word detection is not available on macOS"])
|
|
864
|
+
}
|
|
865
|
+
#endif
|
|
866
|
+
}
|
|
867
|
+
|
|
868
|
+
AsyncFunction("isSttModelLoaded") { (path: String) async -> Bool in
|
|
869
|
+
await DeviceManager.shared.isSttModelLoaded(path)
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
// Final text after its local_transcription event was sent, or null. Never throws.
|
|
873
|
+
AsyncFunction("finishTranscription") { () async -> String? in
|
|
874
|
+
await DeviceManager.shared.finishTranscription()
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
AsyncFunction("restartTranscriber") { () async throws in
|
|
878
|
+
guard await DeviceManager.shared.restartTranscriber() else {
|
|
879
|
+
throw NSError(domain: "SherpaOnnxTranscriber", code: 2,
|
|
880
|
+
userInfo: [NSLocalizedDescriptionKey: "Could not load the speech model"])
|
|
844
881
|
}
|
|
845
882
|
}
|
|
846
883
|
|
|
884
|
+
// Phone-side Silero speech activity on microphone PCM; disabling releases the model.
|
|
885
|
+
AsyncFunction("setSpeechActivityDetection") { (enabled: Bool, options: [String: Any]?) async throws in
|
|
886
|
+
#if !os(macOS)
|
|
887
|
+
let minSilenceMs = (options?["minSilenceMs"] as? NSNumber)?.intValue
|
|
888
|
+
try await SpeechActivityMonitor.shared.setEnabled(enabled, minSilenceMs: minSilenceMs)
|
|
889
|
+
#else
|
|
890
|
+
if enabled {
|
|
891
|
+
throw NSError(domain: "SpeechActivity", code: 1,
|
|
892
|
+
userInfo: [NSLocalizedDescriptionKey: "Native speech activity detection is not available on macOS"])
|
|
893
|
+
}
|
|
894
|
+
#endif
|
|
895
|
+
}
|
|
896
|
+
|
|
847
897
|
// MARK: - Display Commands
|
|
848
898
|
|
|
849
899
|
AsyncFunction("clearDisplay") {
|
|
@@ -53,6 +53,10 @@ Pod::Spec.new do |s|
|
|
|
53
53
|
s.resource_bundles = {
|
|
54
54
|
'BluetoothSDKPrivacy' => ['Source/PrivacyInfo.xcprivacy']
|
|
55
55
|
}
|
|
56
|
+
# Phone-side Silero speech activity runs through the iOS-only sherpa-onnx framework.
|
|
57
|
+
s.ios.resource_bundles = {
|
|
58
|
+
'MentraSileroVad' => ['Resources/SileroVad/silero_vad.onnx']
|
|
59
|
+
}
|
|
56
60
|
|
|
57
61
|
native_source_files = [
|
|
58
62
|
"Source/**/*.{h,m,mm,swift,hpp,cpp,c}",
|
|
@@ -329,6 +329,17 @@ class SherpaOnnxRecognizer {
|
|
|
329
329
|
}
|
|
330
330
|
}
|
|
331
331
|
|
|
332
|
+
/// Replace an ended stream while retaining the loaded recognizer/model.
|
|
333
|
+
@discardableResult
|
|
334
|
+
func recreateStream() -> Bool {
|
|
335
|
+
guard let replacement = SherpaOnnxCreateOnlineStream(recognizer) else { return false }
|
|
336
|
+
lock.lock()
|
|
337
|
+
SherpaOnnxDestroyOnlineStream(stream)
|
|
338
|
+
stream = replacement
|
|
339
|
+
lock.unlock()
|
|
340
|
+
return true
|
|
341
|
+
}
|
|
342
|
+
|
|
332
343
|
/// Signal that no more audio samples would be available.
|
|
333
344
|
/// After this call, you cannot call acceptWaveform() any more.
|
|
334
345
|
func inputFinished() {
|
|
@@ -1000,9 +1011,10 @@ class SherpaOnnxVoiceActivityDetectorWrapper {
|
|
|
1000
1011
|
/// A pointer to the underlying counterpart in C
|
|
1001
1012
|
private let vad: OpaquePointer
|
|
1002
1013
|
|
|
1003
|
-
|
|
1014
|
+
/// Returns nil when sherpa-onnx rejects the model instead of terminating the app.
|
|
1015
|
+
init?(config: UnsafePointer<SherpaOnnxVadModelConfig>, buffer_size_in_seconds: Float) {
|
|
1004
1016
|
guard let vad = SherpaOnnxCreateVoiceActivityDetector(config, buffer_size_in_seconds) else {
|
|
1005
|
-
|
|
1017
|
+
return nil
|
|
1006
1018
|
}
|
|
1007
1019
|
self.vad = vad
|
|
1008
1020
|
}
|
|
@@ -1626,11 +1638,17 @@ class SherpaOnnxKeywordSpotterWrapper {
|
|
|
1626
1638
|
let spotter: OpaquePointer!
|
|
1627
1639
|
var stream: OpaquePointer!
|
|
1628
1640
|
|
|
1629
|
-
|
|
1641
|
+
/// Returns nil when sherpa-onnx rejects the model or keywords instead of crashing later.
|
|
1642
|
+
init?(
|
|
1630
1643
|
config: UnsafePointer<SherpaOnnxKeywordSpotterConfig>!
|
|
1631
1644
|
) {
|
|
1632
|
-
spotter = SherpaOnnxCreateKeywordSpotter(config)
|
|
1633
|
-
stream = SherpaOnnxCreateKeywordStream(spotter)
|
|
1645
|
+
guard let spotter = SherpaOnnxCreateKeywordSpotter(config) else { return nil }
|
|
1646
|
+
guard let stream = SherpaOnnxCreateKeywordStream(spotter) else {
|
|
1647
|
+
SherpaOnnxDestroyKeywordSpotter(spotter)
|
|
1648
|
+
return nil
|
|
1649
|
+
}
|
|
1650
|
+
self.spotter = spotter
|
|
1651
|
+
self.stream = stream
|
|
1634
1652
|
}
|
|
1635
1653
|
|
|
1636
1654
|
deinit {
|
|
Binary file
|
|
@@ -16,7 +16,7 @@ enum BluetoothSdkDefaults {
|
|
|
16
16
|
/// silently disable it on every pair the app touches.
|
|
17
17
|
static let autoPowerOffEnabled = true
|
|
18
18
|
private static let infoSdkVersionKey = "MentraBluetoothSdkVersion"
|
|
19
|
-
private static let swiftPackageSdkVersion = "3.4.0-dev.
|
|
19
|
+
private static let swiftPackageSdkVersion = "3.4.0-dev.1170"
|
|
20
20
|
private static let swiftPackageSdkVersionPlaceholder = "__MENTRA" + "_BLUETOOTH_SDK_VERSION__"
|
|
21
21
|
|
|
22
22
|
private static func normalizedSdkVersion(_ value: String?) -> String? {
|
|
@@ -222,14 +222,6 @@ struct ViewState {
|
|
|
222
222
|
set { DeviceStore.shared.apply("bluetooth", "sensing_enabled", newValue) }
|
|
223
223
|
}
|
|
224
224
|
|
|
225
|
-
/// Phone-side VAD gating switch. Default is OFF (VAD runs) so that the
|
|
226
|
-
/// coordinator can drive per-utterance offline/online STT switching from
|
|
227
|
-
/// `vad_status` events. Set to `true` only as an emergency kill-switch.
|
|
228
|
-
private var bypassVad: Bool {
|
|
229
|
-
get { DeviceStore.shared.get("bluetooth", "bypass_vad") as? Bool ?? false }
|
|
230
|
-
set { DeviceStore.shared.apply("bluetooth", "bypass_vad", newValue) }
|
|
231
|
-
}
|
|
232
|
-
|
|
233
225
|
private var localSttFallbackActive: Bool {
|
|
234
226
|
get { DeviceStore.shared.get("bluetooth", "local_stt_fallback_active") as? Bool ?? false }
|
|
235
227
|
set { DeviceStore.shared.apply("bluetooth", "local_stt_fallback_active", newValue) }
|
|
@@ -558,6 +550,11 @@ struct ViewState {
|
|
|
558
550
|
}
|
|
559
551
|
|
|
560
552
|
func handlePcm(_ pcmData: Data) {
|
|
553
|
+
// The wake word, phone-side speech activity, and local STT all hear the same 16 kHz mono PCM.
|
|
554
|
+
#if !os(macOS) && (!SWIFT_PACKAGE || MENTRA_FEATURE_LOCAL_STT)
|
|
555
|
+
WakeWordDetector.shared.accept(pcmData)
|
|
556
|
+
SpeechActivityMonitor.shared.accept(pcmData)
|
|
557
|
+
#endif
|
|
561
558
|
handleSendingPcm(pcmData)
|
|
562
559
|
|
|
563
560
|
// Send PCM to local transcriber.
|
|
@@ -1009,12 +1006,33 @@ struct ViewState {
|
|
|
1009
1006
|
updateMicState()
|
|
1010
1007
|
}
|
|
1011
1008
|
|
|
1012
|
-
|
|
1009
|
+
/// Whether on-device transcription currently has `path` loaded. Never waits for a load.
|
|
1010
|
+
func isSttModelLoaded(_ path: String) -> Bool {
|
|
1011
|
+
#if !os(macOS) && (!SWIFT_PACKAGE || MENTRA_FEATURE_LOCAL_STT)
|
|
1012
|
+
return transcriber.isModelLoaded(path)
|
|
1013
|
+
#else
|
|
1014
|
+
return false
|
|
1015
|
+
#endif
|
|
1016
|
+
}
|
|
1017
|
+
|
|
1018
|
+
/// Reload the selected model if on-device transcription is in demand. Returns false only
|
|
1019
|
+
/// when that reload failed; true once it loaded or when there is no demand.
|
|
1020
|
+
func restartTranscriber() async -> Bool {
|
|
1021
|
+
#if !os(macOS) && (!SWIFT_PACKAGE || MENTRA_FEATURE_LOCAL_STT)
|
|
1022
|
+
Bridge.log("MAN: Restarting SherpaOnnxTranscriber via command")
|
|
1023
|
+
return await transcriber.restart()
|
|
1024
|
+
#else
|
|
1025
|
+
Bridge.log("MAN: Local STT is not included in this SwiftPM build")
|
|
1026
|
+
return true
|
|
1027
|
+
#endif
|
|
1028
|
+
}
|
|
1029
|
+
|
|
1030
|
+
/// End the current on-device utterance. See `SherpaOnnxTranscriber.finishUtterance`.
|
|
1031
|
+
func finishTranscription() async -> String? {
|
|
1013
1032
|
#if !os(macOS) && (!SWIFT_PACKAGE || MENTRA_FEATURE_LOCAL_STT)
|
|
1014
|
-
|
|
1015
|
-
transcriber.restart()
|
|
1033
|
+
return await transcriber.finishUtterance()
|
|
1016
1034
|
#else
|
|
1017
|
-
|
|
1035
|
+
return nil
|
|
1018
1036
|
#endif
|
|
1019
1037
|
}
|
|
1020
1038
|
|
|
@@ -3,9 +3,9 @@ import Foundation
|
|
|
3
3
|
/// Generated by release CI. Do not edit in a release checkout.
|
|
4
4
|
enum GeneratedReleaseMetadata {
|
|
5
5
|
static let familyBaseVersion = "3.4.0"
|
|
6
|
-
static let releaseIdentity = "3.4.0-dev.
|
|
7
|
-
static let releaseSetId = "mentra-3.4.0-dev.
|
|
8
|
-
static let sourceCommit = "
|
|
9
|
-
static let otaManifestUrl = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-dev.
|
|
10
|
-
static let otaManifestSha256 = "
|
|
6
|
+
static let releaseIdentity = "3.4.0-dev.1170"
|
|
7
|
+
static let releaseSetId = "mentra-3.4.0-dev.1170"
|
|
8
|
+
static let sourceCommit = "bda9eb4b45f3a2f9ab27a3843055470a3fa1a0cf"
|
|
9
|
+
static let otaManifestUrl = "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-dev.1170.json"
|
|
10
|
+
static let otaManifestSha256 = "595391b32c28a6710a47db1088ecd98d8d7b692230a4cddbfa82c950580cbe6c"
|
|
11
11
|
}
|