Compare commits

...

6 Commits

Author SHA1 Message Date
Nolan Darilek eb1d13976a Bump version. 2022-10-19 09:58:45 -05:00
Nolan Darilek 259549e21d
Merge pull request #34 from helgoboss:master
#33 Fix AVFoundation crash on macOS when getting voices
2022-10-19 09:58:02 -05:00
Nolan Darilek 3679ad6153
Merge pull request #36 from helgoboss:bug/35-appkit-crash
#35 Fix AppKit crash when interrupting speech
2022-10-19 09:55:15 -05:00
Benjamin Klum 94615a254a #35 Fix AppKit crash when interrupting speech
avoid removing first string when queue already empty
2022-10-16 23:18:19 +02:00
Benjamin Klum ddf96c10aa #33 Remove unnecessary unsafe keyword 2022-10-16 23:15:52 +02:00
Benjamin Klum 3fdd452646 #33 Fix AVFoundation crash on macOS when getting voices
by preventing manual cleanup of non-owned objects
2022-10-16 22:35:03 +02:00
3 changed files with 19 additions and 9 deletions

View File

@ -1,6 +1,6 @@
[package]
name = "tts"
version = "0.24.2"
version = "0.24.3"
authors = ["Nolan Darilek <nolan@thewordnerd.info>"]
repository = "https://github.com/ndarilek/tts-rs"
description = "High-level Text-To-Speech (TTS) interface"

View File

@ -46,13 +46,15 @@ impl AppKit {
) {
unsafe {
let strings: id = *this.get_ivar("strings");
let str: id = msg_send!(strings, firstObject);
let _: () = msg_send![str, release];
let _: () = msg_send!(strings, removeObjectAtIndex:0);
let count: u32 = msg_send![strings, count];
if count > 0 {
let str: id = msg_send!(strings, firstObject);
let _: BOOL = msg_send![synth, startSpeakingString: str];
let _: () = msg_send![str, release];
let _: () = msg_send!(strings, removeObjectAtIndex:0);
if count > 1 {
let str: id = msg_send!(strings, firstObject);
let _: BOOL = msg_send![synth, startSpeakingString: str];
}
}
}
}

View File

@ -4,6 +4,7 @@ use std::{str::FromStr, sync::Mutex};
use cocoa_foundation::base::{id, nil, NO};
use cocoa_foundation::foundation::NSString;
use core_foundation::array::CFArray;
use core_foundation::base::TCFType;
use core_foundation::string::CFString;
use lazy_static::lazy_static;
use log::{info, trace};
@ -290,19 +291,26 @@ impl Backend for AvFoundation {
}
fn voices(&self) -> Result<Vec<Voice>, Error> {
let voices: CFArray = unsafe { msg_send![class!(AVSpeechSynthesisVoice), speechVoices] };
let voices: CFArray = unsafe {
CFArray::wrap_under_get_rule(msg_send![class!(AVSpeechSynthesisVoice), speechVoices])
};
let rv = voices
.iter()
.map(|v| {
let id: CFString = unsafe { msg_send![*v as *const Object, identifier] };
let name: CFString = unsafe { msg_send![*v as *const Object, name] };
let id: CFString = unsafe {
CFString::wrap_under_get_rule(msg_send![*v as *const Object, identifier])
};
let name: CFString =
unsafe { CFString::wrap_under_get_rule(msg_send![*v as *const Object, name]) };
let gender: i64 = unsafe { msg_send![*v as *const Object, gender] };
let gender = match gender {
1 => Some(Gender::Male),
2 => Some(Gender::Female),
_ => None,
};
let language: CFString = unsafe { msg_send![*v as *const Object, language] };
let language: CFString = unsafe {
CFString::wrap_under_get_rule(msg_send![*v as *const Object, language])
};
let language = language.to_string();
let language = LanguageIdentifier::from_str(&language).unwrap();
Voice {