@mentra/bluetooth-sdk 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +278 -0
- package/android/build.gradle +167 -0
- package/android/lc3Lib/CMakeLists.txt +6 -0
- package/android/lc3Lib/build.gradle +109 -0
- package/android/lc3Lib/proguard-rules.pro +33 -0
- package/android/lc3Lib/src/main/AndroidManifest.xml +2 -0
- package/android/lc3Lib/src/main/cpp/CMakeLists.txt +8 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/CMakeLists.txt +30 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/CMakeLists.txt +7 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/ogg_opus_encoder.cc +96 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/jni/ogg_opus_encoder.h +53 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/Makefile.am +6 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/config_types.h +26 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/config_types.h.in +26 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/ogg.h +209 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libogg/os_types.h +158 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus.h +981 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_custom.h +342 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_defines.h +799 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_multistream.h +660 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_projection.h +568 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/libopus/opus_types.h +166 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/ogg_opus_encoder.cc +268 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/ogg_opus_encoder.h +115 -0
- package/android/lc3Lib/src/main/cpp/google_opus_stuff/opus_tools/opus_header.h +59 -0
- package/android/lc3Lib/src/main/cpp/liblc3/CMakeLists.txt +38 -0
- package/android/lc3Lib/src/main/cpp/liblc3/include/lc3.h +309 -0
- package/android/lc3Lib/src/main/cpp/liblc3/include/lc3_private.h +162 -0
- package/android/lc3Lib/src/main/cpp/liblc3/include/rnnoise.h +114 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/CMakeLists.txt +19 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/attdet.c +92 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/attdet.h +44 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bits.c +375 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bits.h +315 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bwdet.c +129 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/bwdet.h +69 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/common.h +148 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/energy.c +70 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/energy.h +43 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/fastmath.h +158 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/lc3.c +702 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf.c +893 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf.h +111 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf_arm.h +506 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/ltpf_neon.h +281 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/makefile.mk +35 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct.c +452 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct.h +57 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/mdct_neon.h +296 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/meson.build +46 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/plc.c +61 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/plc.h +57 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/sns.c +880 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/sns.h +103 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/spec.c +904 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/spec.h +119 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tables.c +3457 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tables.h +94 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tns.c +457 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3/tns.h +99 -0
- package/android/lc3Lib/src/main/cpp/liblc3/liblc3.cpp +159 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/_kiss_fft_guts.h +182 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/arch.h +261 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/celt_lpc.c +279 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/celt_lpc.h +59 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/common.h +48 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/compile.sh +3 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/denoise.c +646 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/kiss_fft.c +601 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/kiss_fft.h +203 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/opus_types.h +159 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/pitch.c +526 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/pitch.h +149 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn.c +178 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn.h +69 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_data.c +11051 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_data.h +34 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_reader.c +168 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/rnn_train.py +66 -0
- package/android/lc3Lib/src/main/cpp/liblc3/rnnoise/tansig_table.h +45 -0
- package/android/lc3Lib/src/main/java/com/mentra/lc3Lib/Lc3Cpp.java +38 -0
- package/android/lc3Lib/third_party/CMakeLists.txt +23 -0
- package/android/lc3Lib/third_party/CMakeLists_libogg.txt +18 -0
- package/android/lc3Lib/third_party/CMakeLists_libopus.txt +18 -0
- package/android/lc3Lib/third_party/CMakeLists_opus-tools.txt +23 -0
- package/android/lc3Lib/third_party/opus_tools/src/AUTHORS +5 -0
- package/android/lc3Lib/third_party/opus_tools/src/CMakeLists.txt +4 -0
- package/android/lc3Lib/third_party/opus_tools/src/COPYING +371 -0
- package/android/lc3Lib/third_party/opus_tools/src/ChangeLog +3 -0
- package/android/lc3Lib/third_party/opus_tools/src/Makefile.am +42 -0
- package/android/lc3Lib/third_party/opus_tools/src/Makefile.unix +23 -0
- package/android/lc3Lib/third_party/opus_tools/src/NEWS +0 -0
- package/android/lc3Lib/third_party/opus_tools/src/README +0 -0
- package/android/lc3Lib/third_party/opus_tools/src/autogen.sh +115 -0
- package/android/lc3Lib/third_party/opus_tools/src/configure.ac +293 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/arch.h +239 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/audio-in.c +1046 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/diag_range.c +245 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/diag_range.h +28 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/info_opus.c +320 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/info_opus.h +51 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/lpc.c +157 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/lpc.h +27 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opus_header.c +286 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opus_header.h +59 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusdec.c +884 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusenc.c +1021 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusenc.h +101 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusinfo.c +639 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/opusinfo.h +51 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/os_support.h +167 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/resample.c +1137 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/speex_resampler.h +344 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/stack_alloc.h +115 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wav_io.c +125 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wav_io.h +62 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wave_out.c +223 -0
- package/android/lc3Lib/third_party/opus_tools/src/src/wave_out.h +60 -0
- package/android/settings.gradle +1 -0
- package/android/src/main/AndroidManifest.xml +40 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/BluetoothSdkModule.kt +528 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/Bridge.kt +610 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceManager.kt +1616 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/DeviceStore.kt +314 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothModels.kt +1710 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/MentraBluetoothSdk.kt +554 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/ObservableStore.kt +68 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/controllers/ControllerManager.kt +158 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/controllers/R1.kt +934 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/services/Foreground.kt +175 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/services/PhoneMic.kt +1109 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G1.java +3974 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/G2.kt +3551 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Mach1.java +1327 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraLive.java +6959 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraNex.kt +1655 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/MentraosBle.java +53675 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/SGCManager.kt +202 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/sgcs/Simulated.kt +224 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/STTTools.kt +340 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/SherpaOnnxTranscriber.kt +465 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/stt/VadGateSpeechPolicy.kt +221 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/AES.java +106 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/AudioSessionMonitor.kt +189 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/BitmapJavaUtils.java +169 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/BlePhotoUploadService.java +179 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/Constants.kt +44 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/G1Text.kt +436 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/IncidentLogBleRelayNaming.java +29 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/IncidentLogBleUploadService.java +76 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/K900ProtocolUtils.java +791 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/MessageChunker.java +186 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/NexSGCUtils.kt +589 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/PhoneAudioMonitor.kt +303 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/SmartGlassesConnectionState.java +9 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/ByteUtilAudioPlayer.java +655 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/Lc3Player.java +441 -0
- package/android/src/main/java/com/mentra/bluetoothsdk/utils/audio/PCMAudioPlayer.java +431 -0
- package/android/src/main/res/values/strings.xml +4 -0
- package/app.plugin.js +1 -0
- package/build/BluetoothSdk.types.d.ts +498 -0
- package/build/BluetoothSdk.types.d.ts.map +1 -0
- package/build/BluetoothSdk.types.js +23 -0
- package/build/BluetoothSdk.types.js.map +1 -0
- package/build/BluetoothSdkModule.d.ts +71 -0
- package/build/BluetoothSdkModule.d.ts.map +1 -0
- package/build/BluetoothSdkModule.js +106 -0
- package/build/BluetoothSdkModule.js.map +1 -0
- package/build/index.d.ts +3 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +5 -0
- package/build/index.js.map +1 -0
- package/expo-module.config.json +9 -0
- package/ios/BluetoothSdkModule.swift +665 -0
- package/ios/MentraBluetoothSDK.podspec +77 -0
- package/ios/Packages/CoreObjC/CoreObjC.xcodeproj/project.pbxproj +213 -0
- package/ios/Packages/CoreObjC/PcmConverter.h +22 -0
- package/ios/Packages/CoreObjC/PcmConverter.m +266 -0
- package/ios/Packages/CoreObjC/attdet.c +92 -0
- package/ios/Packages/CoreObjC/attdet.h +44 -0
- package/ios/Packages/CoreObjC/bits.c +375 -0
- package/ios/Packages/CoreObjC/bits.h +315 -0
- package/ios/Packages/CoreObjC/bwdet.c +129 -0
- package/ios/Packages/CoreObjC/bwdet.h +69 -0
- package/ios/Packages/CoreObjC/common.h +151 -0
- package/ios/Packages/CoreObjC/energy.c +70 -0
- package/ios/Packages/CoreObjC/energy.h +43 -0
- package/ios/Packages/CoreObjC/fastmath.h +158 -0
- package/ios/Packages/CoreObjC/lc3.c +704 -0
- package/ios/Packages/CoreObjC/lc3.h +313 -0
- package/ios/Packages/CoreObjC/lc3_cpp.h +283 -0
- package/ios/Packages/CoreObjC/lc3_private.h +163 -0
- package/ios/Packages/CoreObjC/ltpf.c +905 -0
- package/ios/Packages/CoreObjC/ltpf.h +111 -0
- package/ios/Packages/CoreObjC/ltpf_arm.h +506 -0
- package/ios/Packages/CoreObjC/ltpf_neon.h +281 -0
- package/ios/Packages/CoreObjC/makefile.mk +35 -0
- package/ios/Packages/CoreObjC/mdct.c +469 -0
- package/ios/Packages/CoreObjC/mdct.h +57 -0
- package/ios/Packages/CoreObjC/mdct_neon.h +296 -0
- package/ios/Packages/CoreObjC/meson.build +61 -0
- package/ios/Packages/CoreObjC/plc.c +61 -0
- package/ios/Packages/CoreObjC/plc.h +57 -0
- package/ios/Packages/CoreObjC/rnnoise.h +114 -0
- package/ios/Packages/CoreObjC/sns.c +880 -0
- package/ios/Packages/CoreObjC/sns.h +103 -0
- package/ios/Packages/CoreObjC/spec.c +907 -0
- package/ios/Packages/CoreObjC/spec.h +119 -0
- package/ios/Packages/CoreObjC/tables.c +3457 -0
- package/ios/Packages/CoreObjC/tables.h +94 -0
- package/ios/Packages/CoreObjC/tns.c +457 -0
- package/ios/Packages/CoreObjC/tns.h +99 -0
- package/ios/Packages/SherpaOnnx/Model/joiner.onnx +0 -0
- package/ios/Packages/SherpaOnnx/Model/tokens.txt +502 -0
- package/ios/Packages/SherpaOnnx/SherpaOnnx.swift +1659 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Headers/cargs.h +162 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Headers/sherpa-onnx/c-api/c-api.h +1852 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Headers/sherpa-onnx/c-api/cxx-api.h +674 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/Info.plist +44 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/libsherpa-onnx.a +0 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64/sherpa-onnx.a +0 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/libsherpa-onnx.a +0 -0
- package/ios/Packages/SherpaOnnx/sherpa-onnx.xcframework/ios-arm64_x86_64-simulator/sherpa-onnx.a +0 -0
- package/ios/Packages/VAD/Common/VAD/VADQuality.swift +41 -0
- package/ios/Packages/VAD/Common/VAD/VADState.swift +26 -0
- package/ios/Packages/VAD/Common/VAD/VADStrategy.swift +29 -0
- package/ios/Packages/VAD/Common/VAD/VADType.swift +14 -0
- package/ios/Packages/VAD/Data/Configuration.swift +68 -0
- package/ios/Packages/VAD/Data/FrameSize.swift +39 -0
- package/ios/Packages/VAD/Data/Record.swift +13 -0
- package/ios/Packages/VAD/Data/Result.swift +22 -0
- package/ios/Packages/VAD/Data/SampleRate.swift +48 -0
- package/ios/Packages/VAD/Silero/Model/silero_vad.onnx +0 -0
- package/ios/Packages/VAD/Silero/SileroVAD.swift +284 -0
- package/ios/Packages/VAD/Silero/SileroVADStrategy.swift +64 -0
- package/ios/Packages/libbz2/module.modulemap +5 -0
- package/ios/Packages/libbz2/shim.h +1 -0
- package/ios/Source/Bridge.swift +353 -0
- package/ios/Source/Bridging-Header.h +16 -0
- package/ios/Source/DeviceManager.swift +1478 -0
- package/ios/Source/DeviceStore.swift +295 -0
- package/ios/Source/MentraBluetoothSDK.swift +2439 -0
- package/ios/Source/ObservableStore.swift +88 -0
- package/ios/Source/PrivacyInfo.xcprivacy +23 -0
- package/ios/Source/controllers/ControllerManager.swift +187 -0
- package/ios/Source/controllers/R1.swift +827 -0
- package/ios/Source/services/PhoneMic.swift +662 -0
- package/ios/Source/sgcs/Frame.swift +651 -0
- package/ios/Source/sgcs/G1.swift +2505 -0
- package/ios/Source/sgcs/G2.swift +3730 -0
- package/ios/Source/sgcs/Mach1.swift +543 -0
- package/ios/Source/sgcs/MentraLive.swift +4708 -0
- package/ios/Source/sgcs/MentraNex.swift +2479 -0
- package/ios/Source/sgcs/SGCManager.swift +243 -0
- package/ios/Source/sgcs/Simulated.swift +270 -0
- package/ios/Source/sgcs/mentraos_ble.pb.swift +3811 -0
- package/ios/Source/stt/STTTools.swift +154 -0
- package/ios/Source/stt/SherpaOnnxTranscriber.swift +401 -0
- package/ios/Source/utils/AudioSessionMonitor.swift +283 -0
- package/ios/Source/utils/Constants.swift +74 -0
- package/ios/Source/utils/Enums.swift +95 -0
- package/ios/Source/utils/G1Text.swift +2067 -0
- package/ios/Source/utils/JSCExperiment.swift +241 -0
- package/ios/Source/utils/MemoryMonitor.swift +44 -0
- package/ios/Source/utils/MessageChunker.swift +164 -0
- package/ios/Source/utils/Models.swift +135 -0
- package/ios/Source/utils/PhoneAudioMonitor.swift +226 -0
- package/ios/Source/utils/TarBz2Extractor.swift +206 -0
- package/package.json +78 -0
- package/plugin/build/index.d.ts +6 -0
- package/plugin/build/index.js +12 -0
- package/plugin/build/withAndroid.d.ts +4 -0
- package/plugin/build/withAndroid.js +80 -0
- package/plugin/build/withIos.d.ts +4 -0
- package/plugin/build/withIos.js +64 -0
- package/src/BluetoothSdk.types.ts +581 -0
- package/src/BluetoothSdkModule.ts +259 -0
- package/src/index.ts +4 -0
|
@@ -0,0 +1,340 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.stt
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import android.content.SharedPreferences
|
|
5
|
+
import com.mentra.bluetoothsdk.Bridge
|
|
6
|
+
import java.io.BufferedInputStream
|
|
7
|
+
import java.io.BufferedOutputStream
|
|
8
|
+
import java.io.File
|
|
9
|
+
import java.io.FileInputStream
|
|
10
|
+
import java.io.FileOutputStream
|
|
11
|
+
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream
|
|
12
|
+
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* STTTools provides utilities for STT model management.
|
|
16
|
+
*
|
|
17
|
+
* Features:
|
|
18
|
+
* - Model path and language code storage
|
|
19
|
+
* - Model validation (check for required files)
|
|
20
|
+
* - tar.bz2 extraction for downloaded models
|
|
21
|
+
*
|
|
22
|
+
* Ported from iOS STTTools.swift to match iOS functionality 1:1
|
|
23
|
+
*/
|
|
24
|
+
object STTTools {
|
|
25
|
+
private const val TAG = "STTTools"
|
|
26
|
+
private const val PREFS_NAME = "MentraPrefs"
|
|
27
|
+
private const val KEY_STT_MODEL_PATH = "STTModelPath"
|
|
28
|
+
private const val KEY_STT_MODEL_LANGUAGE = "STTModelLanguageCode"
|
|
29
|
+
|
|
30
|
+
/** Save STT model details to SharedPreferences */
|
|
31
|
+
fun setSttModelDetails(context: Context, path: String, languageCode: String) {
|
|
32
|
+
val prefs = getPrefs(context)
|
|
33
|
+
prefs.edit().apply {
|
|
34
|
+
putString(KEY_STT_MODEL_PATH, path)
|
|
35
|
+
putString(KEY_STT_MODEL_LANGUAGE, languageCode)
|
|
36
|
+
apply()
|
|
37
|
+
}
|
|
38
|
+
Bridge.log("STT model details saved: path=$path, language=$languageCode")
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** Get the STT model path from SharedPreferences */
|
|
42
|
+
fun getSttModelPath(context: Context): String {
|
|
43
|
+
val prefs = getPrefs(context)
|
|
44
|
+
return prefs.getString(KEY_STT_MODEL_PATH, "") ?: ""
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** Get the STT model language code from SharedPreferences */
|
|
48
|
+
fun getSttModelLanguage(context: Context): String {
|
|
49
|
+
val prefs = getPrefs(context)
|
|
50
|
+
return prefs.getString(KEY_STT_MODEL_LANGUAGE, "en-US") ?: "en-US"
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Check if an STT model is available and valid */
|
|
54
|
+
fun checkSTTModelAvailable(context: Context): Boolean {
|
|
55
|
+
val modelPath = getSttModelPath(context)
|
|
56
|
+
if (modelPath.isEmpty()) {
|
|
57
|
+
return false
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return validateSTTModel(modelPath)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Validate that an STT model has all required files
|
|
65
|
+
*
|
|
66
|
+
* Required files:
|
|
67
|
+
* - tokens.txt (required for all models)
|
|
68
|
+
* - Either CTC model (model.int8.onnx)
|
|
69
|
+
* - Or Transducer model (encoder.onnx, decoder.onnx, joiner.onnx)
|
|
70
|
+
*/
|
|
71
|
+
fun validateSTTModel(path: String): Boolean {
|
|
72
|
+
try {
|
|
73
|
+
val modelDir = File(path)
|
|
74
|
+
|
|
75
|
+
if (!modelDir.exists() || !modelDir.isDirectory) {
|
|
76
|
+
Bridge.log("STT model path does not exist or is not a directory: $path")
|
|
77
|
+
return false
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Check for tokens.txt (required for all models)
|
|
81
|
+
val tokensFile = File(modelDir, "tokens.txt")
|
|
82
|
+
if (!tokensFile.exists()) {
|
|
83
|
+
Bridge.log("STT model missing tokens.txt at: $path")
|
|
84
|
+
return false
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Check for CTC model
|
|
88
|
+
val ctcModelFile = File(modelDir, "model.int8.onnx")
|
|
89
|
+
if (ctcModelFile.exists() && ctcModelFile.canRead() && ctcModelFile.length() > 0) {
|
|
90
|
+
Bridge.log("STT CTC model found at: $path (size: ${ctcModelFile.length()} bytes)")
|
|
91
|
+
return true
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Check for transducer model
|
|
95
|
+
val transducerFiles = listOf("encoder.onnx", "decoder.onnx", "joiner.onnx")
|
|
96
|
+
val allTransducerFilesPresent =
|
|
97
|
+
transducerFiles.all { fileName ->
|
|
98
|
+
val file = File(modelDir, fileName)
|
|
99
|
+
val exists = file.exists() && file.canRead() && file.length() > 0
|
|
100
|
+
if (!exists) {
|
|
101
|
+
Bridge.log(
|
|
102
|
+
"STT model missing or invalid transducer file: $fileName at $path"
|
|
103
|
+
)
|
|
104
|
+
}
|
|
105
|
+
exists
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
if (allTransducerFilesPresent) {
|
|
109
|
+
Bridge.log("STT Transducer model found at: $path")
|
|
110
|
+
return true
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
Bridge.log("No complete STT model found at: $path")
|
|
114
|
+
return false
|
|
115
|
+
} catch (e: Exception) {
|
|
116
|
+
Bridge.log("STT_ERROR: ${e.message}")
|
|
117
|
+
return false
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Extract a tar.bz2 file to a destination directory
|
|
123
|
+
*
|
|
124
|
+
* @param sourcePath Path to the .tar.bz2 file
|
|
125
|
+
* @param destinationPath Directory to extract to
|
|
126
|
+
* @return true if extraction succeeded, false otherwise
|
|
127
|
+
*/
|
|
128
|
+
fun extractTarBz2(sourcePath: String, destinationPath: String): Boolean {
|
|
129
|
+
try {
|
|
130
|
+
val sourceFile = File(sourcePath)
|
|
131
|
+
if (!sourceFile.exists()) {
|
|
132
|
+
Bridge.log("EXTRACTION_ERROR: Source file does not exist: $sourcePath")
|
|
133
|
+
return false
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
val destDir = File(destinationPath)
|
|
137
|
+
|
|
138
|
+
// Create destination directory if it doesn't exist
|
|
139
|
+
if (!destDir.exists()) {
|
|
140
|
+
Bridge.log("Creating destination directory: $destinationPath")
|
|
141
|
+
if (!destDir.mkdirs()) {
|
|
142
|
+
Bridge.log(
|
|
143
|
+
"EXTRACTION_ERROR: Failed to create destination directory: $destinationPath"
|
|
144
|
+
)
|
|
145
|
+
return false
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
Bridge.log("Extracting tar.bz2 from $sourcePath to $destinationPath")
|
|
150
|
+
Bridge.log("Source file size: ${sourceFile.length() / 1024 / 1024}MB")
|
|
151
|
+
|
|
152
|
+
val startTime = System.currentTimeMillis()
|
|
153
|
+
var fileCount = 0
|
|
154
|
+
var bytesExtracted = 0L
|
|
155
|
+
|
|
156
|
+
// Open the tar.bz2 file with buffered streams for better performance
|
|
157
|
+
FileInputStream(sourceFile).use { fis ->
|
|
158
|
+
BufferedInputStream(fis).use { bis ->
|
|
159
|
+
Bridge.log("Opening bz2 decompression stream...")
|
|
160
|
+
BZip2CompressorInputStream(bis).use { bzIn ->
|
|
161
|
+
Bridge.log("Opening tar archive stream...")
|
|
162
|
+
TarArchiveInputStream(bzIn).use { tarIn ->
|
|
163
|
+
Bridge.log("Reading first tar entry...")
|
|
164
|
+
var entry = tarIn.nextEntry
|
|
165
|
+
|
|
166
|
+
while (entry != null) {
|
|
167
|
+
try {
|
|
168
|
+
val outputFile = File(destDir, entry.name)
|
|
169
|
+
Bridge.log(
|
|
170
|
+
"Processing entry: ${entry.name} (${entry.size} bytes, isDir=${entry.isDirectory})"
|
|
171
|
+
)
|
|
172
|
+
|
|
173
|
+
if (entry.isDirectory) {
|
|
174
|
+
// Create directory
|
|
175
|
+
if (!outputFile.exists()) {
|
|
176
|
+
outputFile.mkdirs()
|
|
177
|
+
}
|
|
178
|
+
} else {
|
|
179
|
+
// Create parent directories if needed
|
|
180
|
+
outputFile.parentFile?.let { parent ->
|
|
181
|
+
if (!parent.exists()) {
|
|
182
|
+
parent.mkdirs()
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Extract file with buffered output for better performance
|
|
187
|
+
FileOutputStream(outputFile).use { fos ->
|
|
188
|
+
BufferedOutputStream(fos).use { bos ->
|
|
189
|
+
val buffer =
|
|
190
|
+
ByteArray(
|
|
191
|
+
4096
|
|
192
|
+
) // Use 4KB buffer like original
|
|
193
|
+
// implementation
|
|
194
|
+
var len: Int
|
|
195
|
+
var fileBytes = 0L
|
|
196
|
+
val fileSizeMB = entry.size / 1024 / 1024
|
|
197
|
+
var lastProgressMB = 0L
|
|
198
|
+
|
|
199
|
+
while (tarIn.read(buffer).also { len = it } != -1) {
|
|
200
|
+
bos.write(buffer, 0, len)
|
|
201
|
+
fileBytes += len
|
|
202
|
+
bytesExtracted += len
|
|
203
|
+
|
|
204
|
+
// For large files (>10MB), log progress every
|
|
205
|
+
// 10MB
|
|
206
|
+
if (fileSizeMB > 10) {
|
|
207
|
+
val currentMB = fileBytes / 1024 / 1024
|
|
208
|
+
if (currentMB >= lastProgressMB + 10) {
|
|
209
|
+
lastProgressMB = currentMB
|
|
210
|
+
val percent =
|
|
211
|
+
if (entry.size > 0)
|
|
212
|
+
(fileBytes * 100 /
|
|
213
|
+
entry.size)
|
|
214
|
+
else 0
|
|
215
|
+
Bridge.log(
|
|
216
|
+
" Extracting ${entry.name}: ${currentMB}MB / ${fileSizeMB}MB (${percent}%)"
|
|
217
|
+
)
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
fileCount++
|
|
223
|
+
|
|
224
|
+
// Log progress every file for debugging
|
|
225
|
+
val mbExtracted = bytesExtracted / 1024 / 1024
|
|
226
|
+
Bridge.log(
|
|
227
|
+
"Extracted file $fileCount (${mbExtracted}MB total) - ${entry.name}"
|
|
228
|
+
)
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
Bridge.log("Getting next entry...")
|
|
234
|
+
entry = tarIn.nextEntry
|
|
235
|
+
Bridge.log(
|
|
236
|
+
"Next entry received: ${entry?.name ?: "null (end of archive)"}"
|
|
237
|
+
)
|
|
238
|
+
} catch (e: Exception) {
|
|
239
|
+
Bridge.log(
|
|
240
|
+
"ERROR extracting entry ${entry?.name}: ${e.javaClass.simpleName}: ${e.message}"
|
|
241
|
+
)
|
|
242
|
+
e.printStackTrace()
|
|
243
|
+
throw e
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
Bridge.log("Finished reading all tar entries")
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
val duration = (System.currentTimeMillis() - startTime) / 1000
|
|
254
|
+
val mbExtracted = bytesExtracted / 1024 / 1024
|
|
255
|
+
Bridge.log(
|
|
256
|
+
"Extraction completed successfully: $fileCount files, ${mbExtracted}MB in ${duration}s"
|
|
257
|
+
)
|
|
258
|
+
|
|
259
|
+
// Rename epoch-numbered files to expected names for transducer models
|
|
260
|
+
// Files are extracted to a subdirectory, find it
|
|
261
|
+
val subdirs = destDir.listFiles { file -> file.isDirectory } ?: emptyArray()
|
|
262
|
+
val actualModelDir = if (subdirs.isNotEmpty()) subdirs[0] else destDir
|
|
263
|
+
Bridge.log("Model directory: ${actualModelDir.absolutePath}")
|
|
264
|
+
|
|
265
|
+
// Rename encoder
|
|
266
|
+
val oldEncoderFile = File(actualModelDir, "encoder-epoch-99-avg-1.onnx")
|
|
267
|
+
val newEncoderFile = File(actualModelDir, "encoder.onnx")
|
|
268
|
+
if (oldEncoderFile.exists()) {
|
|
269
|
+
Bridge.log("Renaming encoder-epoch-99-avg-1.onnx to encoder.onnx")
|
|
270
|
+
oldEncoderFile.renameTo(newEncoderFile)
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
// Rename decoder
|
|
274
|
+
val oldDecoderFile = File(actualModelDir, "decoder-epoch-99-avg-1.onnx")
|
|
275
|
+
val newDecoderFile = File(actualModelDir, "decoder.onnx")
|
|
276
|
+
if (oldDecoderFile.exists()) {
|
|
277
|
+
Bridge.log("Renaming decoder-epoch-99-avg-1.onnx to decoder.onnx")
|
|
278
|
+
oldDecoderFile.renameTo(newDecoderFile)
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
// Rename joiner
|
|
282
|
+
val oldJoinerFile = File(actualModelDir, "joiner-epoch-99-avg-1.int8.onnx")
|
|
283
|
+
val newJoinerFile = File(actualModelDir, "joiner.onnx")
|
|
284
|
+
if (oldJoinerFile.exists()) {
|
|
285
|
+
Bridge.log("Renaming joiner-epoch-99-avg-1.int8.onnx to joiner.onnx")
|
|
286
|
+
oldJoinerFile.renameTo(newJoinerFile)
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
// If files were extracted to subdirectory, move them to parent directory
|
|
290
|
+
if (actualModelDir != destDir) {
|
|
291
|
+
Bridge.log("Moving files from subdirectory to parent directory")
|
|
292
|
+
actualModelDir.listFiles()?.forEach { file ->
|
|
293
|
+
if (!file.isDirectory) {
|
|
294
|
+
val targetFile = File(destDir, file.name)
|
|
295
|
+
Bridge.log("Moving ${file.name}")
|
|
296
|
+
file.renameTo(targetFile)
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
// Delete the now-empty subdirectory
|
|
300
|
+
actualModelDir.delete()
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
return true
|
|
304
|
+
} catch (e: Exception) {
|
|
305
|
+
Bridge.log("EXTRACTION_ERROR: ${e.javaClass.simpleName}: ${e.message}")
|
|
306
|
+
e.printStackTrace()
|
|
307
|
+
return false
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/** Get SharedPreferences instance */
|
|
312
|
+
private fun getPrefs(context: Context): SharedPreferences {
|
|
313
|
+
return context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
/** Clear all STT model settings */
|
|
317
|
+
fun clearSttModelSettings(context: Context) {
|
|
318
|
+
val prefs = getPrefs(context)
|
|
319
|
+
prefs.edit().apply {
|
|
320
|
+
remove(KEY_STT_MODEL_PATH)
|
|
321
|
+
remove(KEY_STT_MODEL_LANGUAGE)
|
|
322
|
+
apply()
|
|
323
|
+
}
|
|
324
|
+
Bridge.log("STT model settings cleared")
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
/** Get a summary of the current STT model configuration */
|
|
328
|
+
fun getModelConfigSummary(context: Context): String {
|
|
329
|
+
val path = getSttModelPath(context)
|
|
330
|
+
val language = getSttModelLanguage(context)
|
|
331
|
+
val isValid = checkSTTModelAvailable(context)
|
|
332
|
+
|
|
333
|
+
return """
|
|
334
|
+
STT Model Configuration:
|
|
335
|
+
- Path: ${if (path.isEmpty()) "(not set)" else path}
|
|
336
|
+
- Language: $language
|
|
337
|
+
- Valid: $isValid
|
|
338
|
+
""".trimIndent()
|
|
339
|
+
}
|
|
340
|
+
}
|