From d2c42d97f5313f4c2ca5972b02f6f309374a635b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Caddet?= Date: Mon, 28 Sep 2020 11:18:54 +0200 Subject: [PATCH] the voices::Backend trait is almost stable --- src/backends/av_foundation.rs | 4 ++-- src/backends/av_foundation/voices.rs | 13 ++++++++++--- src/voices.rs | 4 ++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/backends/av_foundation.rs b/src/backends/av_foundation.rs index 445b3c9..7e3590f 100644 --- a/src/backends/av_foundation.rs +++ b/src/backends/av_foundation.rs @@ -101,7 +101,7 @@ impl AvFoundation { rate: 0.5, volume: 1., pitch: 1., - voice: AVSpeechSynthesisVoice::new(""), + voice: AVSpeechSynthesisVoice::new(), } }; *backend_id += 1; @@ -231,7 +231,7 @@ impl Backend for AvFoundation { } fn set_voice(&mut self, voice: &str) -> Result<(),Error> { - self.voice = AVSpeechSynthesisVoice::new(voice); + self.voice = AVSpeechSynthesisVoice::new(); Ok(()) } } diff --git a/src/backends/av_foundation/voices.rs b/src/backends/av_foundation/voices.rs index 32ae9a2..71bf8c1 100644 --- a/src/backends/av_foundation/voices.rs +++ b/src/backends/av_foundation/voices.rs @@ -14,11 +14,10 @@ use crate::voices::Gender; pub(crate) struct AVSpeechSynthesisVoice(*const Object); impl AVSpeechSynthesisVoice { - pub fn new(identifier: &str) -> Self { + pub fn new() -> Self { let voice: *const Object; unsafe{ - let i: id = NSString::alloc(nil).init_str(identifier); - voice = msg_send![class!(AVSpeechSynthesisVoice), voiceWithIdentifier:i]; + voice = msg_send![class!(AVSpeechSynthesisVoice), new]; }; AVSpeechSynthesisVoice{0:voice} } @@ -27,6 +26,14 @@ impl AVSpeechSynthesisVoice { impl voices::Backend for AVSpeechSynthesisVoice { type Backend = AvFoundation; + fn from_id(id: String) -> Self { + unimplemented!() + } + + fn from_language(lang: voices::LanguageIdentifier) -> Self { + unimplemented!() + } + fn list() -> Vec { let voices: CFArray = unsafe{msg_send![class!(AVSpeechSynthesisVoice), speechVoices]}; voices.iter().map(|v| { diff --git a/src/voices.rs b/src/voices.rs index 031fcdd..8ca927d 100644 --- a/src/voices.rs +++ b/src/voices.rs @@ -9,9 +9,13 @@ pub enum Gender { pub trait Backend: Sized { type Backend: crate::Backend; + fn from_id(id: String) -> Self; + fn from_language(lang: LanguageIdentifier) -> Self; fn list() -> Vec; fn name(self) -> String; fn gender(self) -> Gender; fn id(self) -> String; fn language(self) -> LanguageIdentifier; } + +pub struct Voice(Box);