This commit is contained in:
Lee Baker 2022-10-11 22:34:51 +02:00 committed by GitHub
commit 9d06613f38
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 101 additions and 96 deletions

View File

@ -7,7 +7,7 @@ use core_foundation::array::CFArray;
use core_foundation::string::CFString; use core_foundation::string::CFString;
use lazy_static::lazy_static; use lazy_static::lazy_static;
use log::{info, trace}; use log::{info, trace};
use objc::runtime::{Object, Sel}; use objc::runtime::{Class, Object, Sel};
use objc::{class, declare::ClassDecl, msg_send, sel, sel_impl}; use objc::{class, declare::ClassDecl, msg_send, sel, sel_impl};
use unic_langid::LanguageIdentifier; use unic_langid::LanguageIdentifier;
@ -24,13 +24,7 @@ pub(crate) struct AvFoundation {
voice: Option<Voice>, voice: Option<Voice>,
} }
lazy_static! { fn make_speech_sythesizer_delegate() -> Result<&'static Class, Error> {
static ref NEXT_BACKEND_ID: Mutex<u64> = Mutex::new(0);
}
impl AvFoundation {
pub(crate) fn new() -> Result<Self, Error> {
info!("Initializing AVFoundation backend");
let mut decl = ClassDecl::new("MyNSSpeechSynthesizerDelegate", class!(NSObject)) let mut decl = ClassDecl::new("MyNSSpeechSynthesizerDelegate", class!(NSObject))
.ok_or(Error::OperationFailed)?; .ok_or(Error::OperationFailed)?;
decl.add_ivar::<u64>("backend_id"); decl.add_ivar::<u64>("backend_id");
@ -125,8 +119,19 @@ impl AvFoundation {
); );
} }
let delegate_class = decl.register(); Ok(decl.register())
let delegate_obj: *mut Object = unsafe { msg_send![delegate_class, new] }; }
lazy_static! {
static ref NEXT_BACKEND_ID: Mutex<u64> = Mutex::new(0);
static ref DELEGATE_CLASS: &'static Class = make_speech_sythesizer_delegate().unwrap();
}
impl AvFoundation {
pub(crate) fn new() -> Result<Self, Error> {
info!("Initializing AVFoundation backend");
let delegate_obj: *mut Object = unsafe { msg_send![*DELEGATE_CLASS, new] };
let mut backend_id = NEXT_BACKEND_ID.lock().unwrap(); let mut backend_id = NEXT_BACKEND_ID.lock().unwrap();
let rv = unsafe { let rv = unsafe {
trace!("Creating synth"); trace!("Creating synth");