diff --git a/Cargo.toml b/Cargo.toml index 9c0a2cc..bba2987 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,6 +16,7 @@ crate-type = ["lib", "cdylib", "staticlib"] use_tolk = ["tolk"] [dependencies] +dyn-clonable = "0.9" lazy_static = "1" log = "0.4" thiserror = "1" @@ -24,7 +25,7 @@ thiserror = "1" env_logger = "0.8" [target.'cfg(windows)'.dependencies] -tolk = { version = ">= 0.2.1", optional = true } +tolk = { version = "0.3", optional = true } winrt = "0.7" tts_winrt_bindings = { version = "0.1", path="winrt_bindings" } diff --git a/src/backends/appkit.rs b/src/backends/appkit.rs index 647cc3f..432ec23 100644 --- a/src/backends/appkit.rs +++ b/src/backends/appkit.rs @@ -9,6 +9,7 @@ use objc::*; use crate::{Backend, BackendId, Error, Features, UtteranceId}; +#[derive(Clone)] pub(crate) struct AppKit(*mut Object, *mut Object); impl AppKit { diff --git a/src/backends/av_foundation.rs b/src/backends/av_foundation.rs index 58af2f6..14fb584 100644 --- a/src/backends/av_foundation.rs +++ b/src/backends/av_foundation.rs @@ -11,6 +11,7 @@ use objc::{class, declare::ClassDecl, msg_send, sel, sel_impl}; use crate::{Backend, BackendId, Error, Features, UtteranceId, CALLBACKS}; +#[derive(Clone)] pub(crate) struct AvFoundation { id: BackendId, delegate: *mut Object, diff --git a/src/backends/speech_dispatcher.rs b/src/backends/speech_dispatcher.rs index 72332ca..b5aa9c9 100644 --- a/src/backends/speech_dispatcher.rs +++ b/src/backends/speech_dispatcher.rs @@ -8,6 +8,7 @@ use speech_dispatcher::*; use crate::{Backend, BackendId, Error, Features, UtteranceId, CALLBACKS}; +#[derive(Clone)] pub(crate) struct SpeechDispatcher(Connection); lazy_static! { diff --git a/src/backends/tolk.rs b/src/backends/tolk.rs index 4cf7315..1230a02 100644 --- a/src/backends/tolk.rs +++ b/src/backends/tolk.rs @@ -4,6 +4,7 @@ use tolk::Tolk as TolkPtr; use crate::{Backend, BackendId, Error, Features, UtteranceId}; +#[derive(Clone)] pub(crate) struct Tolk(TolkPtr); impl Tolk { diff --git a/src/backends/web.rs b/src/backends/web.rs index 1b047a8..ee203fe 100644 --- a/src/backends/web.rs +++ b/src/backends/web.rs @@ -12,6 +12,7 @@ use web_sys::{ use crate::{Backend, BackendId, Error, Features, UtteranceId, CALLBACKS}; +#[derive(Clone)] pub struct Web { id: BackendId, rate: f32, diff --git a/src/backends/winrt.rs b/src/backends/winrt.rs index 618c810..6d01e97 100644 --- a/src/backends/winrt.rs +++ b/src/backends/winrt.rs @@ -21,6 +21,7 @@ impl From for Error { } } +#[derive(Clone)] pub struct WinRT { id: BackendId, synth: SpeechSynthesizer, diff --git a/src/lib.rs b/src/lib.rs index a071d93..3b5c357 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -19,6 +19,7 @@ use std::sync::Mutex; #[cfg(any(target_os = "macos", target_os = "ios"))] use cocoa_foundation::base::id; +use dyn_clonable::*; use lazy_static::lazy_static; #[cfg(target_os = "macos")] use libc::c_char; @@ -28,6 +29,7 @@ use thiserror::Error; mod backends; +#[derive(Clone, Copy, Debug)] pub enum Backends { #[cfg(target_os = "linux")] SpeechDispatcher, @@ -107,7 +109,8 @@ pub enum Error { OutOfRange, } -pub trait Backend { +#[clonable] +trait Backend: Clone { fn id(&self) -> Option; fn supported_features(&self) -> Features; fn speak(&mut self, text: &str, interrupt: bool) -> Result, Error>; @@ -148,6 +151,7 @@ lazy_static! { }; } +#[derive(Clone)] pub struct TTS(Box); unsafe impl Send for TTS {}