Implement stop callback on MacOS.

This commit is contained in:
Nolan Darilek 2020-10-08 08:07:33 -05:00
parent 8c783205c3
commit 6f12974ce4
1 changed files with 23 additions and 0 deletions

View File

@ -66,6 +66,24 @@ impl AvFoundation {
}
}
extern "C" fn speech_synthesizer_did_cancel_speech_utterance(
this: &Object,
_: Sel,
_synth: *const Object,
utterance: id,
) {
unsafe {
let backend_id: u64 = *this.get_ivar("backend_id");
let backend_id = BackendId::AvFoundation(backend_id);
let mut callbacks = CALLBACKS.lock().unwrap();
let callbacks = callbacks.get_mut(&backend_id).unwrap();
if let Some(callback) = callbacks.utterance_stop.as_mut() {
let utterance_id = UtteranceId::AvFoundation(utterance);
callback(utterance_id);
}
}
}
unsafe {
decl.add_method(
sel!(speechSynthesizer:didStartSpeechUtterance:),
@ -77,6 +95,11 @@ impl AvFoundation {
speech_synthesizer_did_finish_speech_utterance
as extern "C" fn(&Object, Sel, *const Object, id) -> (),
);
decl.add_method(
sel!(speechSynthesizer:didCancelSpeechUtterance:),
speech_synthesizer_did_cancel_speech_utterance
as extern "C" fn(&Object, Sel, *const Object, id) -> (),
);
}
let delegate_class = decl.register();