From 47e164a0c8267c03384e5fe256ec00ab95c58917 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Fri, 19 Nov 2021 09:22:05 -0600 Subject: [PATCH] Support Speech Dispatcher initialization failures, and bump version. --- Cargo.toml | 4 ++-- src/backends/speech_dispatcher.rs | 9 ++++----- src/lib.rs | 11 +++++++++-- 3 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index c2542a9..fc478ea 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "tts" -version = "0.18.3" +version = "0.19.0" authors = ["Nolan Darilek "] repository = "https://github.com/ndarilek/tts-rs" description = "High-level Text-To-Speech (TTS) interface" @@ -25,7 +25,7 @@ tolk = { version = "0.5", optional = true } windows = { version = "0.27", features = ["alloc", "std", "Foundation", "Media_Core", "Media_Playback", "Media_SpeechSynthesis", "Storage_Streams"] } [target.'cfg(target_os = "linux")'.dependencies] -speech-dispatcher = "0.7" +speech-dispatcher = "0.8" [target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies] cocoa-foundation = "0.1" diff --git a/src/backends/speech_dispatcher.rs b/src/backends/speech_dispatcher.rs index 39c7fd8..bd373c4 100644 --- a/src/backends/speech_dispatcher.rs +++ b/src/backends/speech_dispatcher.rs @@ -1,6 +1,5 @@ #[cfg(target_os = "linux")] -use std::collections::HashMap; -use std::sync::Mutex; +use std::{collections::HashMap, sync::Mutex}; use lazy_static::*; use log::{info, trace}; @@ -19,9 +18,9 @@ lazy_static! { } impl SpeechDispatcher { - pub(crate) fn new() -> Self { + pub(crate) fn new() -> std::result::Result { info!("Initializing SpeechDispatcher backend"); - let connection = speech_dispatcher::Connection::open("tts", "tts", "tts", Mode::Threaded); + let connection = speech_dispatcher::Connection::open("tts", "tts", "tts", Mode::Threaded)?; let sd = SpeechDispatcher(connection); let mut speaking = SPEAKING.lock().unwrap(); speaking.insert(sd.0.client_id(), false); @@ -66,7 +65,7 @@ impl SpeechDispatcher { let mut speaking = SPEAKING.lock().unwrap(); speaking.insert(client_id, true); }))); - sd + Ok(sd) } } diff --git a/src/lib.rs b/src/lib.rs index 4247435..9488daa 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -26,6 +26,7 @@ use lazy_static::lazy_static; use libc::c_char; #[cfg(target_os = "macos")] use objc::{class, msg_send, sel, sel_impl}; +use speech_dispatcher::SpeechDispatcherError; use thiserror::Error; #[cfg(all(windows, feature = "tolk"))] use tolk::Tolk; @@ -113,8 +114,11 @@ pub enum Error { #[error("Operation failed")] OperationFailed, #[cfg(target_arch = "wasm32")] - #[error("JavaScript error: [0])]")] + #[error("JavaScript error: [0]")] JavaScriptError(wasm_bindgen::JsValue), + #[cfg(target_os = "linux")] + #[error("Speech Dispatcher error: {0}")] + SpeechDispatcher(#[from] SpeechDispatcherError), #[cfg(windows)] #[error("WinRT error")] WinRt(windows::core::Error), @@ -183,7 +187,10 @@ impl Tts { pub fn new(backend: Backends) -> Result { let backend = match backend { #[cfg(target_os = "linux")] - Backends::SpeechDispatcher => Ok(Tts(Box::new(backends::SpeechDispatcher::new()))), + Backends::SpeechDispatcher => { + let tts = backends::SpeechDispatcher::new()?; + Ok(Tts(Box::new(tts))) + } #[cfg(target_arch = "wasm32")] Backends::Web => { let tts = backends::Web::new()?;