mirror of
https://github.com/ndarilek/tts-rs.git
synced 2024-11-23 06:49:38 +00:00
Make TTS
clonable.
Also, add other possibly useful derives.
This commit is contained in:
parent
565aa6d654
commit
551bb1292e
|
@ -16,6 +16,7 @@ crate-type = ["lib", "cdylib", "staticlib"]
|
||||||
use_tolk = ["tolk"]
|
use_tolk = ["tolk"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
dyn-clonable = "0.9"
|
||||||
lazy_static = "1"
|
lazy_static = "1"
|
||||||
log = "0.4"
|
log = "0.4"
|
||||||
thiserror = "1"
|
thiserror = "1"
|
||||||
|
@ -24,7 +25,7 @@ thiserror = "1"
|
||||||
env_logger = "0.8"
|
env_logger = "0.8"
|
||||||
|
|
||||||
[target.'cfg(windows)'.dependencies]
|
[target.'cfg(windows)'.dependencies]
|
||||||
tolk = { version = ">= 0.2.1", optional = true }
|
tolk = { version = "0.3", optional = true }
|
||||||
winrt = "0.7"
|
winrt = "0.7"
|
||||||
tts_winrt_bindings = { version = "0.1", path="winrt_bindings" }
|
tts_winrt_bindings = { version = "0.1", path="winrt_bindings" }
|
||||||
|
|
||||||
|
|
|
@ -9,6 +9,7 @@ use objc::*;
|
||||||
|
|
||||||
use crate::{Backend, BackendId, Error, Features, UtteranceId};
|
use crate::{Backend, BackendId, Error, Features, UtteranceId};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub(crate) struct AppKit(*mut Object, *mut Object);
|
pub(crate) struct AppKit(*mut Object, *mut Object);
|
||||||
|
|
||||||
impl AppKit {
|
impl AppKit {
|
||||||
|
|
|
@ -11,6 +11,7 @@ use objc::{class, declare::ClassDecl, msg_send, sel, sel_impl};
|
||||||
|
|
||||||
use crate::{Backend, BackendId, Error, Features, UtteranceId, CALLBACKS};
|
use crate::{Backend, BackendId, Error, Features, UtteranceId, CALLBACKS};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub(crate) struct AvFoundation {
|
pub(crate) struct AvFoundation {
|
||||||
id: BackendId,
|
id: BackendId,
|
||||||
delegate: *mut Object,
|
delegate: *mut Object,
|
||||||
|
|
|
@ -8,6 +8,7 @@ use speech_dispatcher::*;
|
||||||
|
|
||||||
use crate::{Backend, BackendId, Error, Features, UtteranceId, CALLBACKS};
|
use crate::{Backend, BackendId, Error, Features, UtteranceId, CALLBACKS};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub(crate) struct SpeechDispatcher(Connection);
|
pub(crate) struct SpeechDispatcher(Connection);
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
|
|
|
@ -4,6 +4,7 @@ use tolk::Tolk as TolkPtr;
|
||||||
|
|
||||||
use crate::{Backend, BackendId, Error, Features, UtteranceId};
|
use crate::{Backend, BackendId, Error, Features, UtteranceId};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub(crate) struct Tolk(TolkPtr);
|
pub(crate) struct Tolk(TolkPtr);
|
||||||
|
|
||||||
impl Tolk {
|
impl Tolk {
|
||||||
|
|
|
@ -12,6 +12,7 @@ use web_sys::{
|
||||||
|
|
||||||
use crate::{Backend, BackendId, Error, Features, UtteranceId, CALLBACKS};
|
use crate::{Backend, BackendId, Error, Features, UtteranceId, CALLBACKS};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct Web {
|
pub struct Web {
|
||||||
id: BackendId,
|
id: BackendId,
|
||||||
rate: f32,
|
rate: f32,
|
||||||
|
|
|
@ -21,6 +21,7 @@ impl From<winrt::Error> for Error {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
pub struct WinRT {
|
pub struct WinRT {
|
||||||
id: BackendId,
|
id: BackendId,
|
||||||
synth: SpeechSynthesizer,
|
synth: SpeechSynthesizer,
|
||||||
|
|
|
@ -19,6 +19,7 @@ use std::sync::Mutex;
|
||||||
|
|
||||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||||
use cocoa_foundation::base::id;
|
use cocoa_foundation::base::id;
|
||||||
|
use dyn_clonable::*;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
use libc::c_char;
|
use libc::c_char;
|
||||||
|
@ -28,6 +29,7 @@ use thiserror::Error;
|
||||||
|
|
||||||
mod backends;
|
mod backends;
|
||||||
|
|
||||||
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub enum Backends {
|
pub enum Backends {
|
||||||
#[cfg(target_os = "linux")]
|
#[cfg(target_os = "linux")]
|
||||||
SpeechDispatcher,
|
SpeechDispatcher,
|
||||||
|
@ -107,7 +109,8 @@ pub enum Error {
|
||||||
OutOfRange,
|
OutOfRange,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait Backend {
|
#[clonable]
|
||||||
|
trait Backend: Clone {
|
||||||
fn id(&self) -> Option<BackendId>;
|
fn id(&self) -> Option<BackendId>;
|
||||||
fn supported_features(&self) -> Features;
|
fn supported_features(&self) -> Features;
|
||||||
fn speak(&mut self, text: &str, interrupt: bool) -> Result<Option<UtteranceId>, Error>;
|
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>);
|
pub struct TTS(Box<dyn Backend>);
|
||||||
|
|
||||||
unsafe impl Send for TTS {}
|
unsafe impl Send for TTS {}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user