diff --git a/Cargo.lock b/Cargo.lock index 90c7b5f..f05e6f6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2,6 +2,12 @@ # It is not intended for manual editing. version = 3 +[[package]] +name = "Inflector" +version = "0.11.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe438c63458706e03479442743baae6c88256498e6431708f6dfc520a26515d3" + [[package]] name = "addr2line" version = "0.22.0" @@ -28,6 +34,46 @@ dependencies = [ "cpufeatures", ] +[[package]] +name = "aformat" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "888c88fe52c66481cc389ba777a85715b1868b76cfd37e018911f89bc9a84388" +dependencies = [ + "aformat-macros", + "to-arraystring", + "typenum", + "typenum_mappings", +] + +[[package]] +name = "aformat-macros" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1d3370253838699d84eb0eba50100317518c8dc4cdf69ddbcba7a4e9938f09e" +dependencies = [ + "bytestring", + "proc-macro2", + "procout", + "quote", + "syn 2.0.72", +] + +[[package]] +name = "android-tzdata" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0" + +[[package]] +name = "android_system_properties" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311" +dependencies = [ + "libc", +] + [[package]] name = "anyhow" version = "1.0.86" @@ -40,6 +86,12 @@ version = "1.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "69f7f8c3906b62b754cd5326047894316021dcfe5a194c8ea52bdd94934a3457" +[[package]] +name = "arrayvec" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" + [[package]] name = "async-trait" version = "0.1.81" @@ -48,7 +100,7 @@ checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.72", ] [[package]] @@ -536,6 +588,15 @@ dependencies = [ "either", ] +[[package]] +name = "bytestring" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "74d80203ea6b29df88012294f62733de21cfeab47f17b41af3a38bc30a03ee72" +dependencies = [ + "bytes", +] + [[package]] name = "cbc" version = "0.1.2" @@ -557,6 +618,20 @@ version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" +[[package]] +name = "chrono" +version = "0.4.38" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" +dependencies = [ + "android-tzdata", + "iana-time-zone", + "js-sys", + "num-traits", + "wasm-bindgen", + "windows-targets 0.52.6", +] + [[package]] name = "cipher" version = "0.4.4" @@ -1017,6 +1092,29 @@ dependencies = [ "tracing", ] +[[package]] +name = "iana-time-zone" +version = "0.1.60" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7ffbb5a1b541ea2561f8c41c087286cc091e21e556a4f09a8f6cbf17b69b141" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + [[package]] name = "idna" version = "0.5.0" @@ -1327,7 +1425,7 @@ checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.72", ] [[package]] @@ -1366,6 +1464,19 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "procout" +version = "0.1.13" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d710f595d4e0a6df3265e2fc65731ee564ada41400628563fe635905ab70418" +dependencies = [ + "Inflector", + "chrono", + "proc-macro2", + "quote", + "syn 1.0.109", +] + [[package]] name = "quinn" version = "0.11.3" @@ -1753,7 +1864,7 @@ checksum = "e0cd7e117be63d3c3678776753929474f3b04a43a080c744d6b0ae2a8c28e222" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.72", ] [[package]] @@ -1877,6 +1988,17 @@ version = "2.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + [[package]] name = "syn" version = "2.0.72" @@ -1917,7 +2039,7 @@ checksum = "a4558b58466b9ad7ca0f102865eccc95938dca1a74a856f2b57b6629050da261" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.72", ] [[package]] @@ -1976,6 +2098,17 @@ version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" +[[package]] +name = "to-arraystring" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fafaa22f176928fb926345e78eb2ec404603c878b274e6ab1f76de1f6dde1b1" +dependencies = [ + "arrayvec", + "itoa", + "ryu", +] + [[package]] name = "tokio" version = "1.39.2" @@ -2002,7 +2135,7 @@ checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.72", ] [[package]] @@ -2085,7 +2218,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.72", ] [[package]] @@ -2121,6 +2254,7 @@ checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" name = "tts-service" version = "0.1.0" dependencies = [ + "aformat", "anyhow", "aws-config", "aws-sdk-polly", @@ -2152,6 +2286,18 @@ version = "1.17.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "42ff0bf0c66b8238c6f3b578df37d0b7848e55df8577b3f74f92a69acceeb825" +[[package]] +name = "typenum_mappings" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cbc2d8952dd1e08b0164a5b51549e80631ac9da4107669d26c8ea89cb0b5545" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.72", + "to-arraystring", +] + [[package]] name = "unicode-bidi" version = "0.3.15" @@ -2250,7 +2396,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn", + "syn 2.0.72", "wasm-bindgen-shared", ] @@ -2284,7 +2430,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.72", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -2336,6 +2482,15 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" +[[package]] +name = "windows-core" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" +dependencies = [ + "windows-targets 0.52.6", +] + [[package]] name = "windows-sys" version = "0.48.0" @@ -2509,7 +2664,7 @@ checksum = "fa4f8080344d4671fb4e831a13ad1e68092748387dfc4f55e356242fae12ce3e" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.72", ] [[package]] @@ -2529,5 +2684,5 @@ checksum = "ce36e65b0d2999d2aafac989fb249189a141aee1f53c612c1f37d72631959f69" dependencies = [ "proc-macro2", "quote", - "syn", + "syn 2.0.72", ] diff --git a/Cargo.toml b/Cargo.toml index efe27b2..b6ced4a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -23,6 +23,7 @@ itertools = "0.13" aws-sdk-polly = "1.7.0" small-fixed-array = { version = "0.4.0", features = ["serde"] } memchr = "2.7.4" +aformat = "0.1.4" [dependencies.fernet] version = "0.2" diff --git a/src/espeak.rs b/src/espeak.rs index 90b9826..2ccd275 100644 --- a/src/espeak.rs +++ b/src/espeak.rs @@ -1,5 +1,6 @@ use std::sync::{LazyLock, OnceLock}; +use aformat::{aformat, CapStr, ToArrayString}; use memchr::memmem::Finder; use reqwest::header::HeaderValue; use tokio::io::AsyncReadExt; @@ -25,6 +26,7 @@ pub async fn get_tts( anyhow::bail!("Invalid voice: {voice}"); } + let voice = CapStr::<8>(voice); let Finders { repeat_err, replaced_with_err, @@ -41,9 +43,9 @@ pub async fn get_tts( "--pho", "-q", "-s", - &speaking_rate.to_string(), + &speaking_rate.to_arraystring(), "-v", - &format!("mb/mb-{voice}"), + &aformat!("mb/mb-{voice}"), text, ]) .spawn()?; @@ -59,7 +61,7 @@ pub async fn get_tts( .stdin(espeak_stdout) .args([ "-e", - &format!("/usr/share/mbrola/{voice}/{voice}"), + &aformat!("/usr/share/mbrola/{voice}/{voice}"), "-", "-.wav", ]) diff --git a/src/gtts.rs b/src/gtts.rs index 81cdbb2..4d41c31 100644 --- a/src/gtts.rs +++ b/src/gtts.rs @@ -1,5 +1,6 @@ use std::sync::OnceLock; +use aformat::ToArrayString; use ipgen::IpNetwork; use itertools::Itertools; use rand::Rng; @@ -31,7 +32,7 @@ fn parse_url(text: &str, lang: &str) -> reqwest::Url { url.query_pairs_mut() .append_pair("tl", lang) .append_pair("q", text) - .append_pair("textlen", &text.len().to_string()) + .append_pair("textlen", &text.len().to_arraystring()) .finish(); url }