@mentra/bluetooth-sdk 3.4.0-dev.1169 → 3.4.0-dev.1171
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
|
@@ -100,6 +100,28 @@ export type GlassesMediaVolumeSetResult = {
|
|
|
100
100
|
statusCode: number
|
|
101
101
|
}
|
|
102
102
|
|
|
103
|
+
/** On-device keyword spotter state and detections. Describes only the wake-word model. */
|
|
104
|
+
export type WakeWordEvent = {
|
|
105
|
+
kind: "loading" | "ready" | "detected" | "error"
|
|
106
|
+
phrase: string
|
|
107
|
+
/** Unix epoch milliseconds. */
|
|
108
|
+
timestamp: number
|
|
109
|
+
message?: string
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Phone-side speech activity from the on-device Silero detector
|
|
114
|
+
* ([setSpeechActivityDetection]). Sent on transitions only. A gap in incoming
|
|
115
|
+
* microphone audio counts as silence.
|
|
116
|
+
*/
|
|
117
|
+
export type SpeechActivityEvent = {
|
|
118
|
+
speaking: boolean
|
|
119
|
+
/** 0 while speaking; on a silence transition, how long the audio has been silent. */
|
|
120
|
+
silentForMs: number
|
|
121
|
+
/** Unix epoch milliseconds. */
|
|
122
|
+
timestamp: number
|
|
123
|
+
}
|
|
124
|
+
|
|
103
125
|
export type LocalTranscriptionEvent = {
|
|
104
126
|
text: string
|
|
105
127
|
isFinal?: boolean
|
|
@@ -1271,6 +1293,8 @@ export type BluetoothSdkModuleEvents = {
|
|
|
1271
1293
|
voice_activity_detection_status: (event: VoiceActivityDetectionStatusEvent) => void
|
|
1272
1294
|
speaking_status: (event: SpeakingStatusEvent) => void
|
|
1273
1295
|
battery_status: (event: BatteryStatusEvent) => void
|
|
1296
|
+
wake_word: (event: WakeWordEvent) => void
|
|
1297
|
+
speech_activity: (event: SpeechActivityEvent) => void
|
|
1274
1298
|
local_transcription: (event: LocalTranscriptionEvent) => void
|
|
1275
1299
|
native_notification_status: (event: NativeNotificationStatus) => void
|
|
1276
1300
|
native_notification_delivery: (event: NativeNotificationDelivery) => void
|
|
@@ -1446,6 +1470,8 @@ export type BluetoothSdkEventMap = {
|
|
|
1446
1470
|
voice_activity_detection_status: VoiceActivityDetectionStatusEvent
|
|
1447
1471
|
speaking_status: SpeakingStatusEvent
|
|
1448
1472
|
battery_status: BatteryStatusEvent
|
|
1473
|
+
wake_word: WakeWordEvent
|
|
1474
|
+
speech_activity: SpeechActivityEvent
|
|
1449
1475
|
local_transcription: LocalTranscriptionEvent
|
|
1450
1476
|
wifi_status_change: WifiStatusChangeEvent
|
|
1451
1477
|
wifi_scan_result: WifiScanResultEvent
|
|
@@ -1698,7 +1724,30 @@ export interface BluetoothSdkPublicModule {
|
|
|
1698
1724
|
checkSttModelAvailable(): Promise<boolean>
|
|
1699
1725
|
validateSttModel(path: string): Promise<boolean>
|
|
1700
1726
|
extractTarBz2(sourcePath: string, destinationPath: string): Promise<boolean>
|
|
1727
|
+
/**
|
|
1728
|
+
* Start or stop on-device keyword spotting on microphone PCM. `modelDir` must contain
|
|
1729
|
+
* `encoder.int8.onnx`, `decoder.onnx`, `joiner.int8.onnx`, `tokens.txt` and `keywords.txt`;
|
|
1730
|
+
* it is required when enabling. Disabling releases the model.
|
|
1731
|
+
*/
|
|
1732
|
+
setWakeWordDetection(enabled: boolean, modelDir?: string | null): Promise<void>
|
|
1733
|
+
/**
|
|
1734
|
+
* Finalize the active on-device recognizer's current utterance now. Resolves after the final
|
|
1735
|
+
* `local_transcription` event for it has been emitted, with that final text (empty when nothing
|
|
1736
|
+
* was pending). Resolves `null` when no streaming model is active or the loaded model can't
|
|
1737
|
+
* finalize early.
|
|
1738
|
+
*/
|
|
1739
|
+
finishTranscription(): Promise<string | null>
|
|
1740
|
+
/**
|
|
1741
|
+
* Reload the selected speech model when on-device transcription is in demand. Resolves after
|
|
1742
|
+
* it is loaded; rejects when loading fails; resolves immediately when there is no demand.
|
|
1743
|
+
*/
|
|
1701
1744
|
restartTranscriber(): Promise<void>
|
|
1745
|
+
/**
|
|
1746
|
+
* Start or stop the on-device Silero speech detector on microphone PCM. While enabled it emits
|
|
1747
|
+
* `speech_activity` transitions; `minSilenceMs` (default 300) is the quiet gap before a silence
|
|
1748
|
+
* transition. Disabling releases the model.
|
|
1749
|
+
*/
|
|
1750
|
+
setSpeechActivityDetection(enabled: boolean, options?: {minSilenceMs?: number}): Promise<void>
|
|
1702
1751
|
|
|
1703
1752
|
// TTS Commands (TODO: MOVE TO CRUST)
|
|
1704
1753
|
setTtsModelDetails(path: string, languageCode: string): Promise<void>
|
|
@@ -266,7 +266,16 @@ declare class BluetoothSdkNativeModule extends NativeModule<BluetoothSdkModuleEv
|
|
|
266
266
|
* so a caller that depends on the guarantee must gate on platform.
|
|
267
267
|
*/
|
|
268
268
|
setMicSourcePin(source: string | null): Promise<void>
|
|
269
|
+
/** See the public `setWakeWordDetection`. `modelDir` is required when enabling. */
|
|
270
|
+
setWakeWordDetection(enabled: boolean, modelDir?: string | null): Promise<void>
|
|
271
|
+
/** Whether the active recognizer has `path` loaded. Never blocks on a model load. */
|
|
272
|
+
isSttModelLoaded(path: string): Promise<boolean>
|
|
273
|
+
/** See the public `finishTranscription`. */
|
|
274
|
+
finishTranscription(): Promise<string | null>
|
|
275
|
+
/** See the public `restartTranscriber`. */
|
|
269
276
|
restartTranscriber(): Promise<void>
|
|
277
|
+
/** See the public `setSpeechActivityDetection`. */
|
|
278
|
+
setSpeechActivityDetection(enabled: boolean, options?: {minSilenceMs?: number}): Promise<void>
|
|
270
279
|
|
|
271
280
|
// Audio Playback Monitoring
|
|
272
281
|
// Notify native side when our app starts/stops playing audio
|
|
@@ -280,10 +289,15 @@ declare class BluetoothSdkNativeModule extends NativeModule<BluetoothSdkModuleEv
|
|
|
280
289
|
/**
|
|
281
290
|
* Open a PCM stream session. One AudioTrack per id; caller manages ids.
|
|
282
291
|
*
|
|
283
|
-
* `jitterMs`
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
292
|
+
* `jitterMs` (default 500) is how much audio is queued before playback starts, and the playout
|
|
293
|
+
* cushion after that. Omit it for one-way media, where the default cushion is inaudible; pass a
|
|
294
|
+
* small value for conversational audio, where the same cushion is delay before the far end is
|
|
295
|
+
* heard. Both platforms honor it: playback starts once `jitterMs` is queued or the stream is
|
|
296
|
+
* closed, so a sound shorter than `jitterMs` still plays.
|
|
297
|
+
*
|
|
298
|
+
* A stream that has not received audio yet is aborted when the audio route changes (Bluetooth
|
|
299
|
+
* or glasses connect/disconnect, a call starting or ending, an audio-session interruption), so
|
|
300
|
+
* its next write rejects with "stream not open" instead of playing on a stale route.
|
|
287
301
|
*/
|
|
288
302
|
pcmStreamOpen(
|
|
289
303
|
streamId: string,
|
|
@@ -302,6 +316,21 @@ declare class BluetoothSdkNativeModule extends NativeModule<BluetoothSdkModuleEv
|
|
|
302
316
|
pcmStreamClose(streamId: string): Promise<{durationMs: number}>
|
|
303
317
|
/** Stop immediately, dropping any backlog. Idempotent. */
|
|
304
318
|
pcmStreamAbort(streamId: string): Promise<void>
|
|
319
|
+
/**
|
|
320
|
+
* Fetch `url` (HTTP GET) and play its body as raw 16-bit little-endian mono PCM at `sampleRate`
|
|
321
|
+
* while it downloads, through the same stream player as `pcmStreamOpen`. Native code reads the
|
|
322
|
+
* body; audio never crosses into JavaScript. Resolves with the played duration after the whole
|
|
323
|
+
* body has played. Rejects on a non-2xx response or a network error (whatever already played
|
|
324
|
+
* stays played), and with "aborted" after `pcmStreamAbort(streamId)`. Must not block the shared
|
|
325
|
+
* module queue while it runs.
|
|
326
|
+
*/
|
|
327
|
+
pcmStreamPlayUrl(
|
|
328
|
+
streamId: string,
|
|
329
|
+
url: string,
|
|
330
|
+
sampleRate: number,
|
|
331
|
+
volume: number,
|
|
332
|
+
jitterMs?: number,
|
|
333
|
+
): Promise<{durationMs: number}>
|
|
305
334
|
|
|
306
335
|
/** Mentra Live only: K900 `cs_getvol` / `sr_getvol`. */
|
|
307
336
|
getGlassesMediaVolume(): Promise<GlassesMediaVolumeGetResult>
|
|
@@ -12,9 +12,9 @@ export interface BluetoothSdkReleaseMetadata {
|
|
|
12
12
|
export const BLUETOOTH_SDK_RELEASE_METADATA: Readonly<BluetoothSdkReleaseMetadata> = Object.freeze({
|
|
13
13
|
"schemaVersion": 1,
|
|
14
14
|
"familyBaseVersion": "3.4.0",
|
|
15
|
-
"releaseIdentity": "3.4.0-dev.
|
|
16
|
-
"releaseSetId": "mentra-3.4.0-dev.
|
|
17
|
-
"sourceCommit": "
|
|
18
|
-
"otaManifestUrl": "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-dev.
|
|
19
|
-
"otaManifestSha256": "
|
|
15
|
+
"releaseIdentity": "3.4.0-dev.1171",
|
|
16
|
+
"releaseSetId": "mentra-3.4.0-dev.1171",
|
|
17
|
+
"sourceCommit": "71f6bde0a4763e70a264209ed6a241f68abca6ed",
|
|
18
|
+
"otaManifestUrl": "https://artifactscdn.mentraglass.com/Mentra-Community/MentraOS/releases/mentra-builds-v3.4.0/mentra-live-ota-3.4.0-dev.1171.json",
|
|
19
|
+
"otaManifestSha256": "97b0fb26591041a9562ab648d1a66f0d8fc75ea75a8bc047a1958effe8f06382"
|
|
20
20
|
})
|
package/src/index.ts
CHANGED
|
@@ -26,6 +26,8 @@ const PUBLIC_EVENT_NAMES = new Set<BluetoothSdkEventName>([
|
|
|
26
26
|
"speaking_status",
|
|
27
27
|
"battery_status",
|
|
28
28
|
"local_transcription",
|
|
29
|
+
"wake_word",
|
|
30
|
+
"speech_activity",
|
|
29
31
|
"wifi_status_change",
|
|
30
32
|
"wifi_scan_result",
|
|
31
33
|
"wifi_forget_result",
|
|
@@ -192,7 +194,10 @@ export const BluetoothSdk: BluetoothSdkPublicModule = Object.freeze({
|
|
|
192
194
|
checkSttModelAvailable: bindPublicMethod("checkSttModelAvailable"),
|
|
193
195
|
validateSttModel: bindPublicMethod("validateSttModel"),
|
|
194
196
|
extractTarBz2: bindPublicMethod("extractTarBz2"),
|
|
197
|
+
setWakeWordDetection: bindPublicMethod("setWakeWordDetection"),
|
|
198
|
+
finishTranscription: bindPublicMethod("finishTranscription"),
|
|
195
199
|
restartTranscriber: bindPublicMethod("restartTranscriber"),
|
|
200
|
+
setSpeechActivityDetection: bindPublicMethod("setSpeechActivityDetection"),
|
|
196
201
|
setTtsModelDetails: bindPublicMethod("setTtsModelDetails"),
|
|
197
202
|
getTtsModelPath: bindPublicMethod("getTtsModelPath"),
|
|
198
203
|
getTtsModelLanguage: bindPublicMethod("getTtsModelLanguage"),
|
|
@@ -258,6 +263,8 @@ export type {
|
|
|
258
263
|
GlassesSessionChangedEvent,
|
|
259
264
|
KeepAliveAckEvent,
|
|
260
265
|
LocalTranscriptionEvent,
|
|
266
|
+
WakeWordEvent,
|
|
267
|
+
SpeechActivityEvent,
|
|
261
268
|
LogEvent,
|
|
262
269
|
MicLc3Event,
|
|
263
270
|
MicHealthEvent,
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
Copyright 2023 Georgiy Konovalov
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
|
|
5
|
-
associated documentation files (the "Software"), to deal in the Software without restriction,
|
|
6
|
-
including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
7
|
-
and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
|
|
8
|
-
subject to the following conditions:
|
|
9
|
-
|
|
10
|
-
The above copyright notice and this permission notice shall be included in all copies or substantial
|
|
11
|
-
portions of the Software.
|
|
12
|
-
|
|
13
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
|
|
14
|
-
NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
15
|
-
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
16
|
-
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
17
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
// Vendored from https://github.com/gkonovalov/android-vad (silero module, v2.0.10)
|
|
2
|
-
// Consumed in-place by the bluetooth-sdk so we can pin ORT to a version that
|
|
3
|
-
// matches our other ORT consumer (sherpa-onnx) without depending on a Jitpack
|
|
4
|
-
// AAR whose prebuilt JNI was built against a different ORT.
|
|
5
|
-
plugins {
|
|
6
|
-
id 'com.android.library'
|
|
7
|
-
id 'kotlin-android'
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
android {
|
|
11
|
-
namespace "com.konovalov.vad.silero"
|
|
12
|
-
compileSdk 36
|
|
13
|
-
|
|
14
|
-
defaultConfig {
|
|
15
|
-
minSdkVersion 24
|
|
16
|
-
targetSdkVersion 36
|
|
17
|
-
|
|
18
|
-
ndk {
|
|
19
|
-
// Honor reactNativeArchitectures (dev CI is arm64-only; staging
|
|
20
|
-
// production sets all four ABIs) so this module does not keep
|
|
21
|
-
// compiling every ABI on a filtered build.
|
|
22
|
-
def abiList = (findProperty("reactNativeArchitectures") ?: "armeabi-v7a,arm64-v8a,x86,x86_64")
|
|
23
|
-
.toString()
|
|
24
|
-
.split(",")
|
|
25
|
-
.collect { it.trim() }
|
|
26
|
-
.findAll { !it.isEmpty() }
|
|
27
|
-
abiFilters(*abiList)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
aaptOptions {
|
|
32
|
-
noCompress "onnx"
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
compileOptions {
|
|
36
|
-
sourceCompatibility JavaVersion.VERSION_17
|
|
37
|
-
targetCompatibility JavaVersion.VERSION_17
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
kotlinOptions {
|
|
41
|
-
jvmTarget = '17'
|
|
42
|
-
}
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
dependencies {
|
|
46
|
-
// 1.24.3 matches the ORT version sherpa-onnx 1.13.2 was built against, so
|
|
47
|
-
// both consumers can share a single libonnxruntime.so (same versioned
|
|
48
|
-
// OrtGetApiBase@@VERS_1.24.3 symbol). Keep these versions in lockstep.
|
|
49
|
-
implementation 'com.microsoft.onnxruntime:onnxruntime-android:1.24.3'
|
|
50
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
# Add project specific ProGuard rules here.
|
|
2
|
-
# You can control the set of applied configuration files using the
|
|
3
|
-
# proguardFiles setting in build.gradle.
|
|
4
|
-
#
|
|
5
|
-
# For more details, see
|
|
6
|
-
# http://developer.android.com/guide/developing/tools/proguard.html
|
|
7
|
-
|
|
8
|
-
# If your project uses WebView with JS, uncomment the following
|
|
9
|
-
# and specify the fully qualified class name to the JavaScript interface
|
|
10
|
-
# class:
|
|
11
|
-
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
|
|
12
|
-
# public *;
|
|
13
|
-
#}
|
|
14
|
-
|
|
15
|
-
# Uncomment this to preserve the line number information for
|
|
16
|
-
# debugging stack traces.
|
|
17
|
-
#-keepattributes SourceFile,LineNumberTable
|
|
18
|
-
|
|
19
|
-
# If you keep the line number information, uncomment this to
|
|
20
|
-
# hide the original source file name.
|
|
21
|
-
#-renamesourcefileattribute SourceFile
|
|
22
|
-
-keep class ai.onnxruntime.** {*;}
|
|
23
|
-
-keep class com.konovalov.vad.** {*;}
|
|
24
|
-
-dontwarn com.google.**
|
|
Binary file
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
package com.konovalov.silero
|
|
2
|
-
|
|
3
|
-
import android.content.Context
|
|
4
|
-
import androidx.test.ext.junit.runners.AndroidJUnit4
|
|
5
|
-
import androidx.test.platform.app.InstrumentationRegistry
|
|
6
|
-
import com.konovalov.vad.silero.Vad
|
|
7
|
-
import com.konovalov.vad.silero.VadSilero
|
|
8
|
-
import com.konovalov.vad.silero.config.FrameSize
|
|
9
|
-
import com.konovalov.vad.silero.config.Mode
|
|
10
|
-
import com.konovalov.vad.silero.config.SampleRate
|
|
11
|
-
import junit.framework.TestCase.assertEquals
|
|
12
|
-
import org.junit.After
|
|
13
|
-
import org.junit.Before
|
|
14
|
-
import org.junit.Test
|
|
15
|
-
import org.junit.runner.RunWith
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Created by Georgiy Konovalov on 12/22/2023.
|
|
20
|
-
*
|
|
21
|
-
* Instrumented test for VadSilero class.
|
|
22
|
-
*/
|
|
23
|
-
@RunWith(AndroidJUnit4::class)
|
|
24
|
-
class VadSileroTest {
|
|
25
|
-
|
|
26
|
-
private lateinit var vad: VadSilero
|
|
27
|
-
private lateinit var testContext: Context
|
|
28
|
-
|
|
29
|
-
@Before
|
|
30
|
-
fun setUp() {
|
|
31
|
-
this.testContext = InstrumentationRegistry.getInstrumentation().context
|
|
32
|
-
|
|
33
|
-
this.vad = Vad.builder()
|
|
34
|
-
.setContext(testContext)
|
|
35
|
-
.setSampleRate(SampleRate.SAMPLE_RATE_16K)
|
|
36
|
-
.setFrameSize(FrameSize.FRAME_SIZE_512)
|
|
37
|
-
.setMode(Mode.VERY_AGGRESSIVE)
|
|
38
|
-
.build()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
@After
|
|
42
|
-
fun shutdown() {
|
|
43
|
-
vad.close()
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
@Test
|
|
47
|
-
fun testIsSpeech() {
|
|
48
|
-
// List for VAD results
|
|
49
|
-
val actualResult = mutableListOf<Boolean>()
|
|
50
|
-
|
|
51
|
-
// List with expected VAD results
|
|
52
|
-
val expectedResult = listOf(
|
|
53
|
-
false, false, false, false, false,
|
|
54
|
-
false, true, true, true, true,
|
|
55
|
-
true, true, true, true, true,
|
|
56
|
-
true, true, true, false, false
|
|
57
|
-
)
|
|
58
|
-
|
|
59
|
-
// Buffer size should be 2x for ByteArray
|
|
60
|
-
val chunkSize = vad.frameSize.value * 2
|
|
61
|
-
|
|
62
|
-
// Reading audio data from test file
|
|
63
|
-
testContext.assets.open("hello.wav").buffered().use { input ->
|
|
64
|
-
// Skip WAV Header
|
|
65
|
-
input.skip(44)
|
|
66
|
-
|
|
67
|
-
while (input.available() > 0) {
|
|
68
|
-
// Read audio Frame
|
|
69
|
-
val frameChunk = ByteArray(chunkSize).apply { input.read(this) }
|
|
70
|
-
|
|
71
|
-
// Save interference result
|
|
72
|
-
actualResult.add(vad.isSpeech(frameChunk))
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Compare expectedResult with actualResult
|
|
77
|
-
assertEquals(expectedResult, actualResult)
|
|
78
|
-
}
|
|
79
|
-
}
|
|
@@ -1,160 +0,0 @@
|
|
|
1
|
-
package com.konovalov.vad.silero
|
|
2
|
-
|
|
3
|
-
import android.content.Context
|
|
4
|
-
import com.konovalov.vad.silero.config.FrameSize
|
|
5
|
-
import com.konovalov.vad.silero.config.Mode
|
|
6
|
-
import com.konovalov.vad.silero.config.SampleRate
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Created by Georgiy Konovalov on 6/26/2023.
|
|
10
|
-
*
|
|
11
|
-
* The Silero VAD algorithm, based on DNN, analyzes the audio signal to determine whether it
|
|
12
|
-
* contains speech or non-speech segments. It offers higher accuracy in differentiating speech from
|
|
13
|
-
* background noise compared to the WebRTC VAD algorithm.
|
|
14
|
-
*
|
|
15
|
-
* The Silero VAD supports the following parameters:
|
|
16
|
-
*
|
|
17
|
-
* Sample Rates:
|
|
18
|
-
*
|
|
19
|
-
* 8000Hz,
|
|
20
|
-
* 16000Hz
|
|
21
|
-
*
|
|
22
|
-
* Frame Sizes (per sample rate):
|
|
23
|
-
*
|
|
24
|
-
* For 8000Hz: 80, 160, 240
|
|
25
|
-
* For 16000Hz: 160, 320, 480
|
|
26
|
-
*
|
|
27
|
-
* Mode:
|
|
28
|
-
*
|
|
29
|
-
* NORMAL,
|
|
30
|
-
* LOW_BITRATE,
|
|
31
|
-
* AGGRESSIVE,
|
|
32
|
-
* VERY_AGGRESSIVE
|
|
33
|
-
*
|
|
34
|
-
* Please note that the VAD class supports these specific combinations of sample
|
|
35
|
-
* rates and frame sizes, and the classifiers determine the aggressiveness of the voice
|
|
36
|
-
* activity detection algorithm.
|
|
37
|
-
*
|
|
38
|
-
* @param context is required for reading the model file from file system.
|
|
39
|
-
* @param sampleRate is required for processing audio input.
|
|
40
|
-
* @param frameSize is required for processing audio input.
|
|
41
|
-
* @param mode is required for the VAD model.
|
|
42
|
-
* @param speechDurationMs is minimum duration in milliseconds for speech segments (optional).
|
|
43
|
-
* @param silenceDurationMs is minimum duration in milliseconds for silence segments (optional).
|
|
44
|
-
*/
|
|
45
|
-
class Vad private constructor() {
|
|
46
|
-
private lateinit var context: Context
|
|
47
|
-
private lateinit var sampleRate: SampleRate
|
|
48
|
-
private lateinit var frameSize: FrameSize
|
|
49
|
-
private lateinit var mode: Mode
|
|
50
|
-
private var speechDurationMs = 0
|
|
51
|
-
private var silenceDurationMs = 0
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Set Context for Vad Model.
|
|
55
|
-
*
|
|
56
|
-
* @param context is required for accessing the model file.
|
|
57
|
-
*/
|
|
58
|
-
fun setContext(context: Context): Vad = apply {
|
|
59
|
-
this.context = context.applicationContext ?: context
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Set, retrieve and validate sample rate for Vad Model.
|
|
64
|
-
*
|
|
65
|
-
* Valid Sample Rates:
|
|
66
|
-
*
|
|
67
|
-
* 8000Hz,
|
|
68
|
-
* 16000Hz
|
|
69
|
-
*
|
|
70
|
-
* @param sampleRate is required for processing audio input.
|
|
71
|
-
*/
|
|
72
|
-
fun setSampleRate(sampleRate: SampleRate): Vad = apply {
|
|
73
|
-
this.sampleRate = sampleRate
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Set, retrieve and validate frame size for Vad Model.
|
|
78
|
-
*
|
|
79
|
-
* Valid Frame Sizes (per sample rate):
|
|
80
|
-
*
|
|
81
|
-
* For 8000Hz: 256, 512, 768
|
|
82
|
-
* For 16000Hz: 512, 1024, 1536
|
|
83
|
-
*
|
|
84
|
-
* @param frameSize is required for processing audio input.
|
|
85
|
-
*/
|
|
86
|
-
fun setFrameSize(frameSize: FrameSize): Vad = apply {
|
|
87
|
-
this.frameSize = frameSize
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Set and retrieve detection mode for Vad model.
|
|
92
|
-
*
|
|
93
|
-
* Mode:
|
|
94
|
-
*
|
|
95
|
-
* NORMAL,
|
|
96
|
-
* LOW_BITRATE,
|
|
97
|
-
* AGGRESSIVE,
|
|
98
|
-
* VERY_AGGRESSIVE
|
|
99
|
-
*
|
|
100
|
-
* @param mode is required for the VAD model.
|
|
101
|
-
*/
|
|
102
|
-
fun setMode(mode: Mode): Vad = apply {
|
|
103
|
-
this.mode = mode
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
/**
|
|
107
|
-
* Set the minimum duration in milliseconds for speech segments.
|
|
108
|
-
* The value of this parameter will define the necessary and sufficient duration of positive
|
|
109
|
-
* results to recognize result as speech. This parameter is optional.
|
|
110
|
-
*
|
|
111
|
-
* Permitted range (0ms >= speechDurationMs <= 300000ms).
|
|
112
|
-
*
|
|
113
|
-
* Parameters used for {@link VadSilero.isSpeech}.
|
|
114
|
-
*
|
|
115
|
-
* @param speechDurationMs minimum duration in milliseconds for speech segments.
|
|
116
|
-
*/
|
|
117
|
-
fun setSpeechDurationMs(speechDurationMs: Int): Vad = apply {
|
|
118
|
-
this.speechDurationMs = speechDurationMs
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/**
|
|
122
|
-
* Set the minimum duration in milliseconds for silence segments.
|
|
123
|
-
* The value of this parameter will define the necessary and sufficient duration of
|
|
124
|
-
* negative results to recognize it as silence. This parameter is optional.
|
|
125
|
-
*
|
|
126
|
-
* Permitted range (0ms >= silenceDurationMs <= 300000ms).
|
|
127
|
-
*
|
|
128
|
-
* Parameters used in {@link VadSilero.isSpeech}.
|
|
129
|
-
*
|
|
130
|
-
* @param silenceDurationMs minimum duration in milliseconds for silence segments.
|
|
131
|
-
*/
|
|
132
|
-
fun setSilenceDurationMs(silenceDurationMs: Int): Vad = apply {
|
|
133
|
-
this.silenceDurationMs = silenceDurationMs
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
/**
|
|
137
|
-
* Builds and returns a VadModel instance based on the specified parameters.
|
|
138
|
-
*
|
|
139
|
-
* @return constructed VadSilero model.
|
|
140
|
-
* @throws IllegalArgumentException if invalid parameters have been set for the model.
|
|
141
|
-
* @throws OrtException if the model failed to parse, wasn't compatible or caused an error.
|
|
142
|
-
*/
|
|
143
|
-
fun build(): VadSilero {
|
|
144
|
-
return VadSilero(
|
|
145
|
-
context,
|
|
146
|
-
sampleRate,
|
|
147
|
-
frameSize,
|
|
148
|
-
mode,
|
|
149
|
-
speechDurationMs,
|
|
150
|
-
silenceDurationMs
|
|
151
|
-
)
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
companion object {
|
|
155
|
-
@JvmStatic
|
|
156
|
-
fun builder(): Vad {
|
|
157
|
-
return Vad()
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
}
|