From 22ae0ef5a34950980d44069884f4d0463b326798 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Mon, 21 Nov 2022 12:00:35 -0600 Subject: [PATCH] Refactor to oxilangtag for language codes, and bump Windows dependency. --- Cargo.toml | 4 ++-- src/backends/speech_dispatcher.rs | 6 +++--- src/backends/web.rs | 6 +++--- src/backends/winrt.rs | 5 ++--- src/lib.rs | 6 +++--- 5 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 1627c7b..3bdf75e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 } diff --git a/src/backends/speech_dispatcher.rs b/src/backends/speech_dispatcher.rs index 7abc05a..73f75a4 100644 --- a/src/backends/speech_dispatcher.rs +++ b/src/backends/speech_dispatcher.rs @@ -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::>(); Ok(rv) diff --git a/src/backends/web.rs b/src/backends/web.rs index 578a213..a40cf86 100644 --- a/src/backends/web.rs +++ b/src/backends/web.rs @@ -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 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(), diff --git a/src/backends/winrt.rs b/src/backends/winrt.rs index 70d765f..009243c 100644 --- a/src/backends/winrt.rs +++ b/src/backends/winrt.rs @@ -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 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()?, diff --git a/src/lib.rs b/src/lib.rs index 86dcbd9..9269dbf 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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, - pub(crate) language: LanguageIdentifier, + pub(crate) language: LanguageTag, } impl Voice { @@ -675,7 +675,7 @@ impl Voice { self.gender } - pub fn language(&self) -> LanguageIdentifier { + pub fn language(&self) -> LanguageTag { self.language.clone() } }