From 665013fdff5105d54018bb2a268c369a12779f99 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Wed, 2 Sep 2020 11:40:08 -0500 Subject: [PATCH 1/7] Split text sent to Tolk backend to account for some sort of length limit. Tolk seems to fail on strings larger than 325 characters in length. Here we: * Send any strings with 300 or fewer characters through directly. * For larger strings, split on whitespace boundaries, then create and send buffers of 300 or fewer characters. This may not handle internationalized text, and may not handle someone bombarding TTS with a giant word. PRs for either welcome. --- src/backends/tolk.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/backends/tolk.rs b/src/backends/tolk.rs index 370da65..c71cdfa 100644 --- a/src/backends/tolk.rs +++ b/src/backends/tolk.rs @@ -28,7 +28,25 @@ impl Backend for Tolk { fn speak(&mut self, text: &str, interrupt: bool) -> Result<(), Error> { trace!("speak({}, {})", text, interrupt); - self.0.speak(text, interrupt); + const BUFFER_LENGTH: usize = 300; + if text.len() <= BUFFER_LENGTH { + self.0.speak(text, interrupt); + } else { + if interrupt { + self.stop()?; + } + let tokens = text.split_whitespace(); + let mut buffer = String::new(); + for token in tokens { + if buffer.len() + token.len() > BUFFER_LENGTH { + self.0.speak(buffer, false); + buffer = String::new(); + } else { + buffer.push_str(token); + buffer.push(' '); + } + } + } Ok(()) } From 81b23330e965a88fb52896051b9a0e04e585756f Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Wed, 2 Sep 2020 15:37:34 -0500 Subject: [PATCH 2/7] Move iOS build into separate CI run to see if this odd bug is triggered. --- .github/workflows/test.yml | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9404d8a..49bc04b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -5,7 +5,6 @@ on: pull_request: jobs: - build_linux: name: Build Linux runs-on: ubuntu-latest @@ -34,6 +33,13 @@ jobs: - uses: actions/checkout@v2 - run: | cargo build --release + + build_ios: + name: Build iOS + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + - run: | rustup target add aarch64-apple-ios x86_64-apple-ios cargo install cargo-lipo cargo lipo --release From d3ca27c7074cac36738f20052d178aff28e910e5 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Wed, 2 Sep 2020 15:52:11 -0500 Subject: [PATCH 3/7] Force Rust toolchain update, and separate out iOS build. --- .github/workflows/release.yml | 14 +++++++++++++- .github/workflows/test.yml | 4 ++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f53a0d6..973b9bf 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -6,7 +6,6 @@ on: - "v*" jobs: - build_linux: name: Build Linux runs-on: ubuntu-latest @@ -15,6 +14,7 @@ jobs: - run: | sudo apt-get update sudo apt-get install -y libspeechd-dev + rustup update cargo build --release rustup target add wasm32-unknown-unknown cargo build --release --target wasm32-unknown-unknown @@ -26,6 +26,7 @@ jobs: - uses: actions/checkout@v2 - run: | choco install -y llvm + rustup update cargo build --release build_macos: @@ -34,7 +35,16 @@ jobs: steps: - uses: actions/checkout@v2 - run: | + rustup update cargo build --release + + build_ios: + name: Build iOS + runs-on: macos-latest + steps: + - uses: actions/checkout@v2 + - run: | + rustup update rustup target add aarch64-apple-ios x86_64-apple-ios cargo install cargo-lipo cargo lipo --release @@ -49,6 +59,7 @@ jobs: - uses: actions/checkout@v2 - run: | choco install -y llvm + rustup update cargo login $CARGO_TOKEN cd winrt_bindings cargo package @@ -65,5 +76,6 @@ jobs: - run: | sudo apt-get update sudo apt-get install -y libspeechd-dev + rustup update cargo login $CARGO_TOKEN cargo publish diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 49bc04b..d49d480 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,6 +13,7 @@ jobs: - run: | sudo apt-get update sudo apt-get install -y libspeechd-dev + rustup update cargo build --release rustup target add wasm32-unknown-unknown cargo build --release --target wasm32-unknown-unknown @@ -24,6 +25,7 @@ jobs: - uses: actions/checkout@v2 - run: | choco install -y llvm + rustup update cargo build --release build_macos: @@ -32,6 +34,7 @@ jobs: steps: - uses: actions/checkout@v2 - run: | + rustup update cargo build --release build_ios: @@ -40,6 +43,7 @@ jobs: steps: - uses: actions/checkout@v2 - run: | + rustup update rustup target add aarch64-apple-ios x86_64-apple-ios cargo install cargo-lipo cargo lipo --release From 0d61dc258f6cbab1a4c0a984cd3277bbba757c57 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Wed, 2 Sep 2020 16:03:04 -0500 Subject: [PATCH 4/7] Set up conditional compilation for iOS. --- Cargo.toml | 5 ++--- src/backends/av_foundation.rs | 4 ++-- src/backends/mod.rs | 4 ++-- src/lib.rs | 9 ++++++--- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fed932d..4a2f44e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,8 +9,7 @@ exclude = ["*.cfg", "*.yml"] edition = "2018" [lib] -name = "tts" -crate-type = ["staticlib", "cdylib"] +crate-type = ["lib", "staticlib"] [dependencies] log = "0.4" @@ -27,7 +26,7 @@ tts_winrt_bindings = { version = "0.1", path="winrt_bindings" } [target.'cfg(target_os = "linux")'.dependencies] speech-dispatcher = "0.4" -[target.'cfg(target_os = "macos")'.dependencies] +[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] cocoa-foundation = "0.1" libc = "0.2" objc = "0.2" diff --git a/src/backends/av_foundation.rs b/src/backends/av_foundation.rs index 13ea05c..a04eaea 100644 --- a/src/backends/av_foundation.rs +++ b/src/backends/av_foundation.rs @@ -1,4 +1,4 @@ -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "ios"))] #[link(name = "AVFoundation", kind = "framework")] use cocoa_foundation::base::{id, nil}; use cocoa_foundation::foundation::NSString; @@ -132,7 +132,7 @@ impl Backend for AvFoundation { fn is_speaking(&self) -> Result { let is_speaking: i8 = unsafe { msg_send![self.synth, isSpeaking] }; - Ok(is_speaking == YES) + Ok(is_speaking == 1) } } diff --git a/src/backends/mod.rs b/src/backends/mod.rs index 7971db1..c999faf 100644 --- a/src/backends/mod.rs +++ b/src/backends/mod.rs @@ -13,7 +13,7 @@ mod web; #[cfg(target_os = "macos")] mod appkit; -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "ios"))] mod av_foundation; #[cfg(target_os = "linux")] @@ -28,5 +28,5 @@ pub use self::web::*; #[cfg(target_os = "macos")] pub use self::appkit::*; -#[cfg(target_os = "macos")] +#[cfg(any(target_os = "macos", target_os = "ios"))] pub use self::av_foundation::*; diff --git a/src/lib.rs b/src/lib.rs index d5d8210..d1dda48 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,8 +11,9 @@ * * WebAssembly */ +use std::boxed::Box; #[cfg(target_os = "macos")] -use std::{boxed::Box, ffi::CStr}; +use std::ffi::CStr; #[cfg(target_os = "macos")] use cocoa_foundation::base::id; @@ -35,7 +36,7 @@ pub enum Backends { WinRT, #[cfg(target_os = "macos")] AppKit, - #[cfg(target_os = "macos")] + #[cfg(any(target_os = "macos", target_os = "ios"))] AvFoundation, } @@ -122,7 +123,7 @@ impl TTS { } #[cfg(target_os = "macos")] Backends::AppKit => Ok(TTS(Box::new(backends::AppKit::new()))), - #[cfg(target_os = "macos")] + #[cfg(any(target_os = "macos", target_os = "ios"))] Backends::AvFoundation => Ok(TTS(Box::new(backends::AvFoundation::new()))), } } @@ -156,6 +157,8 @@ impl TTS { TTS::new(Backends::AppKit) } }; + #[cfg(target_os = "ios")] + let tts = TTS::new(Backends::AvFoundation); tts } From 03ea2602bc2f9a906ecd80087174d28c9f5417e3 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Wed, 2 Sep 2020 16:37:07 -0500 Subject: [PATCH 5/7] Don't link against AppKit if building on iOS. --- build.rs | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/build.rs b/build.rs index eb44096..1aa98d1 100644 --- a/build.rs +++ b/build.rs @@ -1,15 +1,8 @@ -// Copyright 2013-2015 The Servo Project Developers. See the COPYRIGHT -// file at the top-level directory of this distribution. -// -// Licensed under the Apache License, Version 2.0 or the MIT license -// , at your -// option. This file may not be copied, modified, or distributed -// except according to those terms. - fn main() { if std::env::var("TARGET").unwrap().contains("-apple") { - println!("cargo:rustc-link-lib=framework=AppKit"); println!("cargo:rustc-link-lib=framework=AVFoundation"); + if !std::env::var("CARGO_CFG_TARGET_OS").unwrap().contains("ios") { + println!("cargo:rustc-link-lib=framework=AppKit"); + } } } From c8fd02b448e13837ea51a31c24abb11bcc2cdca4 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Wed, 2 Sep 2020 16:51:25 -0500 Subject: [PATCH 6/7] Bump version. --- Cargo.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Cargo.toml b/Cargo.toml index af088f3..8ecb3f0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tts" -version = "0.6.2" +version = "0.6.3" authors = ["Nolan Darilek "] repository = "https://github.com/ndarilek/tts-rs" description = "High-level Text-To-Speech (TTS) interface" From 14a721c83795b3e64590e3848ecea0264b52798e Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Wed, 2 Sep 2020 17:13:03 -0500 Subject: [PATCH 7/7] Depend on `build_ios` for releasing. --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 973b9bf..911d343 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -68,7 +68,7 @@ jobs: publish: name: Publish runs-on: ubuntu-latest - needs: [build_linux, build_windows, build_macos] + needs: [build_linux, build_windows, build_macos, build_ios] env: CARGO_TOKEN: ${{ secrets.CARGO_TOKEN }} steps: