1
0
mirror of https://github.com/ndarilek/tts-rs.git synced 2024-11-17 13:49:36 +00:00

Implement unused framework for AVFoundation callbacks.

This commit is contained in:
Nolan Darilek 2020-09-23 11:28:56 -05:00
parent 36a12597de
commit bd57075d53
4 changed files with 34 additions and 11 deletions

View File

@ -7,12 +7,12 @@ use objc::declare::ClassDecl;
use objc::runtime::*;
use objc::*;
use crate::{Backend, Error, Features, UtteranceId};
use crate::{Backend, BackendId, Error, Features, UtteranceId};
pub struct AppKit(*mut Object, *mut Object);
pub(crate) struct AppKit(*mut Object, *mut Object);
impl AppKit {
pub fn new() -> Self {
pub(crate) fn new() -> Self {
info!("Initializing AppKit backend");
unsafe {
let obj: *mut Object = msg_send![class!(NSSpeechSynthesizer), new];
@ -91,6 +91,10 @@ impl AppKit {
}
impl Backend for AppKit {
fn id(&self) -> Option<BackendId> {
None
}
fn supported_features(&self) -> Features {
Features {
stop: true,

View File

@ -1,36 +1,52 @@
#[cfg(any(target_os = "macos", target_os = "ios"))]
#[link(name = "AVFoundation", kind = "framework")]
use std::sync::Mutex;
use cocoa_foundation::base::{id, nil};
use cocoa_foundation::foundation::NSString;
use lazy_static::lazy_static;
use log::{info, trace};
use objc::runtime::*;
use objc::*;
use crate::{Backend, Error, Features, UtteranceId};
use crate::{Backend, BackendId, Error, Features, UtteranceId};
pub struct AvFoundation {
pub(crate) struct AvFoundation {
id: BackendId,
synth: *mut Object,
rate: f32,
volume: f32,
pitch: f32,
}
lazy_static! {
static ref NEXT_BACKEND_ID: Mutex<u64> = Mutex::new(0);
}
impl AvFoundation {
pub fn new() -> Self {
pub(crate) fn new() -> Self {
info!("Initializing AVFoundation backend");
unsafe {
let mut backend_id = NEXT_BACKEND_ID.lock().unwrap();
let rv = unsafe {
let synth: *mut Object = msg_send![class!(AVSpeechSynthesizer), new];
AvFoundation {
id: BackendId::AvFoundation(*backend_id),
synth: synth,
rate: 0.5,
volume: 1.,
pitch: 1.,
}
}
};
*backend_id += 1;
rv
}
}
impl Backend for AvFoundation {
fn id(&self) -> Option<BackendId> {
Some(self.id)
}
fn supported_features(&self) -> Features {
Features {
stop: true,
@ -38,6 +54,7 @@ impl Backend for AvFoundation {
pitch: true,
volume: true,
is_speaking: true,
utterance_callbacks: true,
}
}

View File

@ -26,7 +26,7 @@ pub use self::tolk::*;
pub use self::web::*;
#[cfg(target_os = "macos")]
pub use self::appkit::*;
pub(crate) use self::appkit::*;
#[cfg(any(target_os = "macos", target_os = "ios"))]
pub use self::av_foundation::*;
pub(crate) use self::av_foundation::*;

View File

@ -55,7 +55,7 @@ pub enum BackendId {
#[cfg(windows)]
WinRT(u64),
#[cfg(any(target_os = "macos", target_os = "ios"))]
AvFoundation(id),
AvFoundation(u64),
}
#[derive(Clone, Debug, PartialEq)]
@ -66,6 +66,8 @@ pub enum UtteranceId {
Web(u64),
#[cfg(windows)]
WinRT(MediaPlaybackItem),
#[cfg(any(target_os = "macos", target_os = "ios"))]
AvFoundation(id),
}
pub struct Features {