move audio toolkit into src-tauri to fix permissions

This commit is contained in:
CJ Pais 2025-07-10 12:38:06 -07:00
parent 0c927d2a70
commit 59541b8ec4
19 changed files with 105 additions and 7736 deletions

2
.gitignore vendored
View file

@ -23,7 +23,5 @@ dist-ssr
*.sln
*.sw?
src-tauri/resources/models
/target/
recording_*

7696
Cargo.lock generated

File diff suppressed because it is too large Load diff

View file

@ -1,3 +0,0 @@
[workspace]
members = ["src-tauri", "crates/audio-toolkit"]
resolver = "2"

View file

@ -1,20 +0,0 @@
[package]
name = "audio-toolkit"
version = "0.1.0"
edition = "2024"
description = "Audio recording and processing toolkit for Handy"
authors = ["cjpais"]
[[bin]]
name = "cli"
path = "src/bin/cli.rs"
[dependencies]
anyhow = "1.0.98"
cpal = "0.16.0"
hound = "3.5.1"
rubato = "0.16.2"
vad-rs = "0.1.5"
[dependencies.ort-sys]
version = "=2.0.0-rc.9"

89
src-tauri/Cargo.lock generated
View file

@ -895,6 +895,20 @@ dependencies = [
"coreaudio-sys",
]
[[package]]
name = "coreaudio-rs"
version = "0.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1aae284fbaf7d27aa0e292f7677dfbe26503b0d555026f702940805a630eac17"
dependencies = [
"bitflags 1.3.2",
"libc",
"objc2-audio-toolbox",
"objc2-core-audio",
"objc2-core-audio-types",
"objc2-core-foundation",
]
[[package]]
name = "coreaudio-sys"
version = "0.2.16"
@ -912,7 +926,7 @@ checksum = "873dab07c8f743075e57f524c583985fbaf745602acbe916a01539364369a779"
dependencies = [
"alsa",
"core-foundation-sys",
"coreaudio-rs",
"coreaudio-rs 0.11.3",
"dasp_sample",
"jni",
"js-sys",
@ -927,6 +941,32 @@ dependencies = [
"windows 0.54.0",
]
[[package]]
name = "cpal"
version = "0.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cbd307f43cc2a697e2d1f8bc7a1d824b5269e052209e28883e5bc04d095aaa3f"
dependencies = [
"alsa",
"coreaudio-rs 0.13.0",
"dasp_sample",
"jni",
"js-sys",
"libc",
"mach2",
"ndk 0.9.0",
"ndk-context",
"num-derive",
"num-traits",
"objc2-audio-toolbox",
"objc2-core-audio",
"objc2-core-audio-types",
"wasm-bindgen",
"wasm-bindgen-futures",
"web-sys",
"windows 0.54.0",
]
[[package]]
name = "cpufeatures"
version = "0.2.17"
@ -2029,12 +2069,14 @@ name = "handy"
version = "0.2.3"
dependencies = [
"anyhow",
"cpal",
"cpal 0.16.0",
"enigo",
"env_logger",
"futures-util",
"hound",
"log",
"once_cell",
"ort-sys",
"rdev",
"reqwest 0.11.27",
"rodio",
@ -3268,6 +3310,21 @@ dependencies = [
"objc2-quartz-core 0.3.1",
]
[[package]]
name = "objc2-audio-toolbox"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "10cbe18d879e20a4aea544f8befe38bcf52255eb63d3f23eca2842f3319e4c07"
dependencies = [
"bitflags 2.8.0",
"libc",
"objc2 0.6.1",
"objc2-core-audio",
"objc2-core-audio-types",
"objc2-core-foundation",
"objc2-foundation 0.3.1",
]
[[package]]
name = "objc2-cloud-kit"
version = "0.3.1"
@ -3279,6 +3336,28 @@ dependencies = [
"objc2-foundation 0.3.1",
]
[[package]]
name = "objc2-core-audio"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ca44961e888e19313b808f23497073e3f6b3c22bb485056674c8b49f3b025c82"
dependencies = [
"dispatch2",
"objc2 0.6.1",
"objc2-core-audio-types",
"objc2-core-foundation",
]
[[package]]
name = "objc2-core-audio-types"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c0f1cc99bb07ad2ddb6527ddf83db6a15271bb036b3eb94b801cd44fdc666ee1"
dependencies = [
"bitflags 2.8.0",
"objc2 0.6.1",
]
[[package]]
name = "objc2-core-data"
version = "0.2.2"
@ -4405,7 +4484,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7ceb6607dd738c99bc8cb28eff249b7cd5c8ec88b9db96c0608c1480d140fb1"
dependencies = [
"claxon",
"cpal",
"cpal 0.15.3",
"hound",
"lewton",
"symphonia",
@ -4413,9 +4492,9 @@ dependencies = [
[[package]]
name = "rubato"
version = "0.16.1"
version = "0.16.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdd96992d7e24b3d7f35fdfe02af037a356ac90d41b466945cf3333525a86eea"
checksum = "5258099699851cfd0082aeb645feb9c084d9a5e1f1b8d5372086b989fc5e56a1"
dependencies = [
"num-complex",
"num-integer",

View file

@ -5,6 +5,7 @@ description = "Handy"
authors = ["cjpais"]
edition = "2021"
license = "MIT"
default-run = "handy"
[profile.dev]
incremental = true # Compile your binary in smaller steps.
@ -18,6 +19,10 @@ incremental = true # Compile your binary in smaller steps.
name = "handy_app_lib"
crate-type = ["staticlib", "cdylib", "rlib"]
# [[bin]]
# name = "cli"
# path = "src/audio_toolkit/bin/cli.rs"
[build-dependencies]
tauri-build = { version = "2", features = [] }
@ -30,10 +35,11 @@ serde_json = "1"
tauri-plugin-clipboard-manager = "2"
tauri-plugin-macos-permissions = "2.0.4"
rdev = { git = "https://github.com/rustdesk-org/rdev" }
cpal = "0.15.3"
cpal = "0.16.0"
whisper-rs = { version = "0.13.2", features = ["whisper-cpp-log"] }
anyhow = "1.0.95"
rubato = "0.16.1"
rubato = "0.16.2"
hound = "3.5.1"
env_logger = "0.11.6"
log = "0.4.25"
tokio = "1.43.0"
@ -45,7 +51,6 @@ tauri-plugin-process = "2"
rodio = "0.20.1"
reqwest = { version = "0.11", features = ["json", "stream"] }
futures-util = "0.3"
audio-toolkit = { path = "../crates/audio-toolkit" }
[dependencies.ort-sys]
version = "=2.0.0-rc.9"

Binary file not shown.

View file

@ -9,7 +9,7 @@ use cpal::{
traits::{DeviceTrait, HostTrait, StreamTrait},
};
use crate::{
use crate::audio_toolkit::{
VoiceActivityDetector,
audio::FrameResampler,
constants,

View file

@ -1,7 +1,12 @@
use audio_toolkit::{AudioRecorder, SileroVad, list_input_devices, vad::SmoothedVad};
use hound::WavWriter;
use std::io::{self, Write};
use handy_app_lib::audio_toolkit::{
audio::{list_input_devices, CpalDeviceInfo},
vad::SmoothedVad,
AudioRecorder, SileroVad,
};
#[derive(Debug, Clone, PartialEq)]
enum RecorderMode {
AlwaysOn,
@ -73,7 +78,7 @@ impl RecorderState {
fn start_recording(
&mut self,
device_index: Option<usize>,
devices: &[audio_toolkit::CpalDeviceInfo],
devices: &[CpalDeviceInfo],
) -> Result<(), Box<dyn std::error::Error>> {
if self.is_recording {
return Err("Already recording! Stop the current recording first.".into());
@ -170,7 +175,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
println!("=========================");
print_help();
let silero = SileroVad::new("./src-tauri/resources/models/silero_vad_v4.onnx", 0.5)?;
let silero = SileroVad::new("./resources/models/silero_vad_v4.onnx", 0.5)?;
let smoothed_vad = SmoothedVad::new(Box::new(silero), 15, 15);
let recorder = AudioRecorder::new()?.with_vad(Box::new(smoothed_vad));
let mut state = RecorderState::new(recorder);
@ -324,7 +329,7 @@ fn print_help() {
println!();
}
fn print_devices(devices: &[audio_toolkit::CpalDeviceInfo]) {
fn print_devices(devices: &[CpalDeviceInfo]) {
println!("Available audio devices:");
for (index, device) in devices.iter().enumerate() {
println!(" {}: {}", index, device.name);

View file

@ -4,7 +4,7 @@ use std::path::Path;
use vad_rs::Vad;
use super::{VadFrame, VoiceActivityDetector};
use crate::constants;
use crate::audio_toolkit::constants;
const SILERO_FRAME_MS: u32 = 30;
const SILERO_FRAME_SAMPLES: usize =

View file

@ -1,4 +1,5 @@
mod actions;
pub mod audio_toolkit;
mod commands;
mod managers;
mod settings;

View file

@ -1,5 +1,5 @@
use crate::settings::get_settings;
use audio_toolkit::{vad::SmoothedVad, AudioRecorder, SileroVad};
use crate::audio_toolkit::{vad::SmoothedVad, AudioRecorder, SileroVad};
use log::{debug, info};
use std::sync::{Arc, Mutex};
use std::time::Instant;