the voices::Backend trait is almost stable

This commit is contained in:
François Caddet 2020-09-28 11:18:54 +02:00
parent 3294a82485
commit d2c42d97f5
3 changed files with 16 additions and 5 deletions

View File

@ -101,7 +101,7 @@ impl AvFoundation {
rate: 0.5, rate: 0.5,
volume: 1., volume: 1.,
pitch: 1., pitch: 1.,
voice: AVSpeechSynthesisVoice::new(""), voice: AVSpeechSynthesisVoice::new(),
} }
}; };
*backend_id += 1; *backend_id += 1;
@ -231,7 +231,7 @@ impl Backend for AvFoundation {
} }
fn set_voice(&mut self, voice: &str) -> Result<(),Error> { fn set_voice(&mut self, voice: &str) -> Result<(),Error> {
self.voice = AVSpeechSynthesisVoice::new(voice); self.voice = AVSpeechSynthesisVoice::new();
Ok(()) Ok(())
} }
} }

View File

@ -14,11 +14,10 @@ use crate::voices::Gender;
pub(crate) struct AVSpeechSynthesisVoice(*const Object); pub(crate) struct AVSpeechSynthesisVoice(*const Object);
impl AVSpeechSynthesisVoice { impl AVSpeechSynthesisVoice {
pub fn new(identifier: &str) -> Self { pub fn new() -> Self {
let voice: *const Object; let voice: *const Object;
unsafe{ unsafe{
let i: id = NSString::alloc(nil).init_str(identifier); voice = msg_send![class!(AVSpeechSynthesisVoice), new];
voice = msg_send![class!(AVSpeechSynthesisVoice), voiceWithIdentifier:i];
}; };
AVSpeechSynthesisVoice{0:voice} AVSpeechSynthesisVoice{0:voice}
} }
@ -27,6 +26,14 @@ impl AVSpeechSynthesisVoice {
impl voices::Backend for AVSpeechSynthesisVoice { impl voices::Backend for AVSpeechSynthesisVoice {
type Backend = AvFoundation; type Backend = AvFoundation;
fn from_id(id: String) -> Self {
unimplemented!()
}
fn from_language(lang: voices::LanguageIdentifier) -> Self {
unimplemented!()
}
fn list() -> Vec<Self> { fn list() -> Vec<Self> {
let voices: CFArray = unsafe{msg_send![class!(AVSpeechSynthesisVoice), speechVoices]}; let voices: CFArray = unsafe{msg_send![class!(AVSpeechSynthesisVoice), speechVoices]};
voices.iter().map(|v| { voices.iter().map(|v| {

View File

@ -9,9 +9,13 @@ pub enum Gender {
pub trait Backend: Sized { pub trait Backend: Sized {
type Backend: crate::Backend; type Backend: crate::Backend;
fn from_id(id: String) -> Self;
fn from_language(lang: LanguageIdentifier) -> Self;
fn list() -> Vec<Self>; fn list() -> Vec<Self>;
fn name(self) -> String; fn name(self) -> String;
fn gender(self) -> Gender; fn gender(self) -> Gender;
fn id(self) -> String; fn id(self) -> String;
fn language(self) -> LanguageIdentifier; fn language(self) -> LanguageIdentifier;
} }
pub struct Voice<T: Backend + Sized>(Box<T>);