This commit is contained in:
Lee C. Baker 2024-02-19 15:26:58 +08:00 committed by GitHub
commit a2e8e201cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 101 additions and 96 deletions

View File

@ -8,7 +8,7 @@ use core_foundation::base::TCFType;
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 oxilangtag::LanguageTag; use oxilangtag::LanguageTag;
@ -25,13 +25,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");
@ -126,8 +120,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");