1
0
mirror of https://github.com/ndarilek/tts-rs.git synced 2024-07-22 05:19:38 +00:00

Make TTS clonable.

Also, add other possibly useful derives.
This commit is contained in:
Nolan Darilek 2020-11-02 21:27:13 -06:00
parent 565aa6d654
commit 551bb1292e
8 changed files with 13 additions and 2 deletions

View File

@ -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" }

View File

@ -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 {

View File

@ -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,

View File

@ -8,6 +8,7 @@ use speech_dispatcher::*;
use crate::{Backend, BackendId, Error, Features, UtteranceId, CALLBACKS};
#[derive(Clone)]
pub(crate) struct SpeechDispatcher(Connection);
lazy_static! {

View File

@ -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 {

View File

@ -12,6 +12,7 @@ use web_sys::{
use crate::{Backend, BackendId, Error, Features, UtteranceId, CALLBACKS};
#[derive(Clone)]
pub struct Web {
id: BackendId,
rate: f32,

View File

@ -21,6 +21,7 @@ impl From<winrt::Error> for Error {
}
}
#[derive(Clone)]
pub struct WinRT {
id: BackendId,
synth: SpeechSynthesizer,

View File

@ -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<BackendId>;
fn supported_features(&self) -> Features;
fn speak(&mut self, text: &str, interrupt: bool) -> Result<Option<UtteranceId>, Error>;
@ -148,6 +151,7 @@ lazy_static! {
};
}
#[derive(Clone)]
pub struct TTS(Box<dyn Backend>);
unsafe impl Send for TTS {}