Skip to content

Commit

Permalink
Remove some allocations via aformat
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev committed Aug 5, 2024
1 parent 7ea8503 commit b216b7d
Show file tree
Hide file tree
Showing 4 changed files with 173 additions and 14 deletions.
175 changes: 165 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
8 changes: 5 additions & 3 deletions src/espeak.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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,
Expand All @@ -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()?;
Expand All @@ -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",
])
Expand Down
3 changes: 2 additions & 1 deletion src/gtts.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::sync::OnceLock;

use aformat::ToArrayString;
use ipgen::IpNetwork;
use itertools::Itertools;
use rand::Rng;
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit b216b7d

Please sign in to comment.