@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,431 @@
|
|
|
1
|
+
package com.mentra.bluetoothsdk.utils.audio;
|
|
2
|
+
|
|
3
|
+
import android.content.Context;
|
|
4
|
+
import android.media.AudioDeviceInfo;
|
|
5
|
+
import android.media.AudioFormat;
|
|
6
|
+
import android.media.AudioManager;
|
|
7
|
+
import android.media.AudioTrack;
|
|
8
|
+
import android.os.Build;
|
|
9
|
+
import android.util.Log;
|
|
10
|
+
|
|
11
|
+
import java.nio.ByteBuffer;
|
|
12
|
+
import java.nio.ByteOrder;
|
|
13
|
+
import java.util.concurrent.atomic.AtomicBoolean;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* PCM Audio Player for playing raw PCM audio data
|
|
17
|
+
* Supports different sample rates, bit depths, and channel configurations
|
|
18
|
+
*/
|
|
19
|
+
public class PCMAudioPlayer {
|
|
20
|
+
private static final String TAG = "PCMAudioPlayer";
|
|
21
|
+
|
|
22
|
+
// Audio configuration
|
|
23
|
+
private int sampleRate;
|
|
24
|
+
private int channelConfig;
|
|
25
|
+
private int audioFormat;
|
|
26
|
+
private int bufferSize;
|
|
27
|
+
|
|
28
|
+
// AudioTrack instance
|
|
29
|
+
private AudioTrack audioTrack;
|
|
30
|
+
private Context context;
|
|
31
|
+
private AudioManager audioManager;
|
|
32
|
+
|
|
33
|
+
// Playback state
|
|
34
|
+
private AtomicBoolean isPlaying = new AtomicBoolean(false);
|
|
35
|
+
private AtomicBoolean isInitialized = new AtomicBoolean(false);
|
|
36
|
+
|
|
37
|
+
// Thread for playback
|
|
38
|
+
private Thread playbackThread;
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Constructor with default audio configuration
|
|
42
|
+
*/
|
|
43
|
+
public PCMAudioPlayer(Context context) {
|
|
44
|
+
this(context, 16000, AudioFormat.CHANNEL_OUT_MONO, AudioFormat.ENCODING_PCM_16BIT);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* Constructor with custom audio configuration
|
|
49
|
+
*
|
|
50
|
+
* @param context Application context
|
|
51
|
+
* @param sampleRate Sample rate in Hz (e.g., 16000, 44100, 48000)
|
|
52
|
+
* @param channelConfig Channel configuration (MONO or STEREO)
|
|
53
|
+
* @param audioFormat Audio format (16-bit, 8-bit, float, etc.)
|
|
54
|
+
*/
|
|
55
|
+
public PCMAudioPlayer(Context context, int sampleRate, int channelConfig, int audioFormat) {
|
|
56
|
+
this.context = context;
|
|
57
|
+
this.audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
|
|
58
|
+
this.sampleRate = sampleRate;
|
|
59
|
+
this.channelConfig = channelConfig;
|
|
60
|
+
this.audioFormat = audioFormat;
|
|
61
|
+
|
|
62
|
+
// Calculate buffer size
|
|
63
|
+
this.bufferSize = AudioTrack.getMinBufferSize(sampleRate, channelConfig, audioFormat);
|
|
64
|
+
if (this.bufferSize == AudioTrack.ERROR_BAD_VALUE) {
|
|
65
|
+
Log.e(TAG, "Invalid audio configuration");
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// Use a larger buffer for better performance
|
|
70
|
+
this.bufferSize = Math.max(this.bufferSize * 2, 8192);
|
|
71
|
+
|
|
72
|
+
initializeAudioTrack();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Initialize the AudioTrack
|
|
77
|
+
*
|
|
78
|
+
* Uses USAGE_VOICE_COMMUNICATION and routes to Bluetooth SCO if available
|
|
79
|
+
*/
|
|
80
|
+
private void initializeAudioTrack() {
|
|
81
|
+
try {
|
|
82
|
+
audioTrack = new AudioTrack.Builder()
|
|
83
|
+
.setAudioAttributes(new android.media.AudioAttributes.Builder()
|
|
84
|
+
.setUsage(android.media.AudioAttributes.USAGE_VOICE_COMMUNICATION)
|
|
85
|
+
.setContentType(android.media.AudioAttributes.CONTENT_TYPE_SPEECH)
|
|
86
|
+
.build())
|
|
87
|
+
.setAudioFormat(new android.media.AudioFormat.Builder()
|
|
88
|
+
.setEncoding(audioFormat)
|
|
89
|
+
.setSampleRate(sampleRate)
|
|
90
|
+
.setChannelMask(channelConfig)
|
|
91
|
+
.build())
|
|
92
|
+
.setBufferSizeInBytes(bufferSize)
|
|
93
|
+
.setTransferMode(AudioTrack.MODE_STREAM)
|
|
94
|
+
.build();
|
|
95
|
+
|
|
96
|
+
if (audioTrack.getState() == AudioTrack.STATE_INITIALIZED) {
|
|
97
|
+
isInitialized.set(true);
|
|
98
|
+
Log.d(TAG, "AudioTrack initialized successfully with USAGE_VOICE_COMMUNICATION");
|
|
99
|
+
|
|
100
|
+
// Route to Bluetooth SCO if available
|
|
101
|
+
routeToBluetoothIfAvailable();
|
|
102
|
+
} else {
|
|
103
|
+
Log.e(TAG, "Failed to initialize AudioTrack");
|
|
104
|
+
}
|
|
105
|
+
} catch (Exception e) {
|
|
106
|
+
Log.e(TAG, "Error initializing AudioTrack", e);
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/**
|
|
111
|
+
* Route audio to Bluetooth SCO device if available
|
|
112
|
+
*/
|
|
113
|
+
private void routeToBluetoothIfAvailable() {
|
|
114
|
+
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M || audioManager == null || audioTrack == null) {
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
try {
|
|
119
|
+
// Get all available audio output devices
|
|
120
|
+
AudioDeviceInfo[] devices = audioManager.getDevices(AudioManager.GET_DEVICES_OUTPUTS);
|
|
121
|
+
|
|
122
|
+
AudioDeviceInfo bluetoothDevice = null;
|
|
123
|
+
|
|
124
|
+
// Look for Bluetooth SCO device
|
|
125
|
+
for (AudioDeviceInfo device : devices) {
|
|
126
|
+
if (device.getType() == AudioDeviceInfo.TYPE_BLUETOOTH_SCO) {
|
|
127
|
+
bluetoothDevice = device;
|
|
128
|
+
Log.d(TAG, "Found Bluetooth SCO device: " + device.getProductName());
|
|
129
|
+
break;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// If we found a Bluetooth SCO device, route audio to it
|
|
134
|
+
if (bluetoothDevice != null) {
|
|
135
|
+
boolean success = audioTrack.setPreferredDevice(bluetoothDevice);
|
|
136
|
+
if (success) {
|
|
137
|
+
Log.d(TAG, "Successfully routed audio to Bluetooth SCO device");
|
|
138
|
+
} else {
|
|
139
|
+
Log.w(TAG, "Failed to route audio to Bluetooth SCO device");
|
|
140
|
+
}
|
|
141
|
+
} else {
|
|
142
|
+
Log.d(TAG, "No Bluetooth SCO device available, using default routing");
|
|
143
|
+
}
|
|
144
|
+
} catch (Exception e) {
|
|
145
|
+
Log.e(TAG, "Error routing to Bluetooth: " + e.getMessage());
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* Play PCM audio data
|
|
151
|
+
*
|
|
152
|
+
* @param pcmData Raw PCM audio data as byte array
|
|
153
|
+
* @return true if playback started successfully
|
|
154
|
+
*/
|
|
155
|
+
public boolean playPCMData(byte[] pcmData) {
|
|
156
|
+
if (!isInitialized.get() || audioTrack == null) {
|
|
157
|
+
Log.e(TAG, "AudioTrack not initialized");
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (isPlaying.get()) {
|
|
162
|
+
Log.w(TAG, "Already playing audio");
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
isPlaying.set(true);
|
|
167
|
+
|
|
168
|
+
playbackThread = new Thread(() -> {
|
|
169
|
+
try {
|
|
170
|
+
audioTrack.play();
|
|
171
|
+
|
|
172
|
+
// Write the PCM data
|
|
173
|
+
int written = audioTrack.write(pcmData, 0, pcmData.length);
|
|
174
|
+
|
|
175
|
+
if (written < 0) {
|
|
176
|
+
Log.e(TAG, "Error writing audio data: " + written);
|
|
177
|
+
} else {
|
|
178
|
+
Log.d(TAG, "Successfully wrote " + written + " bytes of audio data");
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// Wait for playback to complete
|
|
182
|
+
audioTrack.stop();
|
|
183
|
+
|
|
184
|
+
} catch (Exception e) {
|
|
185
|
+
Log.e(TAG, "Error during playback", e);
|
|
186
|
+
} finally {
|
|
187
|
+
isPlaying.set(false);
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
playbackThread.start();
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Play PCM audio data with streaming (for real-time audio)
|
|
197
|
+
*
|
|
198
|
+
* @param pcmData Raw PCM audio data as byte array
|
|
199
|
+
* @return true if data was written successfully
|
|
200
|
+
*/
|
|
201
|
+
public boolean streamPCMData(byte[] pcmData) {
|
|
202
|
+
if (!isInitialized.get() || audioTrack == null) {
|
|
203
|
+
Log.e(TAG, "AudioTrack not initialized");
|
|
204
|
+
return false;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
if (!isPlaying.get()) {
|
|
208
|
+
// Start playback if not already playing
|
|
209
|
+
audioTrack.play();
|
|
210
|
+
isPlaying.set(true);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
try {
|
|
214
|
+
int written = audioTrack.write(pcmData, 0, pcmData.length);
|
|
215
|
+
|
|
216
|
+
if (written < 0) {
|
|
217
|
+
Log.e(TAG, "Error writing audio data: " + written);
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return true;
|
|
222
|
+
} catch (Exception e) {
|
|
223
|
+
Log.e(TAG, "Error streaming audio data", e);
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Play PCM audio data from short array (16-bit samples)
|
|
230
|
+
*
|
|
231
|
+
* @param pcmData PCM audio data as short array
|
|
232
|
+
* @return true if playback started successfully
|
|
233
|
+
*/
|
|
234
|
+
public boolean playPCMData(short[] pcmData) {
|
|
235
|
+
if (!isInitialized.get() || audioTrack == null) {
|
|
236
|
+
Log.e(TAG, "AudioTrack not initialized");
|
|
237
|
+
return false;
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
if (isPlaying.get()) {
|
|
241
|
+
Log.w(TAG, "Already playing audio");
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
isPlaying.set(true);
|
|
246
|
+
|
|
247
|
+
playbackThread = new Thread(() -> {
|
|
248
|
+
try {
|
|
249
|
+
audioTrack.play();
|
|
250
|
+
|
|
251
|
+
// Write the PCM data
|
|
252
|
+
int written = audioTrack.write(pcmData, 0, pcmData.length);
|
|
253
|
+
|
|
254
|
+
if (written < 0) {
|
|
255
|
+
Log.e(TAG, "Error writing audio data: " + written);
|
|
256
|
+
} else {
|
|
257
|
+
Log.d(TAG, "Successfully wrote " + written + " samples of audio data");
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
// Wait for playback to complete
|
|
261
|
+
audioTrack.stop();
|
|
262
|
+
|
|
263
|
+
} catch (Exception e) {
|
|
264
|
+
Log.e(TAG, "Error during playback", e);
|
|
265
|
+
} finally {
|
|
266
|
+
isPlaying.set(false);
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
playbackThread.start();
|
|
271
|
+
return true;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
/**
|
|
275
|
+
* Stream PCM audio data from short array (16-bit samples)
|
|
276
|
+
*
|
|
277
|
+
* @param pcmData PCM audio data as short array
|
|
278
|
+
* @return true if data was written successfully
|
|
279
|
+
*/
|
|
280
|
+
public boolean streamPCMData(short[] pcmData) {
|
|
281
|
+
if (!isInitialized.get() || audioTrack == null) {
|
|
282
|
+
Log.e(TAG, "AudioTrack not initialized");
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
if (!isPlaying.get()) {
|
|
287
|
+
// Start playback if not already playing
|
|
288
|
+
audioTrack.play();
|
|
289
|
+
isPlaying.set(true);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
try {
|
|
293
|
+
int written = audioTrack.write(pcmData, 0, pcmData.length);
|
|
294
|
+
|
|
295
|
+
if (written < 0) {
|
|
296
|
+
Log.e(TAG, "Error writing audio data: " + written);
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
return true;
|
|
301
|
+
} catch (Exception e) {
|
|
302
|
+
Log.e(TAG, "Error streaming audio data", e);
|
|
303
|
+
return false;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Convert byte array to short array (for 16-bit PCM)
|
|
309
|
+
*
|
|
310
|
+
* @param byteData Raw PCM byte data
|
|
311
|
+
* @return Short array representation
|
|
312
|
+
*/
|
|
313
|
+
public static short[] bytesToShorts(byte[] byteData) {
|
|
314
|
+
short[] shortData = new short[byteData.length / 2];
|
|
315
|
+
ByteBuffer.wrap(byteData).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().get(shortData);
|
|
316
|
+
return shortData;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* Convert short array to byte array (for 16-bit PCM)
|
|
321
|
+
*
|
|
322
|
+
* @param shortData PCM short data
|
|
323
|
+
* @return Byte array representation
|
|
324
|
+
*/
|
|
325
|
+
public static byte[] shortsToBytes(short[] shortData) {
|
|
326
|
+
byte[] byteData = new byte[shortData.length * 2];
|
|
327
|
+
ByteBuffer.wrap(byteData).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer().put(shortData);
|
|
328
|
+
return byteData;
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
/**
|
|
332
|
+
* Stop playback
|
|
333
|
+
*/
|
|
334
|
+
public void stop() {
|
|
335
|
+
if (audioTrack != null && isPlaying.get()) {
|
|
336
|
+
audioTrack.stop();
|
|
337
|
+
isPlaying.set(false);
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
if (playbackThread != null && playbackThread.isAlive()) {
|
|
341
|
+
playbackThread.interrupt();
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Pause playback
|
|
347
|
+
*/
|
|
348
|
+
public void pause() {
|
|
349
|
+
if (audioTrack != null && isPlaying.get()) {
|
|
350
|
+
audioTrack.pause();
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* Resume playback
|
|
356
|
+
*/
|
|
357
|
+
public void resume() {
|
|
358
|
+
if (audioTrack != null && isInitialized.get()) {
|
|
359
|
+
audioTrack.play();
|
|
360
|
+
isPlaying.set(true);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Set volume (0.0f to 1.0f)
|
|
366
|
+
*
|
|
367
|
+
* @param volume Volume level
|
|
368
|
+
*/
|
|
369
|
+
public void setVolume(float volume) {
|
|
370
|
+
if (audioTrack != null) {
|
|
371
|
+
audioTrack.setVolume(volume);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Check if currently playing
|
|
377
|
+
*
|
|
378
|
+
* @return true if playing
|
|
379
|
+
*/
|
|
380
|
+
public boolean isPlaying() {
|
|
381
|
+
return isPlaying.get();
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Check if initialized
|
|
386
|
+
*
|
|
387
|
+
* @return true if initialized
|
|
388
|
+
*/
|
|
389
|
+
public boolean isInitialized() {
|
|
390
|
+
return isInitialized.get();
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
/**
|
|
394
|
+
* Get current playback position in frames
|
|
395
|
+
*
|
|
396
|
+
* @return Playback position
|
|
397
|
+
*/
|
|
398
|
+
public int getPlaybackHeadPosition() {
|
|
399
|
+
if (audioTrack != null) {
|
|
400
|
+
return audioTrack.getPlaybackHeadPosition();
|
|
401
|
+
}
|
|
402
|
+
return 0;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Get audio session ID
|
|
407
|
+
*
|
|
408
|
+
* @return Audio session ID
|
|
409
|
+
*/
|
|
410
|
+
public int getAudioSessionId() {
|
|
411
|
+
if (audioTrack != null) {
|
|
412
|
+
return audioTrack.getAudioSessionId();
|
|
413
|
+
}
|
|
414
|
+
return AudioManager.ERROR;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Release resources
|
|
419
|
+
*/
|
|
420
|
+
public void release() {
|
|
421
|
+
stop();
|
|
422
|
+
|
|
423
|
+
if (audioTrack != null) {
|
|
424
|
+
audioTrack.release();
|
|
425
|
+
audioTrack = null;
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
isInitialized.set(false);
|
|
429
|
+
isPlaying.set(false);
|
|
430
|
+
}
|
|
431
|
+
}
|
package/app.plugin.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require('./plugin/build');
|