mirror of https://github.com/ndarilek/tts-rs.git
Compare commits
2 Commits
20b18949e2
...
07edc20861
Author | SHA1 | Date |
---|---|---|
Nolan Darilek | 07edc20861 | |
Nolan Darilek | 96a5209a9f |
|
@ -5,6 +5,17 @@ on:
|
|||
pull_request:
|
||||
|
||||
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:
|
||||
name: Check
|
||||
strategy:
|
||||
|
@ -17,8 +28,7 @@ jobs:
|
|||
if: ${{ runner.os == 'Linux' }}
|
||||
- run: |
|
||||
rustup toolchain install stable
|
||||
cargo fmt --check
|
||||
cargo clippy
|
||||
cargo clippy --all-targets
|
||||
|
||||
check_web:
|
||||
name: Check Web
|
||||
|
@ -28,8 +38,7 @@ jobs:
|
|||
- run: |
|
||||
rustup target add wasm32-unknown-unknown
|
||||
rustup toolchain install stable
|
||||
cargo fmt --all --check
|
||||
cargo clippy --target wasm32-unknown-unknown
|
||||
cargo clippy --all-targets --target wasm32-unknown-unknown
|
||||
|
||||
check_android:
|
||||
name: Check Android
|
||||
|
@ -37,10 +46,9 @@ jobs:
|
|||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- run: |
|
||||
rustup target add aarch64-linux-android
|
||||
rustup toolchain install stable
|
||||
rustup target add aarch64-linux-android armv7-linux-androideabi i686-linux-android x86_64-linux-android
|
||||
cargo install -f xbuild
|
||||
cargo build --target aarch64-linux-android
|
||||
cargo clippy --all-targets --target aarch64-linux-android
|
||||
|
||||
check_web_example:
|
||||
name: Check Web Example
|
||||
|
|
25
src/lib.rs
25
src/lib.rs
|
@ -14,9 +14,10 @@ use std::collections::HashMap;
|
|||
#[cfg(target_os = "macos")]
|
||||
use std::ffi::CStr;
|
||||
use std::fmt;
|
||||
use std::rc::Rc;
|
||||
#[cfg(windows)]
|
||||
use std::string::FromUtf16Error;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::sync::Mutex;
|
||||
use std::{boxed::Box, sync::RwLock};
|
||||
|
||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||
|
@ -258,7 +259,7 @@ lazy_static! {
|
|||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Tts(Arc<RwLock<Box<dyn Backend>>>);
|
||||
pub struct Tts(Rc<RwLock<Box<dyn Backend>>>);
|
||||
|
||||
unsafe impl Send for Tts {}
|
||||
|
||||
|
@ -271,18 +272,18 @@ impl Tts {
|
|||
#[cfg(target_os = "linux")]
|
||||
Backends::SpeechDispatcher => {
|
||||
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")]
|
||||
Backends::Web => {
|
||||
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"))]
|
||||
Backends::Tolk => {
|
||||
let tts = backends::Tolk::new();
|
||||
if let Some(tts) = tts {
|
||||
Ok(Tts(Arc::new(RwLock::new(Box::new(tts)))))
|
||||
Ok(Tts(Rc::new(RwLock::new(Box::new(tts)))))
|
||||
} else {
|
||||
Err(Error::NoneError)
|
||||
}
|
||||
|
@ -290,20 +291,20 @@ impl Tts {
|
|||
#[cfg(windows)]
|
||||
Backends::WinRt => {
|
||||
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")]
|
||||
Backends::AppKit => Ok(Tts(Arc::new(RwLock::new(Box::new(
|
||||
backends::AppKit::new()?
|
||||
))))),
|
||||
Backends::AppKit => Ok(Tts(Rc::new(RwLock::new(
|
||||
Box::new(backends::AppKit::new()?),
|
||||
)))),
|
||||
#[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()?,
|
||||
))))),
|
||||
#[cfg(target_os = "android")]
|
||||
Backends::Android => {
|
||||
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 {
|
||||
|
@ -640,7 +641,7 @@ impl Tts {
|
|||
|
||||
impl Drop for Tts {
|
||||
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() {
|
||||
let mut callbacks = CALLBACKS.lock().unwrap();
|
||||
callbacks.remove(&id);
|
||||
|
|
Loading…
Reference in New Issue