|
|
|
@ -1,12 +1,13 @@
|
|
|
|
|
#![allow(non_upper_case_globals)]
|
|
|
|
|
|
|
|
|
|
use libc::size_t;
|
|
|
|
|
use std::{
|
|
|
|
|
collections::HashMap,
|
|
|
|
|
ffi::{CStr, CString},
|
|
|
|
|
fmt,
|
|
|
|
|
marker::Send,
|
|
|
|
|
os::raw::{c_char, c_int},
|
|
|
|
|
sync::Mutex,
|
|
|
|
|
sync::{Arc, Mutex},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
use lazy_static::lazy_static;
|
|
|
|
@ -32,14 +33,14 @@ pub enum Priority {
|
|
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
|
|
|
#[repr(u32)]
|
|
|
|
|
pub enum VoiceType {
|
|
|
|
|
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,
|
|
|
|
|
Male1 = SPDVoiceType::SPD_MALE1 as u32,
|
|
|
|
|
Male2 = SPDVoiceType::SPD_MALE2 as u32,
|
|
|
|
|
Male3 = SPDVoiceType::SPD_MALE3 as u32,
|
|
|
|
|
Female1 = SPDVoiceType::SPD_FEMALE1 as u32,
|
|
|
|
|
Female2 = SPDVoiceType::SPD_FEMALE2 as u32,
|
|
|
|
|
Female3 = SPDVoiceType::SPD_FEMALE3 as u32,
|
|
|
|
|
ChildMale = SPDVoiceType::SPD_CHILD_MALE as u32,
|
|
|
|
|
ChildFemale = SPDVoiceType::SPD_CHILD_FEMALE as u32,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Hash, PartialEq)]
|
|
|
|
@ -73,9 +74,6 @@ impl Voice {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
|
pub struct Connection(pub *mut SPDConnection, u64);
|
|
|
|
|
|
|
|
|
|
pub type Address = SPDConnectionAddress;
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
|
|
@ -101,8 +99,10 @@ pub enum Notification {
|
|
|
|
|
#[repr(u32)]
|
|
|
|
|
pub enum Punctuation {
|
|
|
|
|
All = SPDPunctuation::SPD_PUNCT_ALL,
|
|
|
|
|
None = SPDPunctuation::SPD_PUNCT_NONE,
|
|
|
|
|
#[cfg(feature = "0_10")]
|
|
|
|
|
Most = SPDPunctuation::SPD_PUNCT_MOST,
|
|
|
|
|
Some = SPDPunctuation::SPD_PUNCT_SOME,
|
|
|
|
|
None = SPDPunctuation::SPD_PUNCT_NONE,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Copy, Debug)]
|
|
|
|
@ -123,12 +123,12 @@ fn c_int_to_result(r: c_int) -> Result<(), Error> {
|
|
|
|
|
|
|
|
|
|
#[derive(Default)]
|
|
|
|
|
struct Callbacks {
|
|
|
|
|
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)>>,
|
|
|
|
|
begin: Option<Box<dyn FnMut(size_t, size_t)>>,
|
|
|
|
|
end: Option<Box<dyn FnMut(size_t, size_t)>>,
|
|
|
|
|
index_mark: Option<Box<dyn FnMut(size_t, size_t, String)>>,
|
|
|
|
|
cancel: Option<Box<dyn FnMut(size_t, size_t)>>,
|
|
|
|
|
pause: Option<Box<dyn FnMut(size_t, size_t)>>,
|
|
|
|
|
resume: Option<Box<dyn FnMut(size_t, size_t)>>,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsafe impl Send for Callbacks {}
|
|
|
|
@ -136,13 +136,13 @@ unsafe impl Send for Callbacks {}
|
|
|
|
|
unsafe impl Sync for Callbacks {}
|
|
|
|
|
|
|
|
|
|
lazy_static! {
|
|
|
|
|
static ref callbacks: Mutex<HashMap<u64, Callbacks>> = {
|
|
|
|
|
static ref callbacks: Mutex<HashMap<size_t, Callbacks>> = {
|
|
|
|
|
let m = HashMap::new();
|
|
|
|
|
Mutex::new(m)
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsafe extern "C" fn cb(msg_id: u64, client_id: u64, state: u32) {
|
|
|
|
|
unsafe extern "C" fn cb(msg_id: size_t, client_id: size_t, state: u32) {
|
|
|
|
|
let state = match state {
|
|
|
|
|
SPDNotificationType_SPD_EVENT_BEGIN => Notification::Begin,
|
|
|
|
|
SPDNotificationType_SPD_EVENT_END => Notification::End,
|
|
|
|
@ -166,7 +166,7 @@ unsafe extern "C" fn cb(msg_id: u64, client_id: u64, state: u32) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unsafe extern "C" fn cb_im(msg_id: u64, client_id: u64, state: u32, index_mark: *mut c_char) {
|
|
|
|
|
unsafe extern "C" fn cb_im(msg_id: size_t, client_id: size_t, state: u32, index_mark: *mut c_char) {
|
|
|
|
|
let index_mark = CStr::from_ptr(index_mark);
|
|
|
|
|
let index_mark = index_mark.to_string_lossy().to_string();
|
|
|
|
|
let state = match state {
|
|
|
|
@ -205,6 +205,9 @@ impl fmt::Display for Error {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
|
pub struct Connection(pub Arc<*mut SPDConnection>, size_t);
|
|
|
|
|
|
|
|
|
|
impl Connection {
|
|
|
|
|
pub fn open<S: Into<String>>(
|
|
|
|
|
client_name: S,
|
|
|
|
@ -228,7 +231,7 @@ impl Connection {
|
|
|
|
|
Ok(Self::setup_connection(c))
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
let mut c = Self(connection?, 0);
|
|
|
|
|
let mut c = Self(Arc::new(connection?), 0);
|
|
|
|
|
c.setup()?;
|
|
|
|
|
Ok(c)
|
|
|
|
|
}
|
|
|
|
@ -262,7 +265,7 @@ impl Connection {
|
|
|
|
|
Ok(Self::setup_connection(c))
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
let mut c = Self(connection?, 0);
|
|
|
|
|
let mut c = Self(Arc::new(connection?), 0);
|
|
|
|
|
c.setup()?;
|
|
|
|
|
Ok(c)
|
|
|
|
|
}
|
|
|
|
@ -285,7 +288,7 @@ impl Connection {
|
|
|
|
|
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) {
|
|
|
|
|
if let Ok(client_id) = client_id.parse::<u64>() {
|
|
|
|
|
if let Ok(client_id) = client_id.parse::<size_t>() {
|
|
|
|
|
self.1 = client_id;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -298,13 +301,13 @@ impl Connection {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn close(&self) {
|
|
|
|
|
unsafe { spd_close(self.0) };
|
|
|
|
|
unsafe { spd_close(*self.0) };
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn say<S: Into<String>>(&self, priority: Priority, text: S) -> Option<u64> {
|
|
|
|
|
let text: String = text.into();
|
|
|
|
|
let param = CString::new(text).unwrap();
|
|
|
|
|
let rv = unsafe { spd_say(self.0, priority as u32, param.as_ptr()) };
|
|
|
|
|
let rv = unsafe { spd_say(*self.0, priority as u32, param.as_ptr()) };
|
|
|
|
|
if rv != -1 {
|
|
|
|
|
Some(rv as u64)
|
|
|
|
|
} else {
|
|
|
|
@ -315,7 +318,7 @@ impl Connection {
|
|
|
|
|
pub fn sayf<S: Into<String>>(&self, priority: Priority, format: S) -> Option<i32> {
|
|
|
|
|
let format: String = format.into();
|
|
|
|
|
let param = CString::new(format).unwrap();
|
|
|
|
|
let rv = unsafe { spd_sayf(self.0, priority as u32, param.as_ptr()) };
|
|
|
|
|
let rv = unsafe { spd_sayf(*self.0, priority as u32, param.as_ptr()) };
|
|
|
|
|
if rv != -1 {
|
|
|
|
|
Some(rv)
|
|
|
|
|
} else {
|
|
|
|
@ -324,79 +327,79 @@ impl Connection {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn stop(&self) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_stop(self.0) };
|
|
|
|
|
let v = unsafe { spd_stop(*self.0) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn stop_all(&self) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_stop_all(self.0) };
|
|
|
|
|
let v = unsafe { spd_stop_all(*self.0) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn stop_uid(&self, target_uid: i32) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_stop_uid(self.0, target_uid) };
|
|
|
|
|
let v = unsafe { spd_stop_uid(*self.0, target_uid) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn cancel(&self) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_cancel(self.0) };
|
|
|
|
|
let v = unsafe { spd_cancel(*self.0) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn cancel_all(&self) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_cancel_all(self.0) };
|
|
|
|
|
let v = unsafe { spd_cancel_all(*self.0) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn cancel_uid(&self, target_uid: i32) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_cancel_uid(self.0, target_uid) };
|
|
|
|
|
let v = unsafe { spd_cancel_uid(*self.0, target_uid) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn pause(&self) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_pause(self.0) };
|
|
|
|
|
let v = unsafe { spd_pause(*self.0) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn pause_all(&self) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_pause_all(self.0) };
|
|
|
|
|
let v = unsafe { spd_pause_all(*self.0) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn pause_uid(&self, target_uid: i32) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_pause_uid(self.0, target_uid) };
|
|
|
|
|
let v = unsafe { spd_pause_uid(*self.0, target_uid) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn resume(&self) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_resume(self.0) };
|
|
|
|
|
let v = unsafe { spd_resume(*self.0) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn resume_all(&self) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_resume_all(self.0) };
|
|
|
|
|
let v = unsafe { spd_resume_all(*self.0) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn resume_uid(&self, target_uid: i32) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_resume_uid(self.0, target_uid) };
|
|
|
|
|
let v = unsafe { spd_resume_uid(*self.0, target_uid) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn key<S: Into<String>>(&self, priority: Priority, key_name: S) -> Result<(), Error> {
|
|
|
|
|
let param = CString::new(key_name.into()).unwrap();
|
|
|
|
|
let v = unsafe { spd_key(self.0, priority as u32, param.as_ptr()) };
|
|
|
|
|
let v = unsafe { spd_key(*self.0, priority as u32, param.as_ptr()) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn char<S: Into<String>>(&self, priority: Priority, char: S) -> Result<(), Error> {
|
|
|
|
|
let param = CString::new(char.into()).unwrap();
|
|
|
|
|
let v = unsafe { spd_char(self.0, priority as u32, param.as_ptr()) };
|
|
|
|
|
let v = unsafe { spd_char(*self.0, priority as u32, param.as_ptr()) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn wchar(&self, priority: Priority, wchar: i32) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_wchar(self.0, priority as u32, wchar as wchar_t) };
|
|
|
|
|
let v = unsafe { spd_wchar(*self.0, priority as u32, wchar as wchar_t) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -406,27 +409,36 @@ impl Connection {
|
|
|
|
|
icon_name: S,
|
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
let param = CString::new(icon_name.into()).unwrap();
|
|
|
|
|
let v = unsafe { spd_char(self.0, priority as u32, param.as_ptr()) };
|
|
|
|
|
let v = unsafe { spd_char(*self.0, priority as u32, param.as_ptr()) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_voice_type(&self, voice_type: VoiceType) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_set_voice_type(self.0, voice_type as u32) };
|
|
|
|
|
#[cfg(all(any(feature = "0_9", feature = "0_10"), not(feature = "0_11")))]
|
|
|
|
|
let v = unsafe { spd_set_voice_type(*self.0, voice_type as u32) };
|
|
|
|
|
#[cfg(all(not(feature = "0_9"), any(feature = "0_11", not(feature = "0_10"))))]
|
|
|
|
|
let v = unsafe { spd_set_voice_type(*self.0, voice_type as i32) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_voice_type_all(&self, voice_type: VoiceType) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_set_voice_type_all(self.0, voice_type as u32) };
|
|
|
|
|
#[cfg(all(any(feature = "0_9", feature = "0_10"), not(feature = "0_11")))]
|
|
|
|
|
let v = unsafe { spd_set_voice_type_all(*self.0, voice_type as u32) };
|
|
|
|
|
#[cfg(all(not(feature = "0_9"), any(feature = "0_11", not(feature = "0_10"))))]
|
|
|
|
|
let v = unsafe { spd_set_voice_type_all(*self.0, voice_type as i32) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_voice_type_uid(&self, voice_type: VoiceType, target_uid: u32) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_set_voice_type_uid(self.0, voice_type as u32, target_uid) };
|
|
|
|
|
#[cfg(all(any(feature = "0_9", feature = "0_10"), not(feature = "0_11")))]
|
|
|
|
|
let v = unsafe { spd_set_voice_type_uid(*self.0, voice_type as u32, target_uid) };
|
|
|
|
|
#[cfg(all(not(feature = "0_9"), any(feature = "0_11", not(feature = "0_10"))))]
|
|
|
|
|
let v = unsafe { spd_set_voice_type_uid(*self.0, voice_type as i32, target_uid) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn get_voice_type(&self) -> Result<VoiceType, Error> {
|
|
|
|
|
let v = unsafe { spd_get_voice_type(self.0) };
|
|
|
|
|
let v = unsafe { spd_get_voice_type(*self.0) };
|
|
|
|
|
Ok(match v {
|
|
|
|
|
SPDVoiceType::SPD_MALE1 => VoiceType::Male1,
|
|
|
|
|
SPDVoiceType::SPD_MALE2 => VoiceType::Male2,
|
|
|
|
@ -442,13 +454,13 @@ impl Connection {
|
|
|
|
|
|
|
|
|
|
pub fn set_synthesis_voice(&self, voice: &Voice) -> Result<(), Error> {
|
|
|
|
|
let param = CString::new(voice.name.clone()).unwrap();
|
|
|
|
|
let v = unsafe { spd_set_synthesis_voice(self.0, param.as_ptr()) };
|
|
|
|
|
let v = unsafe { spd_set_synthesis_voice(*self.0, param.as_ptr()) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_synthesis_voice_all<S: Into<String>>(&self, voice_name: S) -> Result<(), Error> {
|
|
|
|
|
let param = CString::new(voice_name.into()).unwrap();
|
|
|
|
|
let v = unsafe { spd_set_synthesis_voice_all(self.0, param.as_ptr()) };
|
|
|
|
|
let v = unsafe { spd_set_synthesis_voice_all(*self.0, param.as_ptr()) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -458,22 +470,22 @@ impl Connection {
|
|
|
|
|
target_uid: u32,
|
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
let param = CString::new(voice_name.into()).unwrap();
|
|
|
|
|
let v = unsafe { spd_set_synthesis_voice_uid(self.0, param.as_ptr(), target_uid) };
|
|
|
|
|
let v = unsafe { spd_set_synthesis_voice_uid(*self.0, param.as_ptr(), target_uid) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_data_mode(&self, mode: DataMode) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_set_data_mode(self.0, mode as u32) };
|
|
|
|
|
let v = unsafe { spd_set_data_mode(*self.0, mode as u32) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_notification_on(&self, notification: Notification) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_set_notification_on(self.0, notification as u32) };
|
|
|
|
|
let v = unsafe { spd_set_notification_on(*self.0, notification as u32) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_notification_off(&self, notification: Notification) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_set_notification_off(self.0, notification as u32) };
|
|
|
|
|
let v = unsafe { spd_set_notification_off(*self.0, notification as u32) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -483,74 +495,74 @@ impl Connection {
|
|
|
|
|
state: S,
|
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
let param = CString::new(state.into()).unwrap();
|
|
|
|
|
let v = unsafe { spd_set_notification(self.0, notification as u32, param.as_ptr()) };
|
|
|
|
|
let v = unsafe { spd_set_notification(*self.0, notification as u32, param.as_ptr()) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_voice_rate(&self, rate: i32) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_set_voice_rate(self.0, rate) };
|
|
|
|
|
let v = unsafe { spd_set_voice_rate(*self.0, rate) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_voice_rate_all(&self, rate: i32) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_set_voice_rate_all(self.0, rate) };
|
|
|
|
|
let v = unsafe { spd_set_voice_rate_all(*self.0, rate) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_voice_rate_uid(&self, rate: i32, target_uid: u32) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_set_voice_rate_uid(self.0, rate, target_uid) };
|
|
|
|
|
let v = unsafe { spd_set_voice_rate_uid(*self.0, rate, target_uid) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn get_voice_rate(&self) -> i32 {
|
|
|
|
|
unsafe { spd_get_voice_rate(self.0) }
|
|
|
|
|
unsafe { spd_get_voice_rate(*self.0) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_voice_pitch(&self, pitch: i32) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_set_voice_pitch(self.0, pitch) };
|
|
|
|
|
let v = unsafe { spd_set_voice_pitch(*self.0, pitch) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_voice_pitch_all(&self, pitch: i32) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_set_voice_pitch_all(self.0, pitch) };
|
|
|
|
|
let v = unsafe { spd_set_voice_pitch_all(*self.0, pitch) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_voice_pitch_uid(&self, pitch: i32, target_uid: u32) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_set_voice_pitch_uid(self.0, pitch, target_uid) };
|
|
|
|
|
let v = unsafe { spd_set_voice_pitch_uid(*self.0, pitch, target_uid) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn get_voice_pitch(&self) -> i32 {
|
|
|
|
|
unsafe { spd_get_voice_pitch(self.0) }
|
|
|
|
|
unsafe { spd_get_voice_pitch(*self.0) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_volume(&self, volume: i32) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_set_volume(self.0, volume) };
|
|
|
|
|
let v = unsafe { spd_set_volume(*self.0, volume) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_volume_all(&self, volume: i32) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_set_volume_all(self.0, volume) };
|
|
|
|
|
let v = unsafe { spd_set_volume_all(*self.0, volume) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_volume_uid(&self, volume: i32, target_uid: u32) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_set_volume_uid(self.0, volume, target_uid) };
|
|
|
|
|
let v = unsafe { spd_set_volume_uid(*self.0, volume, target_uid) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn get_volume(&self) -> i32 {
|
|
|
|
|
unsafe { spd_get_volume(self.0) }
|
|
|
|
|
unsafe { spd_get_volume(*self.0) }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_punctuation(&self, punctuation: Punctuation) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_set_punctuation(self.0, punctuation as u32) };
|
|
|
|
|
let v = unsafe { spd_set_punctuation(*self.0, punctuation as u32) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_punctuation_all(&self, punctuation: Punctuation) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_set_punctuation_all(self.0, punctuation as u32) };
|
|
|
|
|
let v = unsafe { spd_set_punctuation_all(*self.0, punctuation as u32) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -559,17 +571,17 @@ impl Connection {
|
|
|
|
|
punctuation: Punctuation,
|
|
|
|
|
target_uid: u32,
|
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_set_punctuation_uid(self.0, punctuation as u32, target_uid) };
|
|
|
|
|
let v = unsafe { spd_set_punctuation_uid(*self.0, punctuation as u32, target_uid) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_capital_letters(&self, capital_letters: CapitalLetters) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_set_capital_letters(self.0, capital_letters as u32) };
|
|
|
|
|
let v = unsafe { spd_set_capital_letters(*self.0, capital_letters as u32) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_capital_letters_all(&self, capital_letters: CapitalLetters) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_set_capital_letters_all(self.0, capital_letters as u32) };
|
|
|
|
|
let v = unsafe { spd_set_capital_letters_all(*self.0, capital_letters as u32) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -578,7 +590,7 @@ impl Connection {
|
|
|
|
|
capital_letters: CapitalLetters,
|
|
|
|
|
target_uid: u32,
|
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
let v = unsafe { spd_set_capital_letters_uid(self.0, capital_letters as u32, target_uid) };
|
|
|
|
|
let v = unsafe { spd_set_capital_letters_uid(*self.0, capital_letters as u32, target_uid) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -588,7 +600,7 @@ impl Connection {
|
|
|
|
|
} else {
|
|
|
|
|
SPDSpelling::SPD_SPELL_OFF
|
|
|
|
|
};
|
|
|
|
|
let v = unsafe { spd_set_spelling(self.0, s) };
|
|
|
|
|
let v = unsafe { spd_set_spelling(*self.0, s) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -598,7 +610,7 @@ impl Connection {
|
|
|
|
|
} else {
|
|
|
|
|
SPDSpelling::SPD_SPELL_OFF
|
|
|
|
|
};
|
|
|
|
|
let v = unsafe { spd_set_spelling_all(self.0, s) };
|
|
|
|
|
let v = unsafe { spd_set_spelling_all(*self.0, s) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -608,19 +620,19 @@ impl Connection {
|
|
|
|
|
} else {
|
|
|
|
|
SPDSpelling::SPD_SPELL_OFF
|
|
|
|
|
};
|
|
|
|
|
let v = unsafe { spd_set_spelling_uid(self.0, s, target_uid) };
|
|
|
|
|
let v = unsafe { spd_set_spelling_uid(*self.0, s, target_uid) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_language<S: Into<String>>(&self, language: S) -> Result<(), Error> {
|
|
|
|
|
let param = CString::new(language.into()).unwrap();
|
|
|
|
|
let v = unsafe { spd_set_language(self.0, param.as_ptr()) };
|
|
|
|
|
let v = unsafe { spd_set_language(*self.0, param.as_ptr()) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_language_all<S: Into<String>>(&self, language: S) -> Result<(), Error> {
|
|
|
|
|
let param = CString::new(language.into()).unwrap();
|
|
|
|
|
let v = unsafe { spd_set_language_all(self.0, param.as_ptr()) };
|
|
|
|
|
let v = unsafe { spd_set_language_all(*self.0, param.as_ptr()) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -630,12 +642,12 @@ impl Connection {
|
|
|
|
|
target_uid: u32,
|
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
let param = CString::new(language.into()).unwrap();
|
|
|
|
|
let v = unsafe { spd_set_language_uid(self.0, param.as_ptr(), target_uid) };
|
|
|
|
|
let v = unsafe { spd_set_language_uid(*self.0, param.as_ptr(), target_uid) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn get_language(&self) -> Result<&str, Error> {
|
|
|
|
|
let language = unsafe { spd_get_language(self.0) };
|
|
|
|
|
let language = unsafe { spd_get_language(*self.0) };
|
|
|
|
|
if language.is_null() {
|
|
|
|
|
Err(Error::OperationFailed)
|
|
|
|
|
} else {
|
|
|
|
@ -646,13 +658,13 @@ impl Connection {
|
|
|
|
|
|
|
|
|
|
pub fn set_output_module<S: Into<String>>(&self, output_module: S) -> Result<(), Error> {
|
|
|
|
|
let param = CString::new(output_module.into()).unwrap();
|
|
|
|
|
let v = unsafe { spd_set_output_module(self.0, param.as_ptr()) };
|
|
|
|
|
let v = unsafe { spd_set_output_module(*self.0, param.as_ptr()) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn set_output_module_all<S: Into<String>>(&self, output_module: S) -> Result<(), Error> {
|
|
|
|
|
let param = CString::new(output_module.into()).unwrap();
|
|
|
|
|
let v = unsafe { spd_set_output_module_all(self.0, param.as_ptr()) };
|
|
|
|
|
let v = unsafe { spd_set_output_module_all(*self.0, param.as_ptr()) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -662,7 +674,7 @@ impl Connection {
|
|
|
|
|
target_uid: u32,
|
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
let param = CString::new(output_module.into()).unwrap();
|
|
|
|
|
let v = unsafe { spd_set_output_module_uid(self.0, param.as_ptr(), target_uid) };
|
|
|
|
|
let v = unsafe { spd_set_output_module_uid(*self.0, param.as_ptr(), target_uid) };
|
|
|
|
|
c_int_to_result(v)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -673,7 +685,7 @@ impl Connection {
|
|
|
|
|
SPD_NO_REPLY as i32
|
|
|
|
|
};
|
|
|
|
|
let data = CString::new(data.into()).unwrap();
|
|
|
|
|
let rv = unsafe { spd_send_data(self.0, data.as_ptr(), wfr) };
|
|
|
|
|
let rv = unsafe { spd_send_data(*self.0, data.as_ptr(), wfr) };
|
|
|
|
|
if rv.is_null() {
|
|
|
|
|
None
|
|
|
|
|
} else {
|
|
|
|
@ -682,7 +694,7 @@ impl Connection {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn on_begin(&self, f: Option<Box<dyn FnMut(u64, u64)>>) {
|
|
|
|
|
pub fn on_begin(&self, f: Option<Box<dyn FnMut(size_t, size_t)>>) {
|
|
|
|
|
if let Ok(mut cbs) = callbacks.lock() {
|
|
|
|
|
let cb = cbs.get_mut(&self.1);
|
|
|
|
|
if let Some(cb) = cb {
|
|
|
|
@ -691,7 +703,7 @@ impl Connection {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn on_end(&self, f: Option<Box<dyn FnMut(u64, u64)>>) {
|
|
|
|
|
pub fn on_end(&self, f: Option<Box<dyn FnMut(size_t, size_t)>>) {
|
|
|
|
|
if let Ok(mut cbs) = callbacks.lock() {
|
|
|
|
|
let cb = cbs.get_mut(&self.1);
|
|
|
|
|
if let Some(cb) = cb {
|
|
|
|
@ -700,7 +712,7 @@ impl Connection {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn on_cancel(&self, f: Option<Box<dyn FnMut(u64, u64)>>) {
|
|
|
|
|
pub fn on_cancel(&self, f: Option<Box<dyn FnMut(size_t, size_t)>>) {
|
|
|
|
|
if let Ok(mut cbs) = callbacks.lock() {
|
|
|
|
|
let cb = cbs.get_mut(&self.1);
|
|
|
|
|
if let Some(cb) = cb {
|
|
|
|
@ -709,7 +721,7 @@ impl Connection {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn on_pause(&self, f: Option<Box<dyn FnMut(u64, u64)>>) {
|
|
|
|
|
pub fn on_pause(&self, f: Option<Box<dyn FnMut(size_t, size_t)>>) {
|
|
|
|
|
if let Ok(mut cbs) = callbacks.lock() {
|
|
|
|
|
let cb = cbs.get_mut(&self.1);
|
|
|
|
|
if let Some(cb) = cb {
|
|
|
|
@ -718,7 +730,7 @@ impl Connection {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn on_resume(&self, f: Option<Box<dyn FnMut(u64, u64)>>) {
|
|
|
|
|
pub fn on_resume(&self, f: Option<Box<dyn FnMut(size_t, size_t)>>) {
|
|
|
|
|
if let Ok(mut cbs) = callbacks.lock() {
|
|
|
|
|
let cb = cbs.get_mut(&self.1);
|
|
|
|
|
if let Some(cb) = cb {
|
|
|
|
@ -727,7 +739,7 @@ impl Connection {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn on_index_mark(&self, f: Option<Box<dyn FnMut(u64, u64, String)>>) {
|
|
|
|
|
pub fn on_index_mark(&self, f: Option<Box<dyn FnMut(size_t, size_t, String)>>) {
|
|
|
|
|
if let Ok(mut cbs) = callbacks.lock() {
|
|
|
|
|
let cb = cbs.get_mut(&self.1);
|
|
|
|
|
if let Some(cb) = cb {
|
|
|
|
@ -737,7 +749,7 @@ impl Connection {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn list_synthesis_voices(&self) -> Result<Vec<Voice>, Error> {
|
|
|
|
|
let start = unsafe { spd_list_synthesis_voices(self.0) };
|
|
|
|
|
let start = unsafe { spd_list_synthesis_voices(*self.0) };
|
|
|
|
|
let slice = unsafe { null_term_array_ptr_to_slice(start) }.ok_or(Error::OperationFailed)?;
|
|
|
|
|
let voices = unsafe {
|
|
|
|
|
slice
|
|
|
|
@ -759,7 +771,7 @@ impl Connection {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn list_output_modules(&self) -> Result<Vec<String>, Error> {
|
|
|
|
|
let start = unsafe { spd_list_modules(self.0) };
|
|
|
|
|
let start = unsafe { spd_list_modules(*self.0) };
|
|
|
|
|
let slice = unsafe { null_term_array_ptr_to_slice(start) }.ok_or(Error::OperationFailed)?;
|
|
|
|
|
let modules = unsafe {
|
|
|
|
|
slice
|
|
|
|
@ -773,7 +785,7 @@ impl Connection {
|
|
|
|
|
Ok(modules)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pub fn client_id(&self) -> u64 {
|
|
|
|
|
pub fn client_id(&self) -> size_t {
|
|
|
|
|
self.1
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -799,7 +811,9 @@ unsafe impl Send for Connection {}
|
|
|
|
|
|
|
|
|
|
impl Drop for Connection {
|
|
|
|
|
fn drop(&mut self) {
|
|
|
|
|
self.close();
|
|
|
|
|
callbacks.lock().unwrap().remove(&self.1);
|
|
|
|
|
if Arc::strong_count(&self.0) <= 1 {
|
|
|
|
|
self.close();
|
|
|
|
|
callbacks.lock().unwrap().remove(&self.1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|