basic audio

This commit is contained in:
AnActualEmerald 2022-09-03 04:07:13 -04:00
parent 33054f5e75
commit 57e5fce8f2
Signed by: emerald
GPG Key ID: CC76D6B296CAC8B0
9 changed files with 469 additions and 116 deletions

BIN
public/images/test.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 848 KiB

331
src-tauri/Cargo.lock generated
View File

@ -83,9 +83,9 @@ dependencies = [
[[package]]
name = "anyhow"
version = "1.0.62"
version = "1.0.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1485d4d2cc45e7b201ee3767015c96faa5904387c9d87c6efdd0fb511f12d305"
checksum = "a26fa4d7e3f2eebadf743988fc8aec9fa9a9e82611acafd77c1462ed6262440a"
[[package]]
name = "atk"
@ -111,6 +111,17 @@ dependencies = [
"system-deps 6.0.2",
]
[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8"
dependencies = [
"hermit-abi",
"libc",
"winapi",
]
[[package]]
name = "autocfg"
version = "1.1.0"
@ -141,8 +152,8 @@ dependencies = [
"lazy_static",
"lazycell",
"peeking_take_while",
"proc-macro2",
"quote",
"proc-macro2 1.0.43",
"quote 1.0.21",
"regex",
"rustc-hash",
"shlex",
@ -283,7 +294,10 @@ dependencies = [
name = "cathode-tube"
version = "0.0.0"
dependencies = [
"anyhow",
"cpal",
"env_logger",
"log",
"ray_format",
"serde",
"serde_json",
@ -497,6 +511,7 @@ dependencies = [
"alsa",
"core-foundation-sys",
"coreaudio-rs",
"jack",
"jni 0.19.0",
"js-sys",
"libc",
@ -572,10 +587,10 @@ dependencies = [
"itoa 0.4.8",
"matches",
"phf 0.8.0",
"proc-macro2",
"quote",
"proc-macro2 1.0.43",
"quote 1.0.21",
"smallvec",
"syn",
"syn 1.0.99",
]
[[package]]
@ -584,8 +599,8 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dfae75de57f2b2e85e8768c3ea840fd159c8f33e2b6522c7835b7abac81be16e"
dependencies = [
"quote",
"syn",
"quote 1.0.21",
"syn 1.0.99",
]
[[package]]
@ -594,8 +609,8 @@ version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdffe87e1d521a10f9696f833fe502293ea446d7f256c06128293a4119bdf4cb"
dependencies = [
"quote",
"syn",
"quote 1.0.21",
"syn 1.0.99",
]
[[package]]
@ -622,10 +637,10 @@ checksum = "859d65a907b6852c9361e3185c862aae7fafd2887876799fa55f5f99dc40d610"
dependencies = [
"fnv",
"ident_case",
"proc-macro2",
"quote",
"proc-macro2 1.0.43",
"quote 1.0.21",
"strsim",
"syn",
"syn 1.0.99",
]
[[package]]
@ -635,8 +650,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c972679f83bdf9c42bd905396b6c3588a843a17f0f16dfcfa3e2c5d57441835"
dependencies = [
"darling_core",
"quote",
"syn",
"quote 1.0.21",
"syn 1.0.99",
]
[[package]]
@ -665,10 +680,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4fb810d30a7c1953f91334de7244731fc3f3c10d7fe163338a35b9f640960321"
dependencies = [
"convert_case",
"proc-macro2",
"quote",
"proc-macro2 1.0.43",
"quote 1.0.21",
"rustc_version 0.4.0",
"syn",
"syn 1.0.99",
]
[[package]]
@ -709,6 +724,38 @@ version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd0c93bb4b0c6d9b77f4435b0ae98c24d17f1c45b2ff844c6151a07256ca923b"
[[package]]
name = "dlib"
version = "0.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac1b7517328c04c2aa68422fc60a41b92208182142ed04a25879c26c8f878794"
dependencies = [
"libloading",
]
[[package]]
name = "dlopen"
version = "0.1.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "71e80ad39f814a9abe68583cd50a2d45c8a67561c3361ab8da240587dda80937"
dependencies = [
"dlopen_derive",
"lazy_static",
"libc",
"winapi",
]
[[package]]
name = "dlopen_derive"
version = "0.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f236d9e1b1fbd81cea0f9cbdc8dcc7e8ebcd80e6659cd7cb2ad5f6c05946c581"
dependencies = [
"libc",
"quote 0.6.13",
"syn 0.15.44",
]
[[package]]
name = "dtoa"
version = "0.4.8"
@ -730,6 +777,19 @@ version = "1.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ef6b89e5b37196644d8796de5268852ff179b44e96276cf4290264843743bb7"
[[package]]
name = "env_logger"
version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b2cf0344971ee6c64c31be0d530793fba457d322dfec2810c453d0ef228f9c3"
dependencies = [
"atty",
"humantime",
"log",
"regex",
"termcolor",
]
[[package]]
name = "fastrand"
version = "1.8.0"
@ -881,9 +941,9 @@ version = "0.3.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0db9cce532b0eae2ccf2766ab246f114b56b9cf6d445e00c2549fbc100ca045d"
dependencies = [
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn 1.0.99",
]
[[package]]
@ -1102,9 +1162,9 @@ dependencies = [
"heck 0.4.0",
"proc-macro-crate",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn 1.0.99",
]
[[package]]
@ -1197,9 +1257,9 @@ dependencies = [
"anyhow",
"proc-macro-crate",
"proc-macro-error",
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn 1.0.99",
]
[[package]]
@ -1250,9 +1310,9 @@ dependencies = [
"log",
"mac",
"markup5ever",
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn 1.0.99",
]
[[package]]
@ -1272,6 +1332,12 @@ version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "21dec9db110f5f872ed9699c3ecf50cf16f423502706ba5c72462e28d3157573"
[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "ico"
version = "0.1.0"
@ -1379,6 +1445,34 @@ version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c8af84674fe1f223a982c933a0ee1086ac4d4052aa0fb8060c12c6ad838e754"
[[package]]
name = "jack"
version = "0.9.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1c526d2fb3a79b52ba3459a9ede300393d7a9774e781576b71904fc01be2060"
dependencies = [
"bitflags",
"dlib",
"jack-sys",
"lazy_static",
"libc",
"log",
]
[[package]]
name = "jack-sys"
version = "0.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2f9e233f62be3591634748e2a7ea1966605807e50f2687dd8d4a6b42ae894cd4"
dependencies = [
"dlib",
"dlopen",
"lazy_static",
"libc",
"libloading",
"pkg-config",
]
[[package]]
name = "javascriptcore-rs"
version = "0.16.0"
@ -1723,9 +1817,9 @@ version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "876a53fff98e03a936a674b29568b0e605f06b29372c2489ff4de23f1949743d"
dependencies = [
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn 1.0.99",
]
[[package]]
@ -1795,9 +1889,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3b0498641e53dd6ac1a4f22547548caa6864cc4933784319cd1775271c5a46ce"
dependencies = [
"proc-macro-crate",
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn 1.0.99",
]
[[package]]
@ -2038,9 +2132,9 @@ dependencies = [
"phf_generator 0.8.0",
"phf_shared 0.8.0",
"proc-macro-hack",
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn 1.0.99",
]
[[package]]
@ -2052,9 +2146,9 @@ dependencies = [
"phf_generator 0.10.0",
"phf_shared 0.10.0",
"proc-macro-hack",
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn 1.0.99",
]
[[package]]
@ -2161,9 +2255,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c"
dependencies = [
"proc-macro-error-attr",
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn 1.0.99",
"version_check",
]
@ -2173,8 +2267,8 @@ version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.43",
"quote 1.0.21",
"version_check",
]
@ -2184,6 +2278,15 @@ version = "0.5.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dbf0c48bc1d91375ae5c3cd81e3722dff1abcf81a30960240640d223f59fe0e5"
[[package]]
name = "proc-macro2"
version = "0.4.30"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf3d2011ab5c909338f7887f4fc896d35932e29146c12c8d01da6b22a80ba759"
dependencies = [
"unicode-xid",
]
[[package]]
name = "proc-macro2"
version = "1.0.43"
@ -2202,13 +2305,22 @@ dependencies = [
"bytemuck",
]
[[package]]
name = "quote"
version = "0.6.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6ce23b6b870e8f94f81fb0a363d65d86675884b34a09043c81e5562f11c1f8e1"
dependencies = [
"proc-macro2 0.4.30",
]
[[package]]
name = "quote"
version = "1.0.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bbe448f377a7d6961e30f5955f9b8d106c3f5e449d493ee1b125c1d43c2b5179"
dependencies = [
"proc-macro2",
"proc-macro2 1.0.43",
]
[[package]]
@ -2502,9 +2614,9 @@ version = "1.0.144"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94ed3a816fb1d101812f83e789f888322c34e291f894f19590dc310963e87a00"
dependencies = [
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn 1.0.99",
]
[[package]]
@ -2524,9 +2636,9 @@ version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1fe39d9fbb0ebf5eb2c7cb7e2a47e4f462fad1379f1166b8ae49ad9eae89a7ca"
dependencies = [
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn 1.0.99",
]
[[package]]
@ -2546,9 +2658,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e182d6ec6f05393cc0e5ed1bf81ad6db3a8feedf8ee515ecdd369809bcce8082"
dependencies = [
"darling",
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn 1.0.99",
]
[[package]]
@ -2568,9 +2680,9 @@ version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74064874e9f6a15f04c1f3cb627902d0e6b410abbf36668afa873c61889f1763"
dependencies = [
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn 1.0.99",
]
[[package]]
@ -2641,6 +2753,16 @@ version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1"
[[package]]
name = "socket2"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02e2d2db9033d13a1567121ddd7a095ee144db4e1ca1b1bda3419bc0da294ebd"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "soup2"
version = "0.2.1"
@ -2712,8 +2834,8 @@ checksum = "6bb30289b722be4ff74a408c3cc27edeaad656e06cb1fe8fa9231fa59c728988"
dependencies = [
"phf_generator 0.10.0",
"phf_shared 0.10.0",
"proc-macro2",
"quote",
"proc-macro2 1.0.43",
"quote 1.0.21",
]
[[package]]
@ -2728,14 +2850,25 @@ version = "2.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6bdef32e8150c2a081110b42772ffe7d7c9032b606bc226c8260fd97e0976601"
[[package]]
name = "syn"
version = "0.15.44"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9ca4b3b69a77cbe1ffc9e198781b7acb0c7365a883670e8f1c1bc66fba79a5c5"
dependencies = [
"proc-macro2 0.4.30",
"quote 0.6.13",
"unicode-xid",
]
[[package]]
name = "syn"
version = "1.0.99"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "58dbef6ec655055e20b86b15a8cc6d439cca19b667537ac6a1369572d151ab13"
dependencies = [
"proc-macro2",
"quote",
"proc-macro2 1.0.43",
"quote 1.0.21",
"unicode-ident",
]
@ -2895,8 +3028,8 @@ dependencies = [
"json-patch",
"plist",
"png 0.17.5",
"proc-macro2",
"quote",
"proc-macro2 1.0.43",
"quote 1.0.21",
"semver 1.0.13",
"serde",
"serde_json",
@ -2915,9 +3048,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7296fa17996629f43081e1c66d554703900187ed900c5bf46f97f0bcfb069278"
dependencies = [
"heck 0.4.0",
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn 1.0.99",
"tauri-codegen",
"tauri-utils",
]
@ -2977,8 +3110,8 @@ dependencies = [
"kuchiki",
"memchr",
"phf 0.10.1",
"proc-macro2",
"quote",
"proc-macro2 1.0.43",
"quote 1.0.21",
"semver 1.0.13",
"serde",
"serde_json",
@ -3014,6 +3147,15 @@ dependencies = [
"utf-8",
]
[[package]]
name = "termcolor"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
dependencies = [
"winapi-util",
]
[[package]]
name = "thin-slice"
version = "0.1.1"
@ -3035,9 +3177,9 @@ version = "1.0.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "12bafc5b54507e0149cdf1b145a5d80ab80a90bcd9275df43d4fff68460f6c21"
dependencies = [
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn 1.0.99",
]
[[package]]
@ -3084,9 +3226,9 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
version = "1.20.1"
version = "1.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581"
checksum = "89797afd69d206ccd11fb0ea560a44bbb87731d020670e79416d442919257d42"
dependencies = [
"autocfg",
"bytes",
@ -3094,6 +3236,7 @@ dependencies = [
"num_cpus",
"once_cell",
"pin-project-lite",
"socket2",
]
[[package]]
@ -3123,9 +3266,9 @@ version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11c75893af559bc8e10716548bdef5cb2b983f8e637db9d0e15126b61b484ee2"
dependencies = [
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn 1.0.99",
]
[[package]]
@ -3215,6 +3358,12 @@ version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7e8820f5d777f6224dc4be3632222971ac30164d4a258d595640799554ebfd99"
[[package]]
name = "unicode-xid"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
[[package]]
name = "url"
version = "2.2.2"
@ -3321,9 +3470,9 @@ dependencies = [
"bumpalo",
"log",
"once_cell",
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn 1.0.99",
"wasm-bindgen-shared",
]
@ -3333,7 +3482,7 @@ version = "0.2.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b260f13d3012071dfb1512849c033b1925038373aea48ced3012c09df952c602"
dependencies = [
"quote",
"quote 1.0.21",
"wasm-bindgen-macro-support",
]
@ -3343,9 +3492,9 @@ version = "0.2.82"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5be8e654bdd9b79216c2929ab90721aa82faf65c48cdf08bdc4e7f51357b80da"
dependencies = [
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn 1.0.99",
"wasm-bindgen-backend",
"wasm-bindgen-shared",
]
@ -3431,9 +3580,9 @@ version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eaebe196c01691db62e9e4ca52c5ef1e4fd837dcae27dae3ada599b5a8fd05ac"
dependencies = [
"proc-macro2",
"quote",
"syn",
"proc-macro2 1.0.43",
"quote 1.0.21",
"syn 1.0.99",
]
[[package]]
@ -3524,7 +3673,7 @@ version = "0.37.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "67a1062e555f7d9d66fd1130ed4f7c6ec41a47529ee0850cd0e926d95b26bb14"
dependencies = [
"syn",
"syn 1.0.99",
"windows-tokens",
]

View File

@ -16,8 +16,11 @@ tauri-build = { version = "1.0.0", features = [] }
serde_json = "1.0"
serde = { version = "1.0", features = ["derive"] }
tauri = { version = "1.0.0", features = ["fs-create-dir", "fs-read-dir", "fs-read-file", "fs-write-file", "macos-private-api", "window-minimize", "window-set-max-size", "window-set-min-size", "window-unminimize"] }
cpal = "0.14.0"
cpal = { version = "0.14.0", features = ["jack"] }
ray_format = {path = "../ray_format", version = "~0.1.0"}
anyhow = "1.0.63"
log = "0.4.17"
env_logger = "0.9.0"
[features]
# by default Tauri runs in production mode

42
src-tauri/src/audio.rs Normal file
View File

@ -0,0 +1,42 @@
use std::sync::Arc;
use std::sync::Mutex;
use anyhow::anyhow;
use anyhow::Result;
use cpal::traits::StreamTrait;
use cpal::traits::{DeviceTrait, HostTrait};
use cpal::Device;
use cpal::InputCallbackInfo;
// use cpal::OutputCallbackInfo;
use tauri::Window;
pub async fn monitor(window: Window, threshold: Arc<Mutex<f32>>) {
let device = initialize().expect("Unable to init audio");
println!("Using device {}", device.name().unwrap());
let config = device.default_input_config().unwrap();
let stream = device
.build_input_stream(
&config.config(),
move |data: &[f32], _: &InputCallbackInfo| {
if data.iter().any(|e| e.abs() >= *threshold.lock().unwrap()) {
window.emit("mouth-open", "").unwrap();
} else {
window.emit("mouth-close", "").unwrap();
}
},
move |err| {
println!("Audio error: {:?}", err);
},
)
.unwrap();
println!("Start stream");
stream.play().expect("Error creating output stream");
loop {} // the stream will close if it goes out of scope, so just dwell here
}
fn initialize() -> Result<Device> {
let host = cpal::default_host();
host.default_input_device()
.ok_or_else(|| anyhow!("No default output device"))
}

View File

@ -3,14 +3,45 @@
windows_subsystem = "windows"
)]
#[tauri::command]
fn greet(name: &str) -> String {
format!("Hello, {}! You've been greeted from Rust!", name)
}
use std::sync::{Arc, Mutex};
use audio::monitor;
use log::warn;
use tauri::{Manager, State};
mod audio;
const MIC_THRESHOLD: f32 = 0.5f32;
struct MicThreshold(Arc<Mutex<f32>>);
fn main() {
let threshold = Arc::new(Mutex::new(MIC_THRESHOLD));
tauri::Builder::default()
.invoke_handler(tauri::generate_handler![greet])
.manage(MicThreshold(threshold.clone()))
.setup(|app| {
let window = app.get_window("main").unwrap();
tauri::async_runtime::spawn(async move {
monitor(window, threshold).await;
});
Ok(())
})
.invoke_handler(tauri::generate_handler![
set_mic_threshold,
get_mic_threshold
])
.run(tauri::generate_context!())
.expect("error while running tauri application");
}
#[tauri::command]
fn set_mic_threshold(threshold: f32, current: State<'_, MicThreshold>) {
*current.0.lock().unwrap() = threshold;
}
#[tauri::command]
fn get_mic_threshold(current: State<'_, MicThreshold>) -> f32 {
*current.0.lock().unwrap()
}

View File

@ -4,13 +4,22 @@
//TODO: load frame from ray
</script>
<div class="preview" />
<div class="preview">
<img src="vite.svg" alt="Frame {{index}}"/>
</div>
<style lang="scss">
.preview {
display: flex;
align-content: center;
justify-content: center;
border-radius: 10px;
background-color: rgba(150, 150, 150, 0.5);
width: 15vh;
height: 15vh;
img {
width: 75%;
}
}
</style>

View File

@ -0,0 +1,86 @@
<script lang="ts">
import { onMount } from "svelte";
import { appWindow } from "@tauri-apps/api/window";
let src = "images/test.png";
let buf = 0;
let open = false;
let closed = false;
let blink = false;
$: {
if (buf > 50) {
open = true;
closed = false;
} else {
open = false;
closed = true;
}
}
onMount(async () => {
await appWindow.listen("mouth-open", () => {
buf = 100;
});
await appWindow.listen("mouth-close", () => {
buf = buf - 10;
buf = buf < 0 ? 0 : buf;
});
await appWindow.listen("blink", () => {
blink = true;
setTimeout(() => (blink = false), 300);
});
});
</script>
<img {src} alt="tuber" class:open class:closed />
<p>{buf}</p>
<style lang="scss">
@keyframes jump-out {
0% {
transform: translateY(-50%);
}
50% {
transform: translateY(-55%);
}
100% {
transform: translateY(-50%);
}
}
@keyframes jump-in {
0% {
transform: translateY(-50%);
}
50% {
transform: translateY(-55%);
}
100% {
transform: translateY(-50%);
}
}
img {
position: absolute;
transform: translateY(-50%);
top: 50vh;
left: calc(50vw - 200px);
width: 400px;
}
.closed {
animation: jump-out;
animation-duration: 0.3s;
}
.open {
animation: jump-in;
animation-duration: 0.3s;
}
</style>

View File

@ -5,3 +5,4 @@
bottom: 0px;
left: 0px;
}

View File

@ -3,28 +3,49 @@
import { onMount } from "svelte";
import { fly } from "svelte/transition";
import FramePreview from "../components/FramePreview.svelte";
import Tuber from "../components/tube.svelte";
import { invoke } from "@tauri-apps/api/tauri";
let transparent = false;
let threshold = 0.0;
onMount(async () => {
await appWindow.setMinSize(new PhysicalSize(720, 600));
await appWindow.onFocusChanged(({ payload: focused }) => {
transparent = !focused;
});
setInterval(async () => {
threshold = await invoke("get_mic_threshold");
}, 500);
// setInterval(async () => {
// await invoke("set_mic_threshold", {
// threshold: (threshold + 0.2) % 1.0,
// });
// }, 1000);
});
</script>
<div class="container" class:transparent>
{#if !transparent}
<div transition:fly="{{ duration: 200, x: -200, opacity: 100}}" class="frames" >
<div
transition:fly={{ duration: 200, x: -200, opacity: 100 }}
class="frames"
>
{#each [0, 1, 2, 3] as i}
<FramePreview index={i} />
{/each}
</div>
</div>
<div transition:fly={{ duration: 200, x: 200, opacity: 100 }} class="audio">
<p>{threshold.toPrecision(2).toString()}</p>
</div>
{/if}
<Tuber />
</div>
<style>
<style lang="scss">
.frames {
align-items: left;
position: absolute;
@ -34,31 +55,42 @@
display: flex;
justify-content: space-between;
flex-direction: column;
}
}
.audio {
position: absolute;
display: flex;
bottom: 5vh;
top: 5vh;
right: 30px;
}
@keyframes fade-out {
0% {background-color: inherit;}
100% {background-color: transparent;}
}
0% {
background-color: inherit;
}
100% {
background-color: transparent;
}
}
@keyframes fade-in {
0% {background-color: transparent;}
100% {background-color: inherit;}
}
0% {
background-color: transparent;
}
100% {
background-color: inherit;
}
}
.container {
background-color: inherit;
animation-name: fade-in;
animation-duration: 0.25s;
animation-duration: 0.2s;
}
.container.transparent {
animation-name: fade-out;
animation-duration: 0.25s;
animation-duration: 0.2s;
background-color: transparent;
}
}
</style>