mirror of
https://github.com/ndarilek/tts-rs.git
synced 2024-09-29 01:09:37 +00:00
Compare commits
19 Commits
Author | SHA1 | Date | |
---|---|---|---|
b31efe752d | |||
ae7bf7554c | |||
3bc16f0c6f | |||
3c8ae0ae42 | |||
07edc20861 | |||
96a5209a9f | |||
20b18949e2 | |||
f29de0aede | |||
9e1476fd36 | |||
3032fe0fb3 | |||
edd09c24e7 | |||
b7b4e7dc85 | |||
f593340051 | |||
|
12d8e1f532 | ||
|
2a81dc9b70 | ||
|
a0c6cbaf6a | ||
5c528f1d8e | |||
9fb8107acf | |||
8dabcc99c4 |
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
|
@ -12,7 +12,7 @@ jobs:
|
||||||
env:
|
env:
|
||||||
CARGO_TOKEN: ${{ secrets.CARGO_TOKEN }}
|
CARGO_TOKEN: ${{ secrets.CARGO_TOKEN }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- run: |
|
- run: |
|
||||||
sudo apt-get update
|
sudo apt-get update
|
||||||
sudo apt-get install -y libspeechd-dev
|
sudo apt-get install -y libspeechd-dev
|
||||||
|
|
30
.github/workflows/test.yml
vendored
30
.github/workflows/test.yml
vendored
|
@ -5,6 +5,17 @@ on:
|
||||||
pull_request:
|
pull_request:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
check_formatting:
|
||||||
|
name: Check Formatting
|
||||||
|
runs-on: ubuntu-22.04
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v4
|
||||||
|
- run: |
|
||||||
|
rustup toolchain install stable
|
||||||
|
cargo fmt --all --check
|
||||||
|
cd examples/web
|
||||||
|
cargo fmt --all --check
|
||||||
|
|
||||||
check:
|
check:
|
||||||
name: Check
|
name: Check
|
||||||
strategy:
|
strategy:
|
||||||
|
@ -12,41 +23,38 @@ jobs:
|
||||||
os: [windows-latest, ubuntu-22.04, macos-latest]
|
os: [windows-latest, ubuntu-22.04, macos-latest]
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- run: sudo apt-get update; sudo apt-get install -y libspeechd-dev
|
- run: sudo apt-get update; sudo apt-get install -y libspeechd-dev
|
||||||
if: ${{ runner.os == 'Linux' }}
|
if: ${{ runner.os == 'Linux' }}
|
||||||
- run: |
|
- run: |
|
||||||
rustup toolchain install stable
|
rustup toolchain install stable
|
||||||
cargo fmt --check
|
cargo clippy --all-targets
|
||||||
cargo clippy
|
|
||||||
|
|
||||||
check_web:
|
check_web:
|
||||||
name: Check Web
|
name: Check Web
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- run: |
|
- run: |
|
||||||
rustup target add wasm32-unknown-unknown
|
rustup target add wasm32-unknown-unknown
|
||||||
rustup toolchain install stable
|
rustup toolchain install stable
|
||||||
cargo fmt --all --check
|
cargo clippy --all-targets --target wasm32-unknown-unknown
|
||||||
cargo clippy --target wasm32-unknown-unknown
|
|
||||||
|
|
||||||
check_android:
|
check_android:
|
||||||
name: Check Android
|
name: Check Android
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- run: |
|
- run: |
|
||||||
|
rustup target add aarch64-linux-android
|
||||||
rustup toolchain install stable
|
rustup toolchain install stable
|
||||||
rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android
|
cargo clippy --all-targets --target aarch64-linux-android
|
||||||
cargo install -f cargo-apk
|
|
||||||
cargo apk build
|
|
||||||
|
|
||||||
check_web_example:
|
check_web_example:
|
||||||
name: Check Web Example
|
name: Check Web Example
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- run: |
|
- run: |
|
||||||
rustup target add wasm32-unknown-unknown
|
rustup target add wasm32-unknown-unknown
|
||||||
rustup toolchain install stable
|
rustup toolchain install stable
|
||||||
|
|
26
Cargo.toml
26
Cargo.toml
|
@ -1,9 +1,10 @@
|
||||||
[package]
|
[package]
|
||||||
name = "tts"
|
name = "tts"
|
||||||
version = "0.25.5"
|
version = "0.26.3"
|
||||||
authors = ["Nolan Darilek <nolan@thewordnerd.info>"]
|
authors = ["Nolan Darilek <nolan@thewordnerd.info>"]
|
||||||
repository = "https://github.com/ndarilek/tts-rs"
|
repository = "https://github.com/ndarilek/tts-rs"
|
||||||
description = "High-level Text-To-Speech (TTS) interface"
|
description = "High-level Text-To-Speech (TTS) interface"
|
||||||
|
documentation = "https://docs.rs/tts"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
exclude = ["*.cfg", "*.yml"]
|
exclude = ["*.cfg", "*.yml"]
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
@ -26,11 +27,18 @@ serde = { version = "1", optional = true, features = ["derive"] }
|
||||||
thiserror = "1"
|
thiserror = "1"
|
||||||
|
|
||||||
[dev-dependencies]
|
[dev-dependencies]
|
||||||
env_logger = "0.10"
|
env_logger = "0.11"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
tolk = { version = "0.5", optional = true }
|
tolk = { version = "0.5", optional = true }
|
||||||
windows = { version = "0.48", features = ["Foundation", "Foundation_Collections", "Media_Core", "Media_Playback", "Media_SpeechSynthesis", "Storage_Streams"] }
|
windows = { version = "0.58", features = [
|
||||||
|
"Foundation",
|
||||||
|
"Foundation_Collections",
|
||||||
|
"Media_Core",
|
||||||
|
"Media_Playback",
|
||||||
|
"Media_SpeechSynthesis",
|
||||||
|
"Storage_Streams",
|
||||||
|
] }
|
||||||
|
|
||||||
[target.'cfg(target_os = "linux")'.dependencies]
|
[target.'cfg(target_os = "linux")'.dependencies]
|
||||||
speech-dispatcher = { version = "0.16", default-features = false }
|
speech-dispatcher = { version = "0.16", default-features = false }
|
||||||
|
@ -43,12 +51,20 @@ objc = { version = "0.2", features = ["exception"] }
|
||||||
|
|
||||||
[target.wasm32-unknown-unknown.dependencies]
|
[target.wasm32-unknown-unknown.dependencies]
|
||||||
wasm-bindgen = "0.2"
|
wasm-bindgen = "0.2"
|
||||||
web-sys = { version = "0.3", features = ["EventTarget", "SpeechSynthesis", "SpeechSynthesisErrorCode", "SpeechSynthesisErrorEvent", "SpeechSynthesisEvent", "SpeechSynthesisUtterance", "SpeechSynthesisVoice", "Window", ] }
|
web-sys = { version = "0.3", features = [
|
||||||
|
"EventTarget",
|
||||||
|
"SpeechSynthesis",
|
||||||
|
"SpeechSynthesisErrorCode",
|
||||||
|
"SpeechSynthesisErrorEvent",
|
||||||
|
"SpeechSynthesisEvent",
|
||||||
|
"SpeechSynthesisUtterance",
|
||||||
|
"SpeechSynthesisVoice",
|
||||||
|
"Window",
|
||||||
|
] }
|
||||||
|
|
||||||
[target.'cfg(target_os="android")'.dependencies]
|
[target.'cfg(target_os="android")'.dependencies]
|
||||||
jni = "0.21"
|
jni = "0.21"
|
||||||
ndk-context = "0.1"
|
ndk-context = "0.1"
|
||||||
ndk-glue = "0.7"
|
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
[package.metadata.docs.rs]
|
||||||
no-default-features = true
|
no-default-features = true
|
||||||
|
|
|
@ -188,6 +188,7 @@ impl Backend for SpeechDispatcher {
|
||||||
.0
|
.0
|
||||||
.list_synthesis_voices()?
|
.list_synthesis_voices()?
|
||||||
.iter()
|
.iter()
|
||||||
|
.filter(|v| LanguageTag::parse(v.language.clone()).is_ok())
|
||||||
.map(|v| Voice {
|
.map(|v| Voice {
|
||||||
id: v.name.clone(),
|
id: v.name.clone(),
|
||||||
name: v.name.clone(),
|
name: v.name.clone(),
|
||||||
|
|
31
src/lib.rs
31
src/lib.rs
|
@ -14,9 +14,10 @@ use std::collections::HashMap;
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
use std::ffi::CStr;
|
use std::ffi::CStr;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::rc::Rc;
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
use std::string::FromUtf16Error;
|
use std::string::FromUtf16Error;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::Mutex;
|
||||||
use std::{boxed::Box, sync::RwLock};
|
use std::{boxed::Box, sync::RwLock};
|
||||||
|
|
||||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||||
|
@ -258,7 +259,7 @@ lazy_static! {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct Tts(Arc<RwLock<Box<dyn Backend>>>);
|
pub struct Tts(Rc<RwLock<Box<dyn Backend>>>);
|
||||||
|
|
||||||
unsafe impl Send for Tts {}
|
unsafe impl Send for Tts {}
|
||||||
|
|
||||||
|
@ -271,18 +272,18 @@ impl Tts {
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
Backends::SpeechDispatcher => {
|
Backends::SpeechDispatcher => {
|
||||||
let tts = backends::SpeechDispatcher::new()?;
|
let tts = backends::SpeechDispatcher::new()?;
|
||||||
Ok(Tts(Arc::new(RwLock::new(Box::new(tts)))))
|
Ok(Tts(Rc::new(RwLock::new(Box::new(tts)))))
|
||||||
}
|
}
|
||||||
#[cfg(target_arch = "wasm32")]
|
#[cfg(target_arch = "wasm32")]
|
||||||
Backends::Web => {
|
Backends::Web => {
|
||||||
let tts = backends::Web::new()?;
|
let tts = backends::Web::new()?;
|
||||||
Ok(Tts(Arc::new(RwLock::new(Box::new(tts)))))
|
Ok(Tts(Rc::new(RwLock::new(Box::new(tts)))))
|
||||||
}
|
}
|
||||||
#[cfg(all(windows, feature = "tolk"))]
|
#[cfg(all(windows, feature = "tolk"))]
|
||||||
Backends::Tolk => {
|
Backends::Tolk => {
|
||||||
let tts = backends::Tolk::new();
|
let tts = backends::Tolk::new();
|
||||||
if let Some(tts) = tts {
|
if let Some(tts) = tts {
|
||||||
Ok(Tts(Arc::new(RwLock::new(Box::new(tts)))))
|
Ok(Tts(Rc::new(RwLock::new(Box::new(tts)))))
|
||||||
} else {
|
} else {
|
||||||
Err(Error::NoneError)
|
Err(Error::NoneError)
|
||||||
}
|
}
|
||||||
|
@ -290,20 +291,20 @@ impl Tts {
|
||||||
#[cfg(windows)]
|
#[cfg(windows)]
|
||||||
Backends::WinRt => {
|
Backends::WinRt => {
|
||||||
let tts = backends::WinRt::new()?;
|
let tts = backends::WinRt::new()?;
|
||||||
Ok(Tts(Arc::new(RwLock::new(Box::new(tts)))))
|
Ok(Tts(Rc::new(RwLock::new(Box::new(tts)))))
|
||||||
}
|
}
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
Backends::AppKit => Ok(Tts(Arc::new(RwLock::new(Box::new(
|
Backends::AppKit => Ok(Tts(Rc::new(RwLock::new(
|
||||||
backends::AppKit::new()?
|
Box::new(backends::AppKit::new()?),
|
||||||
))))),
|
)))),
|
||||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||||
Backends::AvFoundation => Ok(Tts(Arc::new(RwLock::new(Box::new(
|
Backends::AvFoundation => Ok(Tts(Rc::new(RwLock::new(Box::new(
|
||||||
backends::AvFoundation::new()?,
|
backends::AvFoundation::new()?,
|
||||||
))))),
|
))))),
|
||||||
#[cfg(target_os = "android")]
|
#[cfg(target_os = "android")]
|
||||||
Backends::Android => {
|
Backends::Android => {
|
||||||
let tts = backends::Android::new()?;
|
let tts = backends::Android::new()?;
|
||||||
Ok(Tts(Arc::new(RwLock::new(Box::new(tts)))))
|
Ok(Tts(Rc::new(RwLock::new(Box::new(tts)))))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if let Ok(backend) = backend {
|
if let Ok(backend) = backend {
|
||||||
|
@ -571,7 +572,7 @@ impl Tts {
|
||||||
if utterance_callbacks {
|
if utterance_callbacks {
|
||||||
let mut callbacks = CALLBACKS.lock().unwrap();
|
let mut callbacks = CALLBACKS.lock().unwrap();
|
||||||
let id = self.0.read().unwrap().id().unwrap();
|
let id = self.0.read().unwrap().id().unwrap();
|
||||||
let mut callbacks = callbacks.get_mut(&id).unwrap();
|
let callbacks = callbacks.get_mut(&id).unwrap();
|
||||||
callbacks.utterance_begin = callback;
|
callbacks.utterance_begin = callback;
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
|
@ -591,7 +592,7 @@ impl Tts {
|
||||||
if utterance_callbacks {
|
if utterance_callbacks {
|
||||||
let mut callbacks = CALLBACKS.lock().unwrap();
|
let mut callbacks = CALLBACKS.lock().unwrap();
|
||||||
let id = self.0.read().unwrap().id().unwrap();
|
let id = self.0.read().unwrap().id().unwrap();
|
||||||
let mut callbacks = callbacks.get_mut(&id).unwrap();
|
let callbacks = callbacks.get_mut(&id).unwrap();
|
||||||
callbacks.utterance_end = callback;
|
callbacks.utterance_end = callback;
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
|
@ -611,7 +612,7 @@ impl Tts {
|
||||||
if utterance_callbacks {
|
if utterance_callbacks {
|
||||||
let mut callbacks = CALLBACKS.lock().unwrap();
|
let mut callbacks = CALLBACKS.lock().unwrap();
|
||||||
let id = self.0.read().unwrap().id().unwrap();
|
let id = self.0.read().unwrap().id().unwrap();
|
||||||
let mut callbacks = callbacks.get_mut(&id).unwrap();
|
let callbacks = callbacks.get_mut(&id).unwrap();
|
||||||
callbacks.utterance_stop = callback;
|
callbacks.utterance_stop = callback;
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
|
@ -640,7 +641,7 @@ impl Tts {
|
||||||
|
|
||||||
impl Drop for Tts {
|
impl Drop for Tts {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if Arc::strong_count(&self.0) <= 1 {
|
if Rc::strong_count(&self.0) <= 1 {
|
||||||
if let Some(id) = self.0.read().unwrap().id() {
|
if let Some(id) = self.0.read().unwrap().id() {
|
||||||
let mut callbacks = CALLBACKS.lock().unwrap();
|
let mut callbacks = CALLBACKS.lock().unwrap();
|
||||||
callbacks.remove(&id);
|
callbacks.remove(&id);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user