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

Refactor to oxilangtag for language codes, and bump Windows dependency.

This commit is contained in:
Nolan Darilek 2022-11-21 12:00:35 -06:00
parent f5716c48f5
commit 22ae0ef5a3
5 changed files with 13 additions and 14 deletions

View File

@ -18,18 +18,18 @@ default = ["speech_dispatcher_0_11"]
[dependencies]
dyn-clonable = "0.9"
oxilangtag = "0.1"
lazy_static = "1"
log = "0.4"
serde = { version = "1", optional = true, features = ["derive"] }
thiserror = "1"
unic-langid = "0.9.0"
[dev-dependencies]
env_logger = "0.9"
[target.'cfg(windows)'.dependencies]
tolk = { version = "0.5", optional = true }
windows = { version = "0.42", features = ["Foundation", "Foundation_Collections", "Media_Core", "Media_Playback", "Media_SpeechSynthesis", "Storage_Streams"] }
windows = { version = "0.43", features = ["Foundation", "Foundation_Collections", "Media_Core", "Media_Playback", "Media_SpeechSynthesis", "Storage_Streams"] }
[target.'cfg(target_os = "linux")'.dependencies]
speech-dispatcher = { version = "0.15", default-features = false }

View File

@ -1,10 +1,10 @@
#[cfg(target_os = "linux")]
use std::{collections::HashMap, str::FromStr, sync::Mutex};
use std::{collections::HashMap, sync::Mutex};
use lazy_static::*;
use log::{info, trace};
use oxilangtag::LanguageTag;
use speech_dispatcher::*;
use unic_langid::LanguageIdentifier;
use crate::{Backend, BackendId, Error, Features, UtteranceId, Voice, CALLBACKS};
@ -192,7 +192,7 @@ impl Backend for SpeechDispatcher {
id: v.name.clone(),
name: v.name.clone(),
gender: None,
language: LanguageIdentifier::from_str(&v.language).unwrap(),
language: LanguageTag::parse(v.language.clone()).unwrap(),
})
.collect::<Vec<Voice>>();
Ok(rv)

View File

@ -1,9 +1,9 @@
#[cfg(target_arch = "wasm32")]
use std::{str::FromStr, sync::Mutex};
use std::sync::Mutex;
use lazy_static::lazy_static;
use log::{info, trace};
use unic_langid::LanguageIdentifier;
use oxilangtag::LanguageTag;
use wasm_bindgen::prelude::*;
use wasm_bindgen::JsCast;
use web_sys::{
@ -264,7 +264,7 @@ impl Drop for Web {
impl From<SpeechSynthesisVoice> for Voice {
fn from(other: SpeechSynthesisVoice) -> Self {
let language = LanguageIdentifier::from_str(&other.lang()).unwrap();
let language = LanguageTag::parse(other.lang()).unwrap();
Voice {
id: other.voice_uri(),
name: other.name(),

View File

@ -1,13 +1,12 @@
#[cfg(windows)]
use std::{
collections::{HashMap, VecDeque},
str::FromStr,
sync::Mutex,
};
use lazy_static::lazy_static;
use log::{info, trace};
use unic_langid::LanguageIdentifier;
use oxilangtag::LanguageTag;
use windows::{
Foundation::TypedEventHandler,
Media::{
@ -354,7 +353,7 @@ impl TryInto<Voice> for VoiceInformation {
Gender::Female
};
let language: String = self.Language()?.try_into()?;
let language = LanguageIdentifier::from_str(&language).unwrap();
let language = LanguageTag::parse(language).unwrap();
Ok(Voice {
id: self.Id()?.try_into()?,
name: self.DisplayName()?.try_into()?,

View File

@ -22,6 +22,7 @@ use std::{boxed::Box, sync::RwLock};
#[cfg(any(target_os = "macos", target_os = "ios"))]
use cocoa_foundation::base::id;
use dyn_clonable::*;
pub use oxilangtag::LanguageTag;
use lazy_static::lazy_static;
#[cfg(target_os = "macos")]
use libc::c_char;
@ -32,7 +33,6 @@ use speech_dispatcher::Error as SpeechDispatcherError;
use thiserror::Error;
#[cfg(all(windows, feature = "tolk"))]
use tolk::Tolk;
pub use unic_langid::LanguageIdentifier;
mod backends;
@ -659,7 +659,7 @@ pub struct Voice {
pub(crate) id: String,
pub(crate) name: String,
pub(crate) gender: Option<Gender>,
pub(crate) language: LanguageIdentifier,
pub(crate) language: LanguageTag<String>,
}
impl Voice {
@ -675,7 +675,7 @@ impl Voice {
self.gender
}
pub fn language(&self) -> LanguageIdentifier {
pub fn language(&self) -> LanguageTag<String> {
self.language.clone()
}
}