mirror of https://github.com/ndarilek/tts-rs.git
Make speech-dispatcher opt-in so we can avoid LGPL by default
This commit is contained in:
parent
4466923620
commit
6e8057b023
|
@ -26,7 +26,7 @@ tolk = { version = "0.5", optional = true }
|
|||
windows = { version = "0.30", features = ["alloc", "Foundation", "Media_Core", "Media_Playback", "Media_SpeechSynthesis", "Storage_Streams"] }
|
||||
|
||||
[target.'cfg(target_os = "linux")'.dependencies]
|
||||
speech-dispatcher = "0.11"
|
||||
speech-dispatcher = { version = "0.11", optional = true } # optional, since it is using LGPL
|
||||
|
||||
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies]
|
||||
cocoa-foundation = "0.1"
|
||||
|
@ -39,4 +39,4 @@ web-sys = { version = "0.3", features = ["EventTarget", "SpeechSynthesis", "Spee
|
|||
|
||||
[target.'cfg(target_os="android")'.dependencies]
|
||||
jni = "0.19"
|
||||
ndk-glue = "0.6"
|
||||
ndk-glue = "0.6"
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#[cfg(target_os = "linux")]
|
||||
#[cfg(feature = "speech_dispatcher")]
|
||||
mod speech_dispatcher;
|
||||
|
||||
#[cfg(all(windows, feature = "tolk"))]
|
||||
|
@ -19,7 +19,7 @@ mod av_foundation;
|
|||
#[cfg(target_os = "android")]
|
||||
mod android;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(feature = "speech_dispatcher")]
|
||||
pub(crate) use self::speech_dispatcher::*;
|
||||
|
||||
#[cfg(all(windows, feature = "tolk"))]
|
||||
|
|
46
src/lib.rs
46
src/lib.rs
|
@ -27,7 +27,7 @@ use lazy_static::lazy_static;
|
|||
use libc::c_char;
|
||||
#[cfg(target_os = "macos")]
|
||||
use objc::{class, msg_send, sel, sel_impl};
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(feature = "speech_dispatcher")]
|
||||
use speech_dispatcher::Error as SpeechDispatcherError;
|
||||
use thiserror::Error;
|
||||
#[cfg(all(windows, feature = "tolk"))]
|
||||
|
@ -204,7 +204,7 @@ pub enum Error {
|
|||
#[cfg(target_arch = "wasm32")]
|
||||
#[error("JavaScript error: [0]")]
|
||||
JavaScriptError(wasm_bindgen::JsValue),
|
||||
#[cfg(target_os = "linux")]
|
||||
#[cfg(feature = "speech_dispatcher")]
|
||||
#[error("Speech Dispatcher error: {0}")]
|
||||
SpeechDispatcher(#[from] SpeechDispatcherError),
|
||||
#[cfg(windows)]
|
||||
|
@ -273,50 +273,56 @@ impl Tts {
|
|||
* Create a new `TTS` instance with the specified backend.
|
||||
*/
|
||||
pub fn new(backend: Backends) -> Result<Tts, Error> {
|
||||
let backend = match backend {
|
||||
let backend: Self = match backend {
|
||||
#[cfg(target_os = "linux")]
|
||||
Backends::SpeechDispatcher => {
|
||||
let tts = backends::SpeechDispatcher::new()?;
|
||||
Ok(Tts(Box::new(tts)))
|
||||
#[cfg(feature = "speech_dispatcher")]
|
||||
{
|
||||
let tts = backends::SpeechDispatcher::new()?;
|
||||
Tts(Box::new(tts))
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "speech_dispatcher"))]
|
||||
{
|
||||
log::error!("tts must be compiled with the speech_dispatcher feature on linux");
|
||||
return Err(Error::NoneError);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
Backends::Web => {
|
||||
let tts = backends::Web::new()?;
|
||||
Ok(Tts(Box::new(tts)))
|
||||
Tts(Box::new(tts))
|
||||
}
|
||||
#[cfg(all(windows, feature = "tolk"))]
|
||||
Backends::Tolk => {
|
||||
let tts = backends::Tolk::new();
|
||||
if let Some(tts) = tts {
|
||||
Ok(Tts(Box::new(tts)))
|
||||
Tts(Box::new(tts))
|
||||
} else {
|
||||
Err(Error::NoneError)
|
||||
return Err(Error::NoneError);
|
||||
}
|
||||
}
|
||||
#[cfg(windows)]
|
||||
Backends::WinRt => {
|
||||
let tts = backends::WinRt::new()?;
|
||||
Ok(Tts(Box::new(tts)))
|
||||
Tts(Box::new(tts))
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
Backends::AppKit => Ok(Tts(Box::new(backends::AppKit::new()))),
|
||||
Backends::AppKit => Tts(Box::new(backends::AppKit::new())),
|
||||
#[cfg(any(target_os = "macos", target_os = "ios"))]
|
||||
Backends::AvFoundation => Ok(Tts(Box::new(backends::AvFoundation::new()))),
|
||||
Backends::AvFoundation => Tts(Box::new(backends::AvFoundation::new())),
|
||||
#[cfg(target_os = "android")]
|
||||
Backends::Android => {
|
||||
let tts = backends::Android::new()?;
|
||||
Ok(Tts(Box::new(tts)))
|
||||
Tts(Box::new(tts))
|
||||
}
|
||||
};
|
||||
if let Ok(backend) = backend {
|
||||
if let Some(id) = backend.0.id() {
|
||||
let mut callbacks = CALLBACKS.lock().unwrap();
|
||||
callbacks.insert(id, Callbacks::default());
|
||||
}
|
||||
Ok(backend)
|
||||
} else {
|
||||
backend
|
||||
if let Some(id) = backend.0.id() {
|
||||
let mut callbacks = CALLBACKS.lock().unwrap();
|
||||
callbacks.insert(id, Callbacks::default());
|
||||
}
|
||||
Ok(backend)
|
||||
}
|
||||
|
||||
pub fn default() -> Result<Tts, Error> {
|
||||
|
|
Loading…
Reference in New Issue