1
0
mirror of https://github.com/ndarilek/tts-rs.git synced 2024-11-17 13:09:37 +00:00

Support Speech Dispatcher initialization failures, and bump version.

This commit is contained in:
Nolan Darilek 2021-11-19 09:22:05 -06:00
parent 57ffbf0e4f
commit 47e164a0c8
3 changed files with 15 additions and 9 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "tts"
version = "0.18.3"
version = "0.19.0"
authors = ["Nolan Darilek <nolan@thewordnerd.info>"]
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"

View File

@ -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<Self, Error> {
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)
}
}

View File

@ -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<Tts, Error> {
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()?;