2018-01-12 17:28:39 +00:00
|
|
|
#![allow(non_upper_case_globals)]
|
|
|
|
|
2021-11-19 14:38:17 +00:00
|
|
|
use std::{
|
|
|
|
collections::HashMap,
|
|
|
|
ffi::{CStr, CString},
|
|
|
|
fmt,
|
|
|
|
marker::Send,
|
2021-12-06 18:57:04 +00:00
|
|
|
os::raw::{c_char, c_int},
|
2021-11-19 14:38:17 +00:00
|
|
|
sync::Mutex,
|
|
|
|
};
|
2018-01-12 17:28:39 +00:00
|
|
|
|
2020-08-19 22:28:22 +00:00
|
|
|
use lazy_static::lazy_static;
|
2018-01-12 17:28:39 +00:00
|
|
|
use speech_dispatcher_sys::*;
|
|
|
|
|
2020-08-19 22:28:22 +00:00
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
|
|
#[repr(u32)]
|
2018-01-12 17:28:39 +00:00
|
|
|
pub enum Mode {
|
2020-08-19 22:28:22 +00:00
|
|
|
Single = SPDConnectionMode::SPD_MODE_SINGLE,
|
|
|
|
Threaded = SPDConnectionMode::SPD_MODE_THREADED,
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 22:28:22 +00:00
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
|
|
#[repr(u32)]
|
2018-01-12 17:28:39 +00:00
|
|
|
pub enum Priority {
|
2020-08-19 22:28:22 +00:00
|
|
|
Important = SPDPriority::SPD_IMPORTANT,
|
|
|
|
Message = SPDPriority::SPD_MESSAGE,
|
|
|
|
Text = SPDPriority::SPD_TEXT,
|
|
|
|
Notification = SPDPriority::SPD_NOTIFICATION,
|
|
|
|
Progress = SPDPriority::SPD_PROGRESS,
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 22:28:22 +00:00
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
|
|
#[repr(u32)]
|
2018-01-12 17:28:39 +00:00
|
|
|
pub enum VoiceType {
|
2020-08-19 22:28:22 +00:00
|
|
|
Male1 = SPDVoiceType::SPD_MALE1,
|
|
|
|
Male2 = SPDVoiceType::SPD_MALE2,
|
|
|
|
Male3 = SPDVoiceType::SPD_MALE3,
|
|
|
|
Female1 = SPDVoiceType::SPD_FEMALE1,
|
|
|
|
Female2 = SPDVoiceType::SPD_FEMALE2,
|
|
|
|
Female3 = SPDVoiceType::SPD_FEMALE3,
|
|
|
|
ChildMale = SPDVoiceType::SPD_CHILD_MALE,
|
|
|
|
ChildFemale = SPDVoiceType::SPD_CHILD_FEMALE,
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 22:28:22 +00:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct Connection(pub *mut SPDConnection, u64);
|
2018-01-12 17:28:39 +00:00
|
|
|
|
|
|
|
pub type Address = SPDConnectionAddress;
|
|
|
|
|
2020-08-19 22:28:22 +00:00
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
|
|
#[repr(u32)]
|
2018-01-12 17:28:39 +00:00
|
|
|
pub enum DataMode {
|
2020-08-19 22:28:22 +00:00
|
|
|
Text = SPDDataMode::SPD_DATA_TEXT,
|
|
|
|
SSML = SPDDataMode::SPD_DATA_SSML,
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 22:28:22 +00:00
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
|
|
#[repr(u32)]
|
2018-01-12 17:28:39 +00:00
|
|
|
pub enum Notification {
|
2020-08-19 22:28:22 +00:00
|
|
|
Begin = SPDNotification::SPD_BEGIN,
|
|
|
|
End = SPDNotification::SPD_END,
|
|
|
|
IndexMarks = SPDNotification::SPD_INDEX_MARKS,
|
|
|
|
Cancel = SPDNotification::SPD_CANCEL,
|
|
|
|
Pause = SPDNotification::SPD_PAUSE,
|
|
|
|
Resume = SPDNotification::SPD_RESUME,
|
|
|
|
All = SPDNotification::SPD_ALL,
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 22:28:22 +00:00
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
|
|
#[repr(u32)]
|
2018-01-12 17:28:39 +00:00
|
|
|
pub enum Punctuation {
|
2020-08-19 22:28:22 +00:00
|
|
|
All = SPDPunctuation::SPD_PUNCT_ALL,
|
|
|
|
None = SPDPunctuation::SPD_PUNCT_NONE,
|
|
|
|
Some = SPDPunctuation::SPD_PUNCT_SOME,
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 22:28:22 +00:00
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
|
|
#[repr(u32)]
|
2018-01-12 17:28:39 +00:00
|
|
|
pub enum CapitalLetters {
|
2020-08-19 22:28:22 +00:00
|
|
|
None = SPDCapitalLetters::SPD_CAP_NONE,
|
|
|
|
Spell = SPDCapitalLetters::SPD_CAP_SPELL,
|
|
|
|
Icon = SPDCapitalLetters::SPD_CAP_ICON,
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
/// Converts a `0` to a success and everything else to an error.
|
|
|
|
fn c_int_to_result(r: c_int) -> Result<(), SpeechDispatcherError> {
|
|
|
|
match r {
|
|
|
|
0 => Ok(()),
|
|
|
|
_ => Err(SpeechDispatcherError::OperationFailed),
|
|
|
|
}
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 15:36:00 +00:00
|
|
|
#[derive(Default)]
|
2020-08-19 22:28:22 +00:00
|
|
|
struct Callbacks {
|
2020-09-25 15:36:00 +00:00
|
|
|
begin: Option<Box<dyn FnMut(u64, u64)>>,
|
|
|
|
end: Option<Box<dyn FnMut(u64, u64)>>,
|
|
|
|
index_mark: Option<Box<dyn FnMut(u64, u64, String)>>,
|
|
|
|
cancel: Option<Box<dyn FnMut(u64, u64)>>,
|
|
|
|
pause: Option<Box<dyn FnMut(u64, u64)>>,
|
|
|
|
resume: Option<Box<dyn FnMut(u64, u64)>>,
|
2020-08-19 22:28:22 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 15:36:00 +00:00
|
|
|
unsafe impl Send for Callbacks {}
|
|
|
|
|
|
|
|
unsafe impl Sync for Callbacks {}
|
2020-08-19 22:28:22 +00:00
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
static ref callbacks: Mutex<HashMap<u64, Callbacks>> = {
|
|
|
|
let m = HashMap::new();
|
|
|
|
Mutex::new(m)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
unsafe extern "C" fn cb(msg_id: u64, client_id: u64, state: u32) {
|
|
|
|
let state = match state {
|
|
|
|
SPDNotificationType_SPD_EVENT_BEGIN => Notification::Begin,
|
|
|
|
SPDNotificationType_SPD_EVENT_END => Notification::End,
|
|
|
|
SPDNotificationType_SPD_EVENT_CANCEL => Notification::Cancel,
|
|
|
|
SPDNotificationType_SPD_EVENT_PAUSE => Notification::Pause,
|
|
|
|
SPDNotificationType_SPD_EVENT_RESUME => Notification::Resume,
|
|
|
|
_ => panic!("Unknown notification received in callback: {}", state),
|
|
|
|
};
|
2020-09-25 15:36:00 +00:00
|
|
|
if let Some(c) = callbacks.lock().unwrap().get_mut(&client_id) {
|
2020-08-19 22:28:22 +00:00
|
|
|
let f = match state {
|
2020-09-25 15:36:00 +00:00
|
|
|
Notification::Begin => &mut c.begin,
|
|
|
|
Notification::End => &mut c.end,
|
|
|
|
Notification::Cancel => &mut c.cancel,
|
|
|
|
Notification::Pause => &mut c.pause,
|
|
|
|
Notification::Resume => &mut c.resume,
|
2020-08-19 22:28:22 +00:00
|
|
|
_ => panic!("Unknown notification type"),
|
|
|
|
};
|
2020-09-25 15:36:00 +00:00
|
|
|
if let Some(f) = f.as_mut() {
|
2020-08-20 01:59:48 +00:00
|
|
|
f(msg_id, client_id);
|
2020-08-19 22:28:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-02 13:34:32 +00:00
|
|
|
unsafe extern "C" fn cb_im(msg_id: u64, client_id: u64, state: u32, index_mark: *mut c_char) {
|
2020-08-19 22:28:22 +00:00
|
|
|
let index_mark = CStr::from_ptr(index_mark);
|
|
|
|
let index_mark = index_mark.to_string_lossy().to_string();
|
|
|
|
let state = match state {
|
|
|
|
SPDNotificationType_SPD_EVENT_INDEX_MARK => Notification::IndexMarks,
|
|
|
|
_ => panic!("Unknown notification received in IM callback: {}", state),
|
|
|
|
};
|
2020-09-25 15:36:00 +00:00
|
|
|
if let Some(c) = callbacks.lock().unwrap().get_mut(&client_id) {
|
2020-08-19 22:28:22 +00:00
|
|
|
let f = match state {
|
2020-09-25 15:36:00 +00:00
|
|
|
Notification::IndexMarks => &mut c.index_mark,
|
2020-08-19 22:28:22 +00:00
|
|
|
_ => panic!("Unknown notification type"),
|
|
|
|
};
|
2020-09-25 15:36:00 +00:00
|
|
|
if let Some(f) = f.as_mut() {
|
2020-08-20 01:59:48 +00:00
|
|
|
f(msg_id, client_id, index_mark);
|
2020-08-19 22:28:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-11-19 14:38:17 +00:00
|
|
|
#[derive(Debug)]
|
|
|
|
pub enum SpeechDispatcherError {
|
2021-12-06 18:57:04 +00:00
|
|
|
/// speech-dispatcher failed to initialize. Ensure speech-dispatcher is actually working on
|
|
|
|
/// your system; for example, does the command `spd-say hello` work?
|
2021-11-19 14:38:17 +00:00
|
|
|
InitializationError,
|
2021-12-06 18:57:04 +00:00
|
|
|
/// The operation failed
|
|
|
|
OperationFailed,
|
2021-11-19 14:38:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl std::error::Error for SpeechDispatcherError {}
|
|
|
|
|
|
|
|
impl fmt::Display for SpeechDispatcherError {
|
|
|
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
|
|
use SpeechDispatcherError::*;
|
|
|
|
match self {
|
|
|
|
InitializationError => write!(f, "Failed to initialize"),
|
2021-12-06 18:57:04 +00:00
|
|
|
OperationFailed => write!(f, "Operation failed"),
|
2021-11-19 14:38:17 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-12 17:28:39 +00:00
|
|
|
impl Connection {
|
2019-08-31 14:44:20 +00:00
|
|
|
pub fn open<S: Into<String>>(
|
|
|
|
client_name: S,
|
|
|
|
connection_name: S,
|
|
|
|
user_name: S,
|
|
|
|
mode: Mode,
|
2021-11-19 14:38:17 +00:00
|
|
|
) -> Result<Self, SpeechDispatcherError> {
|
2019-12-23 14:03:24 +00:00
|
|
|
let clientname = CString::new(client_name.into()).unwrap();
|
|
|
|
let connectionname = CString::new(connection_name.into()).unwrap();
|
|
|
|
let username = CString::new(user_name.into()).unwrap();
|
2018-01-12 17:28:39 +00:00
|
|
|
let connection = unsafe {
|
2020-08-19 22:28:22 +00:00
|
|
|
let c = spd_open(
|
2019-12-23 14:03:24 +00:00
|
|
|
clientname.as_ptr(),
|
|
|
|
connectionname.as_ptr(),
|
|
|
|
username.as_ptr(),
|
2019-08-31 14:44:20 +00:00
|
|
|
mode as u32,
|
2020-08-19 22:28:22 +00:00
|
|
|
);
|
2021-11-19 14:38:17 +00:00
|
|
|
if c.is_null() {
|
2021-12-06 18:57:04 +00:00
|
|
|
Err(SpeechDispatcherError::InitializationError)
|
2021-11-19 14:38:17 +00:00
|
|
|
} else {
|
2021-12-06 18:57:04 +00:00
|
|
|
Ok(Self::setup_connection(c))
|
2021-11-19 14:38:17 +00:00
|
|
|
}
|
2018-01-12 17:28:39 +00:00
|
|
|
};
|
2021-12-06 18:57:04 +00:00
|
|
|
let mut c = Self(connection?, 0);
|
|
|
|
c.setup()?;
|
|
|
|
Ok(c)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2019-12-23 14:03:24 +00:00
|
|
|
pub unsafe fn open2<S: Into<String>>(
|
2019-08-31 14:44:20 +00:00
|
|
|
client_name: S,
|
|
|
|
connection_name: S,
|
|
|
|
user_name: S,
|
|
|
|
mode: Mode,
|
|
|
|
address: *mut Address,
|
|
|
|
autospawn: bool,
|
2021-12-06 18:57:04 +00:00
|
|
|
) -> Result<Self, SpeechDispatcherError> {
|
2018-01-12 17:28:39 +00:00
|
|
|
let auto_spawn = if autospawn { 1 } else { 0 };
|
|
|
|
let error_result = vec![CString::new("").unwrap().into_raw()].as_mut_ptr();
|
2019-12-23 14:03:24 +00:00
|
|
|
let clientname = CString::new(client_name.into()).unwrap();
|
|
|
|
let connectionname = CString::new(connection_name.into()).unwrap();
|
|
|
|
let username = CString::new(user_name.into()).unwrap();
|
2020-08-19 22:28:22 +00:00
|
|
|
let connection = {
|
|
|
|
let c = spd_open2(
|
|
|
|
clientname.as_ptr(),
|
|
|
|
connectionname.as_ptr(),
|
|
|
|
username.as_ptr(),
|
|
|
|
mode as u32,
|
|
|
|
address,
|
|
|
|
auto_spawn,
|
|
|
|
error_result,
|
|
|
|
);
|
2021-12-06 18:57:04 +00:00
|
|
|
if c.is_null() {
|
|
|
|
Err(SpeechDispatcherError::InitializationError)
|
|
|
|
} else {
|
|
|
|
Ok(Self::setup_connection(c))
|
|
|
|
}
|
2020-08-19 22:28:22 +00:00
|
|
|
};
|
2021-12-06 18:57:04 +00:00
|
|
|
let mut c = Self(connection?, 0);
|
|
|
|
c.setup()?;
|
|
|
|
Ok(c)
|
2020-08-19 22:28:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
unsafe fn setup_connection(c: *mut SPDConnection) -> *mut SPDConnection {
|
|
|
|
(*c).callback_begin = Some(cb);
|
|
|
|
(*c).callback_end = Some(cb);
|
|
|
|
(*c).callback_cancel = Some(cb);
|
|
|
|
(*c).callback_pause = Some(cb);
|
|
|
|
(*c).callback_resume = Some(cb);
|
|
|
|
(*c).callback_im = Some(cb_im);
|
|
|
|
c
|
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
fn setup(&mut self) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let client_id = self.send_data("HISTORY GET CLIENT_ID\r\n", true);
|
|
|
|
if let Some(client_id) = client_id {
|
|
|
|
let client_id: Vec<&str> = client_id.split("\r\n").collect();
|
|
|
|
let client_id = client_id.get(0);
|
|
|
|
if let Some(client_id) = client_id {
|
|
|
|
let client_id: Vec<&str> = client_id.split("-").collect();
|
|
|
|
if let Some(client_id) = client_id.get(1) {
|
2020-09-26 17:51:39 +00:00
|
|
|
if let Ok(client_id) = client_id.parse::<u64>() {
|
2020-08-19 22:28:22 +00:00
|
|
|
self.1 = client_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
callbacks.lock().unwrap().insert(self.1, Default::default());
|
2021-12-06 18:57:04 +00:00
|
|
|
self.set_notification_on(Notification::All)
|
|
|
|
.map_err(|_| SpeechDispatcherError::InitializationError)?;
|
|
|
|
Ok(())
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn close(&self) {
|
2020-08-19 22:28:22 +00:00
|
|
|
unsafe { spd_close(self.0) };
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2020-09-25 15:36:00 +00:00
|
|
|
pub fn say<S: Into<String>>(&self, priority: Priority, text: S) -> Option<u64> {
|
2019-12-30 15:09:19 +00:00
|
|
|
let text: String = text.into();
|
|
|
|
let param = CString::new(text).unwrap();
|
2020-08-19 22:28:22 +00:00
|
|
|
let rv = unsafe { spd_say(self.0, priority as u32, param.as_ptr()) };
|
|
|
|
if rv != -1 {
|
2020-09-25 15:36:00 +00:00
|
|
|
Some(rv as u64)
|
2020-08-19 22:28:22 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2020-08-19 22:28:22 +00:00
|
|
|
pub fn sayf<S: Into<String>>(&self, priority: Priority, format: S) -> Option<i32> {
|
2019-12-30 15:09:19 +00:00
|
|
|
let format: String = format.into();
|
|
|
|
let param = CString::new(format).unwrap();
|
2020-08-19 22:28:22 +00:00
|
|
|
let rv = unsafe { spd_sayf(self.0, priority as u32, param.as_ptr()) };
|
|
|
|
if rv != -1 {
|
|
|
|
Some(rv)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn stop(&self) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_stop(self.0) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn stop_all(&self) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_stop_all(self.0) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn stop_uid(&self, target_uid: i32) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_stop_uid(self.0, target_uid) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn cancel(&self) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_cancel(self.0) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn cancel_all(&self) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_cancel_all(self.0) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn cancel_uid(&self, target_uid: i32) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_cancel_uid(self.0, target_uid) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn pause(&self) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_pause(self.0) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn pause_all(&self) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_pause_all(self.0) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn pause_uid(&self, target_uid: i32) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_pause_uid(self.0, target_uid) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn resume(&self) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_resume(self.0) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn resume_all(&self) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_resume_all(self.0) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn resume_uid(&self, target_uid: i32) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_resume_uid(self.0, target_uid) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn key<S: Into<String>>(
|
|
|
|
&self,
|
|
|
|
priority: Priority,
|
|
|
|
key_name: S,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2019-12-23 14:03:24 +00:00
|
|
|
let param = CString::new(key_name.into()).unwrap();
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_key(self.0, priority as u32, param.as_ptr()) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn char<S: Into<String>>(
|
|
|
|
&self,
|
|
|
|
priority: Priority,
|
|
|
|
char: S,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2019-12-23 14:03:24 +00:00
|
|
|
let param = CString::new(char.into()).unwrap();
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_char(self.0, priority as u32, param.as_ptr()) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn wchar(&self, priority: Priority, wchar: i32) -> Result<(), SpeechDispatcherError> {
|
2021-12-02 13:34:32 +00:00
|
|
|
let v = unsafe { spd_wchar(self.0, priority as u32, wchar as wchar_t) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn sound_icon<S: Into<String>>(
|
|
|
|
&self,
|
|
|
|
priority: Priority,
|
|
|
|
icon_name: S,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2019-12-23 14:03:24 +00:00
|
|
|
let param = CString::new(icon_name.into()).unwrap();
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_char(self.0, priority as u32, param.as_ptr()) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_voice_type(&self, voice_type: VoiceType) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_voice_type(self.0, voice_type as u32) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_voice_type_all(&self, voice_type: VoiceType) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_voice_type_all(self.0, voice_type as u32) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_voice_type_uid(
|
|
|
|
&self,
|
|
|
|
voice_type: VoiceType,
|
|
|
|
target_uid: u32,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_voice_type_uid(self.0, voice_type as u32, target_uid) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn get_voice_type(&self) -> Result<VoiceType, SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_get_voice_type(self.0) };
|
2021-12-06 18:57:04 +00:00
|
|
|
Ok(match v {
|
2018-01-12 17:28:39 +00:00
|
|
|
SPDVoiceType::SPD_MALE1 => VoiceType::Male1,
|
|
|
|
SPDVoiceType::SPD_MALE2 => VoiceType::Male2,
|
|
|
|
SPDVoiceType::SPD_MALE3 => VoiceType::Male3,
|
|
|
|
SPDVoiceType::SPD_FEMALE1 => VoiceType::Female1,
|
|
|
|
SPDVoiceType::SPD_FEMALE2 => VoiceType::Female2,
|
|
|
|
SPDVoiceType::SPD_FEMALE3 => VoiceType::Female3,
|
|
|
|
SPDVoiceType::SPD_CHILD_MALE => VoiceType::ChildMale,
|
|
|
|
SPDVoiceType::SPD_CHILD_FEMALE => VoiceType::ChildFemale,
|
2021-12-06 18:57:04 +00:00
|
|
|
_ => return Err(SpeechDispatcherError::OperationFailed), // can this happen?
|
|
|
|
})
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_synthesis_voice<S: Into<String>>(
|
|
|
|
&self,
|
|
|
|
voice_name: S,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2019-12-23 14:03:24 +00:00
|
|
|
let param = CString::new(voice_name.into()).unwrap();
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_synthesis_voice(self.0, param.as_ptr()) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_synthesis_voice_all<S: Into<String>>(
|
|
|
|
&self,
|
|
|
|
voice_name: S,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2019-12-23 14:03:24 +00:00
|
|
|
let param = CString::new(voice_name.into()).unwrap();
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_synthesis_voice_all(self.0, param.as_ptr()) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_synthesis_voice_uid<S: Into<String>>(
|
|
|
|
&self,
|
|
|
|
voice_name: S,
|
|
|
|
target_uid: u32,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2019-12-23 14:03:24 +00:00
|
|
|
let param = CString::new(voice_name.into()).unwrap();
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_synthesis_voice_uid(self.0, param.as_ptr(), target_uid) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_data_mode(&self, mode: DataMode) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_data_mode(self.0, mode as u32) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_notification_on(
|
|
|
|
&self,
|
|
|
|
notification: Notification,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_notification_on(self.0, notification as u32) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_notification_off(
|
|
|
|
&self,
|
|
|
|
notification: Notification,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_notification_off(self.0, notification as u32) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_notification<S: Into<String>>(
|
|
|
|
&self,
|
|
|
|
notification: Notification,
|
|
|
|
state: S,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2019-12-23 14:03:24 +00:00
|
|
|
let param = CString::new(state.into()).unwrap();
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_notification(self.0, notification as u32, param.as_ptr()) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_voice_rate(&self, rate: i32) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_voice_rate(self.0, rate) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_voice_rate_all(&self, rate: i32) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_voice_rate_all(self.0, rate) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_voice_rate_uid(
|
|
|
|
&self,
|
|
|
|
rate: i32,
|
|
|
|
target_uid: u32,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_voice_rate_uid(self.0, rate, target_uid) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_voice_rate(&self) -> i32 {
|
2020-08-19 22:28:22 +00:00
|
|
|
unsafe { spd_get_voice_rate(self.0) }
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_voice_pitch(&self, pitch: i32) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_voice_pitch(self.0, pitch) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_voice_pitch_all(&self, pitch: i32) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_voice_pitch_all(self.0, pitch) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_voice_pitch_uid(
|
|
|
|
&self,
|
|
|
|
pitch: i32,
|
|
|
|
target_uid: u32,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_voice_pitch_uid(self.0, pitch, target_uid) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_voice_pitch(&self) -> i32 {
|
2020-08-19 22:28:22 +00:00
|
|
|
unsafe { spd_get_voice_pitch(self.0) }
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_volume(&self, volume: i32) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_volume(self.0, volume) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_volume_all(&self, volume: i32) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_volume_all(self.0, volume) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_volume_uid(
|
|
|
|
&self,
|
|
|
|
volume: i32,
|
|
|
|
target_uid: u32,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_volume_uid(self.0, volume, target_uid) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn get_volume(&self) -> i32 {
|
2020-08-19 22:28:22 +00:00
|
|
|
unsafe { spd_get_volume(self.0) }
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_punctuation(&self, punctuation: Punctuation) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_punctuation(self.0, punctuation as u32) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_punctuation_all(
|
|
|
|
&self,
|
|
|
|
punctuation: Punctuation,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_punctuation_all(self.0, punctuation as u32) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_punctuation_uid(
|
|
|
|
&self,
|
|
|
|
punctuation: Punctuation,
|
|
|
|
target_uid: u32,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_punctuation_uid(self.0, punctuation as u32, target_uid) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_capital_letters(
|
|
|
|
&self,
|
|
|
|
capital_letters: CapitalLetters,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_capital_letters(self.0, capital_letters as u32) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_capital_letters_all(
|
|
|
|
&self,
|
|
|
|
capital_letters: CapitalLetters,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_capital_letters_all(self.0, capital_letters as u32) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2019-08-31 14:44:20 +00:00
|
|
|
pub fn set_capital_letters_uid(
|
|
|
|
&self,
|
|
|
|
capital_letters: CapitalLetters,
|
|
|
|
target_uid: u32,
|
2021-12-06 18:57:04 +00:00
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_capital_letters_uid(self.0, capital_letters as u32, target_uid) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_spelling(&self, spelling: bool) -> Result<(), SpeechDispatcherError> {
|
2019-08-31 14:44:20 +00:00
|
|
|
let s = if spelling {
|
|
|
|
SPDSpelling::SPD_SPELL_ON
|
|
|
|
} else {
|
|
|
|
SPDSpelling::SPD_SPELL_OFF
|
|
|
|
};
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_spelling(self.0, s) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_spelling_all(&self, spelling: bool) -> Result<(), SpeechDispatcherError> {
|
2019-08-31 14:44:20 +00:00
|
|
|
let s = if spelling {
|
|
|
|
SPDSpelling::SPD_SPELL_ON
|
|
|
|
} else {
|
|
|
|
SPDSpelling::SPD_SPELL_OFF
|
|
|
|
};
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_spelling_all(self.0, s) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_spelling_uid(
|
|
|
|
&self,
|
|
|
|
spelling: bool,
|
|
|
|
target_uid: u32,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2019-08-31 14:44:20 +00:00
|
|
|
let s = if spelling {
|
|
|
|
SPDSpelling::SPD_SPELL_ON
|
|
|
|
} else {
|
|
|
|
SPDSpelling::SPD_SPELL_OFF
|
|
|
|
};
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_spelling_uid(self.0, s, target_uid) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_language<S: Into<String>>(&self, language: S) -> Result<(), SpeechDispatcherError> {
|
2019-12-23 14:03:24 +00:00
|
|
|
let param = CString::new(language.into()).unwrap();
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_language(self.0, param.as_ptr()) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_language_all<S: Into<String>>(
|
|
|
|
&self,
|
|
|
|
language: S,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2019-12-23 14:03:24 +00:00
|
|
|
let param = CString::new(language.into()).unwrap();
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_language_all(self.0, param.as_ptr()) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_language_uid<S: Into<String>>(
|
|
|
|
&self,
|
|
|
|
language: S,
|
|
|
|
target_uid: u32,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2019-12-23 14:03:24 +00:00
|
|
|
let param = CString::new(language.into()).unwrap();
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_language_uid(self.0, param.as_ptr(), target_uid) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn get_language(&self) -> Result<&str, SpeechDispatcherError> {
|
|
|
|
let language = unsafe { spd_get_language(self.0) };
|
|
|
|
if language.is_null() {
|
|
|
|
Err(SpeechDispatcherError::OperationFailed)
|
|
|
|
} else {
|
|
|
|
let language = unsafe { CStr::from_ptr(language) };
|
|
|
|
language
|
|
|
|
.to_str()
|
|
|
|
.map_err(|_| SpeechDispatcherError::OperationFailed)
|
|
|
|
}
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_output_module<S: Into<String>>(
|
|
|
|
&self,
|
|
|
|
output_module: S,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2019-12-23 14:03:24 +00:00
|
|
|
let param = CString::new(output_module.into()).unwrap();
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_output_module(self.0, param.as_ptr()) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2021-12-06 18:57:04 +00:00
|
|
|
pub fn set_output_module_all<S: Into<String>>(
|
|
|
|
&self,
|
|
|
|
output_module: S,
|
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2019-12-23 14:03:24 +00:00
|
|
|
let param = CString::new(output_module.into()).unwrap();
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_output_module_all(self.0, param.as_ptr()) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2019-08-31 14:44:20 +00:00
|
|
|
pub fn set_output_module_uid<S: Into<String>>(
|
|
|
|
&self,
|
|
|
|
output_module: S,
|
|
|
|
target_uid: u32,
|
2021-12-06 18:57:04 +00:00
|
|
|
) -> Result<(), SpeechDispatcherError> {
|
2019-12-23 14:03:24 +00:00
|
|
|
let param = CString::new(output_module.into()).unwrap();
|
2020-08-19 22:28:22 +00:00
|
|
|
let v = unsafe { spd_set_output_module_uid(self.0, param.as_ptr(), target_uid) };
|
2021-12-06 18:57:04 +00:00
|
|
|
c_int_to_result(v)
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
2020-08-19 22:28:22 +00:00
|
|
|
|
|
|
|
pub fn send_data<S: Into<String>>(&self, data: S, wait_for_reply: bool) -> Option<String> {
|
|
|
|
let wfr: i32 = if wait_for_reply {
|
|
|
|
SPD_WAIT_REPLY as i32
|
|
|
|
} else {
|
|
|
|
SPD_NO_REPLY as i32
|
|
|
|
};
|
|
|
|
let data = CString::new(data.into()).unwrap();
|
|
|
|
let rv = unsafe { spd_send_data(self.0, data.as_ptr(), wfr) };
|
|
|
|
if rv.is_null() {
|
|
|
|
None
|
|
|
|
} else {
|
|
|
|
let rv = unsafe { CStr::from_ptr(rv) };
|
|
|
|
Some(rv.to_string_lossy().to_string())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-25 15:36:00 +00:00
|
|
|
pub fn on_begin(&self, f: Option<Box<dyn FnMut(u64, u64)>>) {
|
2020-08-19 22:28:22 +00:00
|
|
|
if let Ok(mut cbs) = callbacks.lock() {
|
|
|
|
let cb = cbs.get_mut(&self.1);
|
|
|
|
if let Some(cb) = cb {
|
|
|
|
cb.begin = f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-25 15:36:00 +00:00
|
|
|
pub fn on_end(&self, f: Option<Box<dyn FnMut(u64, u64)>>) {
|
2020-08-19 22:28:22 +00:00
|
|
|
if let Ok(mut cbs) = callbacks.lock() {
|
|
|
|
let cb = cbs.get_mut(&self.1);
|
|
|
|
if let Some(cb) = cb {
|
|
|
|
cb.end = f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-25 15:36:00 +00:00
|
|
|
pub fn on_cancel(&self, f: Option<Box<dyn FnMut(u64, u64)>>) {
|
2020-08-19 22:28:22 +00:00
|
|
|
if let Ok(mut cbs) = callbacks.lock() {
|
|
|
|
let cb = cbs.get_mut(&self.1);
|
|
|
|
if let Some(cb) = cb {
|
|
|
|
cb.cancel = f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-25 15:36:00 +00:00
|
|
|
pub fn on_pause(&self, f: Option<Box<dyn FnMut(u64, u64)>>) {
|
2020-08-19 22:28:22 +00:00
|
|
|
if let Ok(mut cbs) = callbacks.lock() {
|
|
|
|
let cb = cbs.get_mut(&self.1);
|
|
|
|
if let Some(cb) = cb {
|
|
|
|
cb.pause = f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-25 15:36:00 +00:00
|
|
|
pub fn on_resume(&self, f: Option<Box<dyn FnMut(u64, u64)>>) {
|
2020-08-19 22:28:22 +00:00
|
|
|
if let Ok(mut cbs) = callbacks.lock() {
|
|
|
|
let cb = cbs.get_mut(&self.1);
|
|
|
|
if let Some(cb) = cb {
|
|
|
|
cb.resume = f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-25 15:36:00 +00:00
|
|
|
pub fn on_index_mark(&self, f: Option<Box<dyn FnMut(u64, u64, String)>>) {
|
2020-08-19 22:28:22 +00:00
|
|
|
if let Ok(mut cbs) = callbacks.lock() {
|
|
|
|
let cb = cbs.get_mut(&self.1);
|
|
|
|
if let Some(cb) = cb {
|
|
|
|
cb.index_mark = f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-08-20 01:59:48 +00:00
|
|
|
|
|
|
|
pub fn client_id(&self) -> u64 {
|
|
|
|
self.1
|
|
|
|
}
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
|
2019-08-31 14:44:20 +00:00
|
|
|
unsafe impl Send for Connection {}
|
2019-08-31 14:44:01 +00:00
|
|
|
|
2018-01-12 17:28:39 +00:00
|
|
|
impl Drop for Connection {
|
|
|
|
fn drop(&mut self) {
|
|
|
|
self.close();
|
2020-08-19 22:28:22 +00:00
|
|
|
callbacks.lock().unwrap().remove(&self.1);
|
2018-01-12 17:28:39 +00:00
|
|
|
}
|
|
|
|
}
|