From 3294a82485d94e22138b444e84d0a791d094c20f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Caddet?= Date: Sun, 27 Sep 2020 20:35:40 +0200 Subject: [PATCH] some fixes now build on macOS --- src/backends/av_foundation.rs | 9 +++++---- src/backends/av_foundation/voices.rs | 2 +- src/voices.rs | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 src/voices.rs diff --git a/src/backends/av_foundation.rs b/src/backends/av_foundation.rs index 6940e07..445b3c9 100644 --- a/src/backends/av_foundation.rs +++ b/src/backends/av_foundation.rs @@ -10,9 +10,10 @@ use objc::runtime::{Object, Sel}; use objc::{class, declare::ClassDecl, msg_send, sel, sel_impl}; use crate::{Backend, BackendId, Error, Features, UtteranceId, CALLBACKS}; +use crate::voices::Backend as VoiceBackend; mod voices; -use voices::AVSpeechSynthesisVoice; +use voices::*; pub(crate) struct AvFoundation { id: BackendId, @@ -100,7 +101,7 @@ impl AvFoundation { rate: 0.5, volume: 1., pitch: 1., - voice: AVSpeechSynthesisVoice::default(), + voice: AVSpeechSynthesisVoice::new(""), } }; *backend_id += 1; @@ -222,11 +223,11 @@ impl Backend for AvFoundation { } fn voice(&self) -> Result { - Ok(self.voice.identifier()) + Ok(self.voice.id()) } fn list_voices(&self) -> Vec { - AVSpeechSynthesisVoice::list().iter().map(|v| {v.identifier()}).collect() + AVSpeechSynthesisVoice::list().iter().map(|v| {v.id()}).collect() } fn set_voice(&mut self, voice: &str) -> Result<(),Error> { diff --git a/src/backends/av_foundation/voices.rs b/src/backends/av_foundation/voices.rs index b8ee960..32ae9a2 100644 --- a/src/backends/av_foundation/voices.rs +++ b/src/backends/av_foundation/voices.rs @@ -11,7 +11,7 @@ use crate::voices; use crate::voices::Gender; #[derive(Copy,Clone)] -pub struct AVSpeechSynthesisVoice(*const Object); +pub(crate) struct AVSpeechSynthesisVoice(*const Object); impl AVSpeechSynthesisVoice { pub fn new(identifier: &str) -> Self { diff --git a/src/voices.rs b/src/voices.rs new file mode 100644 index 0000000..031fcdd --- /dev/null +++ b/src/voices.rs @@ -0,0 +1,17 @@ + +pub use unic_langid::LanguageIdentifier; + +pub enum Gender { + Other, + Male, + Female, +} + +pub trait Backend: Sized { + type Backend: crate::Backend; + fn list() -> Vec; + fn name(self) -> String; + fn gender(self) -> Gender; + fn id(self) -> String; + fn language(self) -> LanguageIdentifier; +}