diff --git a/app/src/main/java/com/mjm/whisperVoiceRecognition/Wizard.java b/app/src/main/java/com/mjm/whisperVoiceRecognition/Wizard.java index 7b1986c..59d0e81 100644 --- a/app/src/main/java/com/mjm/whisperVoiceRecognition/Wizard.java +++ b/app/src/main/java/com/mjm/whisperVoiceRecognition/Wizard.java @@ -5,6 +5,7 @@ import android.os.Bundle; import android.provider.Settings; import android.widget.Button; +import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; import androidx.core.app.ActivityCompat; @@ -31,6 +32,7 @@ protected void onCreate(Bundle savedInstanceState) { }); btnExit.setOnClickListener(v -> { + Toast.makeText(this, R.string.wizard_completed, Toast.LENGTH_LONG).show(); finish(); }); } diff --git a/app/src/main/jniLibs/arm64-v8a/librust.so b/app/src/main/jniLibs/arm64-v8a/librust.so index 5585baa..5fc7d55 100755 Binary files a/app/src/main/jniLibs/arm64-v8a/librust.so and b/app/src/main/jniLibs/arm64-v8a/librust.so differ diff --git a/app/src/main/jniLibs/x86_64/librust.so b/app/src/main/jniLibs/x86_64/librust.so index c4b5883..912ce2a 100755 Binary files a/app/src/main/jniLibs/x86_64/librust.so and b/app/src/main/jniLibs/x86_64/librust.so differ diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index ce16d18..0eba722 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -13,8 +13,9 @@ Delete Key Record Audio Permission Denied! Microphone Permission Denied. Grant? - Enable Input Method + 1. Enable Input Method Please Grant Microphone Permission - Grant Microphone Permission - Exit + Keyboard Now Available In Keyboard Switcher + 2. Grant Microphone Permission + Done! \ No newline at end of file diff --git a/app/src/main/rust/Cargo.lock b/app/src/main/rust/Cargo.lock index 1a7dbcb..d689bc2 100644 --- a/app/src/main/rust/Cargo.lock +++ b/app/src/main/rust/Cargo.lock @@ -45,16 +45,6 @@ version = "1.0.66" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "216261ddc8289130e551ddcd5ce8a064710c0d064a4d2895c67151c92b5443f6" -[[package]] -name = "apodize" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d9b24c7c750c13dbded968ba2d659ed9cd582b4651d6afdb5d3756cedd56cc8" -dependencies = [ - "nalgebra 0.5.1", - "num", -] - [[package]] name = "approx" version = "0.5.1" @@ -116,40 +106,6 @@ dependencies = [ "memchr", ] -[[package]] -name = "crossbeam-channel" -version = "0.5.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c2dd04ddaf88237dc3b8d8f9a3c1004b506b54b3313403944054d23c0870c521" -dependencies = [ - "cfg-if", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-deque" -version = "0.8.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "715e8152b692bba2d374b53d4875445368fdf21a94751410af607a5ac677d1fc" -dependencies = [ - "cfg-if", - "crossbeam-epoch", - "crossbeam-utils", -] - -[[package]] -name = "crossbeam-epoch" -version = "0.9.13" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "01a9af1f4c2ef74bb8aa1f7e19706bc72d03598c8a570bb5de72243c7a9d9d5a" -dependencies = [ - "autocfg", - "cfg-if", - "crossbeam-utils", - "memoffset", - "scopeguard", -] - [[package]] name = "crossbeam-queue" version = "0.3.8" @@ -175,12 +131,6 @@ version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35" -[[package]] -name = "either" -version = "1.8.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" - [[package]] name = "env_logger" version = "0.9.3" @@ -191,75 +141,6 @@ dependencies = [ "regex", ] -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - -[[package]] -name = "getrandom" -version = "0.2.8" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c05aeb6a22b8f62540c194aac980f2115af067bfe15a0734d7277a768d396b31" -dependencies = [ - "cfg-if", - "libc", - "wasi 0.11.0+wasi-snapshot-preview1", -] - -[[package]] -name = "hashbrown" -version = "0.12.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" - -[[package]] -name = "hermit-abi" -version = "0.1.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" -dependencies = [ - "libc", -] - -[[package]] -name = "hertz" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "83b3729e1f272a3d880f43ba013214d1391491be843b79ac976aa114fb19c023" -dependencies = [ - "time", -] - -[[package]] -name = "indexmap" -version = "1.9.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1885e79c1fc4b10f0e172c475f458b7f7b93061064d98c3293e98c5ba0c8b399" -dependencies = [ - "autocfg", - "hashbrown", -] - -[[package]] -name = "itertools" -version = "0.10.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b0fd2260e829bddf4cb6ea802289de2f86d6a7a690192fbe91b3f46e0f2c8473" -dependencies = [ - "either", -] - -[[package]] -name = "itertools-num" -version = "0.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a872a22f9e6f7521ca557660adb96dd830e54f0f490fa115bb55dd69d38b27e7" -dependencies = [ - "num-traits", -] - [[package]] name = "jni" version = "0.20.0" @@ -286,12 +167,6 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" -[[package]] -name = "libc" -version = "0.2.138" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "db6d7e329c562c5dfab7a46a2afabc8b987ab9a4834c9d1ca04dc54c1546cef8" - [[package]] name = "log" version = "0.4.17" @@ -310,44 +185,12 @@ dependencies = [ "rawpointer", ] -[[package]] -name = "mel" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7365422d82b05f32ecf446661db75f3c7d47a2c069ef87ec0aae8b80ccff8223" -dependencies = [ - "apodize", - "hertz", - "itertools-num", - "num", -] - [[package]] name = "memchr" version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" -[[package]] -name = "memoffset" -version = "0.7.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5de893c32cde5f383baa4c04c5d6dbdd735cfd4a794b0debdb2bb1b421da5ff4" -dependencies = [ - "autocfg", -] - -[[package]] -name = "nalgebra" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "23df3566842762acc29ee6beca8c1e0435a15acdf3bba5be25aafd6af70271c7" -dependencies = [ - "num", - "rand 0.3.23", - "rustc-serialize", -] - [[package]] name = "nalgebra" version = "0.31.4" @@ -357,8 +200,8 @@ dependencies = [ "approx", "matrixmultiply", "nalgebra-macros", - "num-complex 0.4.2", - "num-rational 0.4.1", + "num-complex", + "num-rational", "num-traits", "simba", "typenum", @@ -375,46 +218,6 @@ dependencies = [ "syn", ] -[[package]] -name = "ndarray" -version = "0.15.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "adb12d4e967ec485a5f71c6311fe28158e9d6f4bc4a447b474184d0f91a8fa32" -dependencies = [ - "approx", - "matrixmultiply", - "num-complex 0.4.2", - "num-integer", - "num-traits", - "rawpointer", -] - -[[package]] -name = "ndarray-ndimage" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6dfeb99dba9eaf1d8c65706a27fb261df38bcd5b7f76f3bba2566623e81a833a" -dependencies = [ - "ndarray", - "ndarray-stats", - "num-traits", -] - -[[package]] -name = "ndarray-stats" -version = "0.5.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "af5a8477ac96877b5bd1fd67e0c28736c12943aba24eda92b127e036b0c8f400" -dependencies = [ - "indexmap", - "itertools", - "ndarray", - "noisy_float", - "num-integer", - "num-traits", - "rand 0.8.5", -] - [[package]] name = "ndk" version = "0.7.0" @@ -438,51 +241,6 @@ dependencies = [ "jni-sys", ] -[[package]] -name = "noisy_float" -version = "0.2.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "978fe6e6ebc0bf53de533cd456ca2d9de13de13856eda1518a285d7705a213af" -dependencies = [ - "num-traits", -] - -[[package]] -name = "num" -version = "0.1.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4703ad64153382334aa8db57c637364c322d3372e097840c72000dabdcf6156e" -dependencies = [ - "num-bigint", - "num-complex 0.1.43", - "num-integer", - "num-iter", - "num-rational 0.1.42", - "num-traits", -] - -[[package]] -name = "num-bigint" -version = "0.1.44" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e63899ad0da84ce718c14936262a41cee2c79c981fc0a0e7c7beb47d5a07e8c1" -dependencies = [ - "num-integer", - "num-traits", - "rand 0.4.6", - "rustc-serialize", -] - -[[package]] -name = "num-complex" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b288631d7878aaf59442cffd36910ea604ecd7745c36054328595114001c9656" -dependencies = [ - "num-traits", - "rustc-serialize", -] - [[package]] name = "num-complex" version = "0.4.2" @@ -502,29 +260,6 @@ dependencies = [ "num-traits", ] -[[package]] -name = "num-iter" -version = "0.1.43" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d03e6c028c5dc5cac6e2dec0efda81fc887605bb3d884578bb6d6bf7514e252" -dependencies = [ - "autocfg", - "num-integer", - "num-traits", -] - -[[package]] -name = "num-rational" -version = "0.1.42" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ee314c74bd753fc86b4780aa9475da469155f3848473a261d2d18e35245a784e" -dependencies = [ - "num-bigint", - "num-integer", - "num-traits", - "rustc-serialize", -] - [[package]] name = "num-rational" version = "0.4.1" @@ -545,16 +280,6 @@ dependencies = [ "autocfg", ] -[[package]] -name = "num_cpus" -version = "1.14.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6058e64324c71e02bc2b150e4f3bc8286db6c83092132ffa3f6b1eab0f9def5" -dependencies = [ - "hermit-abi", - "libc", -] - [[package]] name = "num_enum" version = "0.5.7" @@ -584,9 +309,9 @@ checksum = "86f0b0d4bf799edbc74508c1e8bf170ff5f41238e5f8225603ca7caaae2b7860" [[package]] name = "paste" -version = "1.0.9" +version = "1.0.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b1de2e551fb905ac83f73f7aedf2f0cb4a0da7e35efa24a202a936269f1f18e1" +checksum = "d01a5bd0424d00070b0098dd17ebca6f961a959dead1dbcbbbc1d1cd8d3deeba" [[package]] name = "pkg-config" @@ -594,12 +319,6 @@ version = "0.3.26" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" -[[package]] -name = "ppv-lite86" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de" - [[package]] name = "primal-check" version = "0.3.3" @@ -638,74 +357,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.3.23" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "64ac302d8f83c0c1974bf758f6b041c6c8ada916fbb44a609158ca8b064cc76c" -dependencies = [ - "libc", - "rand 0.4.6", -] - -[[package]] -name = "rand" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" -dependencies = [ - "fuchsia-cprng", - "libc", - "rand_core 0.3.1", - "rdrand", - "winapi", -] - -[[package]] -name = "rand" -version = "0.8.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" -dependencies = [ - "libc", - "rand_chacha", - "rand_core 0.6.4", -] - -[[package]] -name = "rand_chacha" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" -dependencies = [ - "ppv-lite86", - "rand_core 0.6.4", -] - -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", -] - -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - -[[package]] -name = "rand_core" -version = "0.6.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" -dependencies = [ - "getrandom", -] - [[package]] name = "raw-window-handle" version = "0.5.0" @@ -721,37 +372,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "60a357793950651c4ed0f3f52338f53b2f809f32d83a07f72909fa13e4c6c1e3" -[[package]] -name = "rayon" -version = "1.6.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6db3a213adf02b3bcfd2d3846bb41cb22857d131789e01df434fb7e7bc0759b7" -dependencies = [ - "either", - "rayon-core", -] - -[[package]] -name = "rayon-core" -version = "1.10.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "cac410af5d00ab6884528b4ab69d1e8e146e8d471201800fa1b4524126de6ad3" -dependencies = [ - "crossbeam-channel", - "crossbeam-deque", - "crossbeam-utils", - "num_cpus", -] - -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "regex" version = "1.7.0" @@ -779,29 +399,19 @@ dependencies = [ "crossbeam-queue", "jni", "log", - "mel", - "nalgebra 0.31.4", - "ndarray", - "ndarray-ndimage", + "nalgebra", "ndk", "ndk-sys", - "rayon", "rustfft", ] -[[package]] -name = "rustc-serialize" -version = "0.3.24" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf128d1287d2ea9d80910b5f1120d0b8eede3fbf1abe91c40d39ea7d51e6fda" - [[package]] name = "rustfft" version = "6.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e17d4f6cbdb180c9f4b2a26bbf01c4e647f1e1dea22fe8eb9db54198b32f9434" dependencies = [ - "num-complex 0.4.2", + "num-complex", "num-integer", "num-traits", "primal-check", @@ -828,12 +438,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "scopeguard" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd" - [[package]] name = "serde" version = "1.0.149" @@ -847,7 +451,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2f3fd720c48c53cace224ae62bef1bbff363a70c68c4802a78b5cc6159618176" dependencies = [ "approx", - "num-complex 0.4.2", + "num-complex", "num-traits", "paste", "wide", @@ -890,17 +494,6 @@ dependencies = [ "syn", ] -[[package]] -name = "time" -version = "0.1.45" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1b797afad3f312d1c66a56d11d0316f916356d11bd158fbc6ca6389ff6bf805a" -dependencies = [ - "libc", - "wasi 0.10.0+wasi-snapshot-preview1", - "winapi", -] - [[package]] name = "toml" version = "0.5.9" @@ -922,9 +515,9 @@ dependencies = [ [[package]] name = "typenum" -version = "1.15.0" +version = "1.16.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dcf81ac59edc17cc8697ff311e8f5ef2d99fcbd9817b34cec66f90b6c3dfd987" +checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba" [[package]] name = "unicode-ident" @@ -949,18 +542,6 @@ dependencies = [ "winapi-util", ] -[[package]] -name = "wasi" -version = "0.10.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1a143597ca7c7793eff794def352d41792a93c481eb1042423ff7ff72ba2c31f" - -[[package]] -name = "wasi" -version = "0.11.0+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" - [[package]] name = "wide" version = "0.7.5" diff --git a/app/src/main/rust/Cargo.toml b/app/src/main/rust/Cargo.toml index 00c344b..785172f 100644 --- a/app/src/main/rust/Cargo.toml +++ b/app/src/main/rust/Cargo.toml @@ -7,20 +7,16 @@ edition = "2021" [dependencies] jni = { version = "0.20.0"} ndk = { version= "0.7.0", features = ["api-level-30", "audio"]} -ndk-sys = "0.4.1+23.1.7779620" +ndk-sys = "0.4.0" android_logger = "0.11.1" log = "0.4.17" anyhow= "1.0.66" -mel = "0.3.0" nalgebra ="0.31.4" crossbeam-queue="0.3.8" rustfft = "6.1.0" -ndarray="0.15.6" -ndarray-ndimage= "0.3.0" -rayon = "1.6.1" ac-ffmpeg = { git = "https://github.com/MichaelMcCulloch/rust-ac-ffmpeg", branch="master"} [profile.release] diff --git a/app/src/main/rust/proof.png b/app/src/main/rust/proof.png deleted file mode 100644 index 014c317..0000000 Binary files a/app/src/main/rust/proof.png and /dev/null differ diff --git a/app/src/main/rust/src/spectrogram.rs b/app/src/main/rust/src/spectrogram.rs index ca6e175..0429707 100644 --- a/app/src/main/rust/src/spectrogram.rs +++ b/app/src/main/rust/src/spectrogram.rs @@ -1,24 +1,13 @@ use std::sync::Arc; use crate::{ - lina::dot_product, mel::compute_mel, statics::WHISPER_FILTERS, + consts::{FFT_LEN, MEL_LEN, N_FFT, N_MEL_BINS}, + mel::compute_mel, + statics::WHISPER_FILTERS, work_buffer::populate_working_buffers, }; -use nalgebra::Complex; -use ndk_sys::exit; -use rayon::prelude::*; -use rustfft::{num_complex::Complex32, num_traits::Zero, Fft}; - -const SAMPLE_RATE: usize = 16000; -const RECORDING_LEN: usize = 30; -const N_FFT: usize = 201; -const FFT_LEN: usize = 400; - -const N_MEL_BINS: usize = 80; -const MEL_LEN: usize = 3000; - -const HOP_LENGTH: usize = 160; +use rustfft::{num_complex::Complex32, Fft}; /// This method is used to generate a log mel spectrogram from a given `f32le_audio` vector. It does this by applying a window function and using an FFT process to compute the power spectrum, before computing the logmel spectrogram. ///