|
|
|
@ -1,25 +1,24 @@
|
|
|
|
|
|
|
|
|
|
use objc::runtime::*;
|
|
|
|
|
use objc::*;
|
|
|
|
|
use core_foundation::array::CFArray;
|
|
|
|
|
use cocoa_foundation::base::{id, nil};
|
|
|
|
|
use cocoa_foundation::foundation::NSString;
|
|
|
|
|
use cocoa_foundation::base::{nil,id};
|
|
|
|
|
use core_foundation::array::CFArray;
|
|
|
|
|
use core_foundation::string::CFString;
|
|
|
|
|
use objc::runtime::*;
|
|
|
|
|
use objc::*;
|
|
|
|
|
|
|
|
|
|
use crate::backends::AvFoundation;
|
|
|
|
|
use crate::voices;
|
|
|
|
|
use crate::voices::Gender;
|
|
|
|
|
|
|
|
|
|
#[derive(Copy,Clone, Debug)]
|
|
|
|
|
#[derive(Copy, Clone, Debug)]
|
|
|
|
|
pub(crate) struct AVSpeechSynthesisVoice(*const Object);
|
|
|
|
|
|
|
|
|
|
impl AVSpeechSynthesisVoice {
|
|
|
|
|
pub fn new() -> Self {
|
|
|
|
|
let voice: *const Object;
|
|
|
|
|
unsafe{
|
|
|
|
|
unsafe {
|
|
|
|
|
voice = msg_send![class!(AVSpeechSynthesisVoice), new];
|
|
|
|
|
};
|
|
|
|
|
AVSpeechSynthesisVoice{0:voice}
|
|
|
|
|
AVSpeechSynthesisVoice { 0: voice }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -35,19 +34,22 @@ impl voices::Backend for AVSpeechSynthesisVoice {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn list() -> Vec<Self> {
|
|
|
|
|
let voices: CFArray = unsafe{msg_send![class!(AVSpeechSynthesisVoice), speechVoices]};
|
|
|
|
|
voices.iter().map(|v| {
|
|
|
|
|
AVSpeechSynthesisVoice{0: *v as *const Object}
|
|
|
|
|
}).collect()
|
|
|
|
|
let voices: CFArray = unsafe { msg_send![class!(AVSpeechSynthesisVoice), speechVoices] };
|
|
|
|
|
voices
|
|
|
|
|
.iter()
|
|
|
|
|
.map(|v| AVSpeechSynthesisVoice {
|
|
|
|
|
0: *v as *const Object,
|
|
|
|
|
})
|
|
|
|
|
.collect()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn name(self) -> String {
|
|
|
|
|
let name: CFString = unsafe{msg_send![self.0, name]};
|
|
|
|
|
let name: CFString = unsafe { msg_send![self.0, name] };
|
|
|
|
|
name.to_string()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn gender(self) -> Gender {
|
|
|
|
|
let gender: i64 = unsafe{ msg_send![self.0, gender] };
|
|
|
|
|
let gender: i64 = unsafe { msg_send![self.0, gender] };
|
|
|
|
|
match gender {
|
|
|
|
|
1 => Gender::Male,
|
|
|
|
|
2 => Gender::Female,
|
|
|
|
@ -56,12 +58,12 @@ impl voices::Backend for AVSpeechSynthesisVoice {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn id(self) -> String {
|
|
|
|
|
let identifier: CFString = unsafe{msg_send![self.0, identifier]};
|
|
|
|
|
let identifier: CFString = unsafe { msg_send![self.0, identifier] };
|
|
|
|
|
identifier.to_string()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn language(self) -> voices::LanguageIdentifier {
|
|
|
|
|
let lang: CFString = unsafe{msg_send![self.0, language]};
|
|
|
|
|
let lang: CFString = unsafe { msg_send![self.0, language] };
|
|
|
|
|
lang.to_string().parse().unwrap()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|