Compare commits
No commits in common. "master" and "v0.8.0+v0.5.2" have entirely different histories.
master
...
v0.8.0+v0.
27
.drone.yml
27
.drone.yml
|
@ -1,27 +0,0 @@
|
||||||
kind: pipeline
|
|
||||||
type: docker
|
|
||||||
name: default
|
|
||||||
|
|
||||||
steps:
|
|
||||||
- name: test
|
|
||||||
image: rust
|
|
||||||
commands:
|
|
||||||
- rustup component add clippy rustfmt
|
|
||||||
- apt-get update -qq
|
|
||||||
- apt-get install -qqy llvm-dev libclang-dev clang libspeechd-dev
|
|
||||||
- cargo fmt --all --check
|
|
||||||
- cargo test --no-default-features --features 0_10
|
|
||||||
- cargo clippy --no-default-features --features 0_10
|
|
||||||
- name: release
|
|
||||||
image: rust
|
|
||||||
commands:
|
|
||||||
- apt-get update -qq
|
|
||||||
- apt-get install -qqy llvm-dev libclang-dev clang libspeechd-dev
|
|
||||||
- cargo publish --no-default-features --features 0_10 --manifest-path speech-dispatcher-sys/Cargo.toml || true
|
|
||||||
- cargo publish --no-default-features --features 0_10 --manifest-path speech-dispatcher/Cargo.toml
|
|
||||||
when:
|
|
||||||
ref:
|
|
||||||
- refs/tags/v*
|
|
||||||
environment:
|
|
||||||
CARGO_REGISTRY_TOKEN:
|
|
||||||
from_secret: cargo_registry_token
|
|
25
.gitlab-ci.yml
Normal file
25
.gitlab-ci.yml
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
image: rust
|
||||||
|
|
||||||
|
stages:
|
||||||
|
- test
|
||||||
|
- publish
|
||||||
|
|
||||||
|
before_script:
|
||||||
|
- apt-get update
|
||||||
|
- apt-get install -y libspeechd-dev llvm-dev libclang-dev clang
|
||||||
|
|
||||||
|
test:
|
||||||
|
stage: test
|
||||||
|
script:
|
||||||
|
- cargo test
|
||||||
|
|
||||||
|
publish:
|
||||||
|
stage: publish
|
||||||
|
script:
|
||||||
|
- cargo login $CARGO_TOKEN
|
||||||
|
- cargo package --manifest-path speech-dispatcher-sys/Cargo.toml
|
||||||
|
- cargo publish --manifest-path speech-dispatcher-sys/Cargo.toml || true
|
||||||
|
- cargo package --manifest-path speech-dispatcher/Cargo.toml
|
||||||
|
- cargo publish --manifest-path speech-dispatcher/Cargo.toml
|
||||||
|
only:
|
||||||
|
- tags
|
60
cliff.toml
60
cliff.toml
|
@ -1,60 +0,0 @@
|
||||||
# configuration file for git-cliff (0.1.0)
|
|
||||||
|
|
||||||
[changelog]
|
|
||||||
# changelog header
|
|
||||||
header = """
|
|
||||||
# Changelog\n
|
|
||||||
All notable changes to this project will be documented in this file.\n
|
|
||||||
"""
|
|
||||||
# template for the changelog body
|
|
||||||
# https://tera.netlify.app/docs/#introduction
|
|
||||||
body = """
|
|
||||||
{% if version %}\
|
|
||||||
## Version {{ version | trim_start_matches(pat="v") }} - {{ timestamp | date(format="%Y-%m-%d") }}
|
|
||||||
{% else %}\
|
|
||||||
## Unreleased
|
|
||||||
{% endif %}\
|
|
||||||
{% for group, commits in commits | group_by(attribute="group") %}
|
|
||||||
### {{ group | upper_first }}
|
|
||||||
{% for commit in commits %}
|
|
||||||
- {% if commit.breaking %}[**breaking**] {% endif %}{{ commit.message | upper_first }}\
|
|
||||||
{% endfor %}
|
|
||||||
{% endfor %}\n
|
|
||||||
"""
|
|
||||||
# remove the leading and trailing whitespace from the template
|
|
||||||
trim = true
|
|
||||||
# changelog footer
|
|
||||||
footer = """
|
|
||||||
<!-- generated by git-cliff -->
|
|
||||||
"""
|
|
||||||
|
|
||||||
[git]
|
|
||||||
# parse the commits based on https://www.conventionalcommits.org
|
|
||||||
conventional_commits = true
|
|
||||||
# filter out the commits that are not conventional
|
|
||||||
filter_unconventional = true
|
|
||||||
# regex for parsing and grouping commits
|
|
||||||
commit_parsers = [
|
|
||||||
{ message = "^feat", group = "Features"},
|
|
||||||
{ message = "^fix", group = "Bug Fixes"},
|
|
||||||
{ message = "^doc", group = "Documentation"},
|
|
||||||
{ message = "^perf", group = "Performance"},
|
|
||||||
{ message = "^refactor", group = "Refactor"},
|
|
||||||
{ message = "^style", group = "Styling"},
|
|
||||||
{ message = "^test", group = "Testing"},
|
|
||||||
{ message = "^chore\\(release\\): prepare for", skip = true},
|
|
||||||
{ message = "^chore", group = "Miscellaneous Tasks"},
|
|
||||||
{ body = ".*security", group = "Security"},
|
|
||||||
]
|
|
||||||
# filter out the commits that are not matched by commit parsers
|
|
||||||
filter_commits = false
|
|
||||||
# glob pattern for matching git tags
|
|
||||||
tag_pattern = "v[0-9]*"
|
|
||||||
# regex for skipping tags
|
|
||||||
skip_tags = ""
|
|
||||||
# regex for ignoring tags
|
|
||||||
ignore_tags = ""
|
|
||||||
# sort the tags chronologically
|
|
||||||
date_order = false
|
|
||||||
# sort the commits inside sections by oldest/newest order
|
|
||||||
sort_commits = "oldest"
|
|
|
@ -1,17 +1,13 @@
|
||||||
[package]
|
[package]
|
||||||
name = "speech-dispatcher-sys"
|
name = "speech-dispatcher-sys"
|
||||||
version = "0.7.0"
|
version = "0.5.2"
|
||||||
authors = ["Nolan Darilek <nolan@thewordnerd.info>"]
|
authors = ["Nolan Darilek <nolan@thewordnerd.info>"]
|
||||||
repository = "https://dev.thewordnerd.info/nolan/speech-dispatcher-rs"
|
repository = "https://gitlab.com/ndarilek/speech-dispatcher-rs"
|
||||||
description = "speech-dispatcher system bindings"
|
description = "speech-dispatcher system bindings"
|
||||||
license = "LGPL-2.1 OR MIT OR Apache-2.0"
|
license = "LGPL-2.1"
|
||||||
edition = "2021"
|
edition = "2018"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
bindgen = ">= 0.54"
|
|
||||||
|
|
||||||
[package.metadata.release]
|
bindgen = ">= 0.54"
|
||||||
tag-prefix = ""
|
gcc = "0.3"
|
||||||
publish = false
|
|
||||||
push = false
|
|
||||||
pre-release-hook = ["git-cliff", "-o", "CHANGELOG.md", "--tag", "{{version}}"]
|
|
||||||
|
|
|
@ -1,29 +1,12 @@
|
||||||
[package]
|
[package]
|
||||||
name = "speech-dispatcher"
|
name = "speech-dispatcher"
|
||||||
version = "0.16.0"
|
version = "0.8.0"
|
||||||
authors = ["Nolan Darilek <nolan@thewordnerd.info>"]
|
authors = ["Nolan Darilek <nolan@thewordnerd.info>"]
|
||||||
repository = "https://dev.thewordnerd.info/nolan/speech-dispatcher-rs"
|
repository = "https://gitlab.com/ndarilek/speech-dispatcher-rs"
|
||||||
description = "Rusty interface to the speech-dispatcher speech synthesis library"
|
description = "Rusty interface to the speech-dispatcher speech synthesis library"
|
||||||
license = "LGPL-2.1 OR MIT OR Apache-2.0"
|
license = "LGPL-2.1"
|
||||||
edition = "2021"
|
edition = "2018"
|
||||||
|
|
||||||
[features]
|
|
||||||
0_11 = ["0_10"]
|
|
||||||
0_10 = []
|
|
||||||
0_9 = []
|
|
||||||
default = ["0_11"]
|
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
lazy_static = "1"
|
lazy_static = "1"
|
||||||
speech-dispatcher-sys = { version = "0.7", path = "../speech-dispatcher-sys" }
|
speech-dispatcher-sys = { version = "0.5", path = "../speech-dispatcher-sys" }
|
||||||
libc = "0.2.125"
|
|
||||||
|
|
||||||
[package.metadata.docs.rs]
|
|
||||||
no-default-features = true
|
|
||||||
features = ["0_9"]
|
|
||||||
|
|
||||||
[package.metadata.release]
|
|
||||||
tag-prefix = ""
|
|
||||||
publish = false
|
|
||||||
push = false
|
|
||||||
pre-release-hook = ["git-cliff", "-o", "CHANGELOG.md", "--tag", "{{version}}"]
|
|
||||||
|
|
|
@ -1,42 +0,0 @@
|
||||||
use speech_dispatcher::*;
|
|
||||||
use std::io;
|
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
let connection = speech_dispatcher::Connection::open(
|
|
||||||
"hello_world",
|
|
||||||
"hello_world",
|
|
||||||
"hello_world",
|
|
||||||
Mode::Threaded,
|
|
||||||
)?;
|
|
||||||
connection.on_begin(Some(Box::new(|msg_id, client_id| {
|
|
||||||
println!("Beginning {} from {}", msg_id, client_id)
|
|
||||||
})));
|
|
||||||
connection.on_end(Some(Box::new(|msg_id, client_id| {
|
|
||||||
println!("Ending {} from {}", msg_id, client_id)
|
|
||||||
})));
|
|
||||||
let connection_clone = connection.clone();
|
|
||||||
drop(connection);
|
|
||||||
connection_clone.say(
|
|
||||||
Priority::Important,
|
|
||||||
format!(
|
|
||||||
"Hello, world at rate {} from client {}.",
|
|
||||||
connection_clone.get_voice_rate(),
|
|
||||||
connection_clone.client_id()
|
|
||||||
),
|
|
||||||
);
|
|
||||||
connection_clone.set_voice_rate(100)?;
|
|
||||||
connection_clone.say(Priority::Important, "This is faster.");
|
|
||||||
connection_clone.set_voice_rate(0)?;
|
|
||||||
connection_clone.set_spelling(true)?;
|
|
||||||
connection_clone.say(Priority::Important, "This is spelled.");
|
|
||||||
connection_clone.set_spelling(false)?;
|
|
||||||
connection_clone.set_punctuation(Punctuation::All)?;
|
|
||||||
connection_clone.say(
|
|
||||||
Priority::Important,
|
|
||||||
"This statement, unlike others, has punctuation that is spoken!",
|
|
||||||
);
|
|
||||||
connection_clone.set_punctuation(Punctuation::None)?;
|
|
||||||
let mut _input = String::new();
|
|
||||||
io::stdin().read_line(&mut _input).unwrap();
|
|
||||||
Ok(())
|
|
||||||
}
|
|
|
@ -22,18 +22,18 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||||
connection.client_id()
|
connection.client_id()
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
connection.set_voice_rate(100)?;
|
connection.set_voice_rate(100);
|
||||||
connection.say(Priority::Important, "This is faster.");
|
connection.say(Priority::Important, "This is faster.");
|
||||||
connection.set_voice_rate(0)?;
|
connection.set_voice_rate(0);
|
||||||
connection.set_spelling(true)?;
|
connection.set_spelling(true);
|
||||||
connection.say(Priority::Important, "This is spelled.");
|
connection.say(Priority::Important, "This is spelled.");
|
||||||
connection.set_spelling(false)?;
|
connection.set_spelling(false);
|
||||||
connection.set_punctuation(Punctuation::All)?;
|
connection.set_punctuation(Punctuation::All);
|
||||||
connection.say(
|
connection.say(
|
||||||
Priority::Important,
|
Priority::Important,
|
||||||
"This statement, unlike others, has punctuation that is spoken!",
|
"This statement, unlike others, has punctuation that is spoken!",
|
||||||
);
|
);
|
||||||
connection.set_punctuation(Punctuation::None)?;
|
connection.set_punctuation(Punctuation::None);
|
||||||
let mut _input = String::new();
|
let mut _input = String::new();
|
||||||
io::stdin().read_line(&mut _input).unwrap();
|
io::stdin().read_line(&mut _input).unwrap();
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -1,29 +0,0 @@
|
||||||
use speech_dispatcher::*;
|
|
||||||
|
|
||||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
||||||
let connection = Connection::open("list_voices", "list_voices", "list_voices", Mode::Threaded)?;
|
|
||||||
|
|
||||||
let modules = connection.list_output_modules()?;
|
|
||||||
println!("Modules available: {:?}", modules);
|
|
||||||
for module in modules {
|
|
||||||
if connection.set_output_module(&module).is_ok() {
|
|
||||||
println!("Listing voices for module {module}");
|
|
||||||
} else {
|
|
||||||
println!("Failed to set output module to {module}");
|
|
||||||
continue;
|
|
||||||
};
|
|
||||||
let voices = connection.list_synthesis_voices()?;
|
|
||||||
for voice in voices {
|
|
||||||
if let Some(variant) = voice.variant {
|
|
||||||
println!(
|
|
||||||
" Name: {} / Language: {} / Variant: {variant}",
|
|
||||||
voice.name, voice.language
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
println!(" Name: {} / Language: {}", voice.name, voice.language);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Use connection.set_synthesis_voice(voice) to set the voice to use.
|
|
||||||
Ok(())
|
|
||||||
}
|
|
|
@ -1,13 +1,11 @@
|
||||||
#![allow(non_upper_case_globals)]
|
#![allow(non_upper_case_globals)]
|
||||||
|
|
||||||
use libc::size_t;
|
|
||||||
use std::{
|
use std::{
|
||||||
collections::HashMap,
|
collections::HashMap,
|
||||||
ffi::{CStr, CString},
|
ffi::{CStr, CString},
|
||||||
fmt,
|
fmt,
|
||||||
marker::Send,
|
marker::Send,
|
||||||
os::raw::{c_char, c_int},
|
sync::Mutex,
|
||||||
sync::{Arc, Mutex},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
|
@ -33,46 +31,18 @@ pub enum Priority {
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
pub enum VoiceType {
|
pub enum VoiceType {
|
||||||
Male1 = SPDVoiceType::SPD_MALE1 as u32,
|
Male1 = SPDVoiceType::SPD_MALE1,
|
||||||
Male2 = SPDVoiceType::SPD_MALE2 as u32,
|
Male2 = SPDVoiceType::SPD_MALE2,
|
||||||
Male3 = SPDVoiceType::SPD_MALE3 as u32,
|
Male3 = SPDVoiceType::SPD_MALE3,
|
||||||
Female1 = SPDVoiceType::SPD_FEMALE1 as u32,
|
Female1 = SPDVoiceType::SPD_FEMALE1,
|
||||||
Female2 = SPDVoiceType::SPD_FEMALE2 as u32,
|
Female2 = SPDVoiceType::SPD_FEMALE2,
|
||||||
Female3 = SPDVoiceType::SPD_FEMALE3 as u32,
|
Female3 = SPDVoiceType::SPD_FEMALE3,
|
||||||
ChildMale = SPDVoiceType::SPD_CHILD_MALE as u32,
|
ChildMale = SPDVoiceType::SPD_CHILD_MALE,
|
||||||
ChildFemale = SPDVoiceType::SPD_CHILD_FEMALE as u32,
|
ChildFemale = SPDVoiceType::SPD_CHILD_FEMALE,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Hash, PartialEq)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Voice {
|
pub struct Connection(pub *mut SPDConnection, u64);
|
||||||
/// The name of this voice. Unique with regards to the output module it came from.
|
|
||||||
pub name: String,
|
|
||||||
/// The language of this voice. Probably a BCP 47 language tag.
|
|
||||||
pub language: String,
|
|
||||||
/// The variant of this language, if present. Loosely defined.
|
|
||||||
pub variant: Option<String>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Voice {
|
|
||||||
/// Convert a SPDVoice to a Voice. Only fails if the fields are non-Unicode.
|
|
||||||
/// Does not check that the pointers are non-null, caller must ensure that.
|
|
||||||
unsafe fn try_from(v: &SPDVoice) -> Result<Self, std::str::Utf8Error> {
|
|
||||||
// SPDVoice fields appear to all be ASCII.
|
|
||||||
let name = CStr::from_ptr(v.name).to_str()?.to_owned();
|
|
||||||
let language = CStr::from_ptr(v.language).to_str()?.to_owned();
|
|
||||||
let variant = CStr::from_ptr(v.variant).to_str()?;
|
|
||||||
let variant = if variant == "none" {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(variant.to_owned())
|
|
||||||
};
|
|
||||||
Ok(Self {
|
|
||||||
name,
|
|
||||||
language,
|
|
||||||
variant,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub type Address = SPDConnectionAddress;
|
pub type Address = SPDConnectionAddress;
|
||||||
|
|
||||||
|
@ -99,10 +69,8 @@ pub enum Notification {
|
||||||
#[repr(u32)]
|
#[repr(u32)]
|
||||||
pub enum Punctuation {
|
pub enum Punctuation {
|
||||||
All = SPDPunctuation::SPD_PUNCT_ALL,
|
All = SPDPunctuation::SPD_PUNCT_ALL,
|
||||||
#[cfg(feature = "0_10")]
|
|
||||||
Most = SPDPunctuation::SPD_PUNCT_MOST,
|
|
||||||
Some = SPDPunctuation::SPD_PUNCT_SOME,
|
|
||||||
None = SPDPunctuation::SPD_PUNCT_NONE,
|
None = SPDPunctuation::SPD_PUNCT_NONE,
|
||||||
|
Some = SPDPunctuation::SPD_PUNCT_SOME,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
@ -113,22 +81,18 @@ pub enum CapitalLetters {
|
||||||
Icon = SPDCapitalLetters::SPD_CAP_ICON,
|
Icon = SPDCapitalLetters::SPD_CAP_ICON,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a `0` to a success and everything else to an error.
|
fn i32_to_bool(v: i32) -> bool {
|
||||||
fn c_int_to_result(r: c_int) -> Result<(), Error> {
|
v == 1
|
||||||
match r {
|
|
||||||
0 => Ok(()),
|
|
||||||
_ => Err(Error::OperationFailed),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
struct Callbacks {
|
struct Callbacks {
|
||||||
begin: Option<Box<dyn FnMut(size_t, size_t)>>,
|
begin: Option<Box<dyn FnMut(u64, u64)>>,
|
||||||
end: Option<Box<dyn FnMut(size_t, size_t)>>,
|
end: Option<Box<dyn FnMut(u64, u64)>>,
|
||||||
index_mark: Option<Box<dyn FnMut(size_t, size_t, String)>>,
|
index_mark: Option<Box<dyn FnMut(u64, u64, String)>>,
|
||||||
cancel: Option<Box<dyn FnMut(size_t, size_t)>>,
|
cancel: Option<Box<dyn FnMut(u64, u64)>>,
|
||||||
pause: Option<Box<dyn FnMut(size_t, size_t)>>,
|
pause: Option<Box<dyn FnMut(u64, u64)>>,
|
||||||
resume: Option<Box<dyn FnMut(size_t, size_t)>>,
|
resume: Option<Box<dyn FnMut(u64, u64)>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl Send for Callbacks {}
|
unsafe impl Send for Callbacks {}
|
||||||
|
@ -136,13 +100,13 @@ unsafe impl Send for Callbacks {}
|
||||||
unsafe impl Sync for Callbacks {}
|
unsafe impl Sync for Callbacks {}
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
static ref callbacks: Mutex<HashMap<size_t, Callbacks>> = {
|
static ref callbacks: Mutex<HashMap<u64, Callbacks>> = {
|
||||||
let m = HashMap::new();
|
let m = HashMap::new();
|
||||||
Mutex::new(m)
|
Mutex::new(m)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn cb(msg_id: size_t, client_id: size_t, state: u32) {
|
unsafe extern "C" fn cb(msg_id: u64, client_id: u64, state: u32) {
|
||||||
let state = match state {
|
let state = match state {
|
||||||
SPDNotificationType_SPD_EVENT_BEGIN => Notification::Begin,
|
SPDNotificationType_SPD_EVENT_BEGIN => Notification::Begin,
|
||||||
SPDNotificationType_SPD_EVENT_END => Notification::End,
|
SPDNotificationType_SPD_EVENT_END => Notification::End,
|
||||||
|
@ -166,7 +130,7 @@ unsafe extern "C" fn cb(msg_id: size_t, client_id: size_t, state: u32) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe extern "C" fn cb_im(msg_id: size_t, client_id: size_t, state: u32, index_mark: *mut c_char) {
|
unsafe extern "C" fn cb_im(msg_id: u64, client_id: u64, state: u32, index_mark: *mut i8) {
|
||||||
let index_mark = CStr::from_ptr(index_mark);
|
let index_mark = CStr::from_ptr(index_mark);
|
||||||
let index_mark = index_mark.to_string_lossy().to_string();
|
let index_mark = index_mark.to_string_lossy().to_string();
|
||||||
let state = match state {
|
let state = match state {
|
||||||
|
@ -185,36 +149,28 @@ unsafe extern "C" fn cb_im(msg_id: size_t, client_id: size_t, state: u32, index_
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Error {
|
pub enum SpeechDispatcherError {
|
||||||
/// speech-dispatcher failed to initialize. Ensure speech-dispatcher is actually working on
|
|
||||||
/// your system; for example, does the command `spd-say hello` work?
|
|
||||||
InitializationError,
|
InitializationError,
|
||||||
/// The operation failed
|
|
||||||
OperationFailed,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::error::Error for Error {}
|
impl std::error::Error for SpeechDispatcherError {}
|
||||||
|
|
||||||
impl fmt::Display for Error {
|
impl fmt::Display for SpeechDispatcherError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||||
use Error::*;
|
use SpeechDispatcherError::*;
|
||||||
match self {
|
match self {
|
||||||
InitializationError => write!(f, "failed to initialize"),
|
InitializationError => write!(f, "Failed to initialize"),
|
||||||
OperationFailed => write!(f, "operation failed"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
|
||||||
pub struct Connection(pub Arc<*mut SPDConnection>, size_t);
|
|
||||||
|
|
||||||
impl Connection {
|
impl Connection {
|
||||||
pub fn open<S: Into<String>>(
|
pub fn open<S: Into<String>>(
|
||||||
client_name: S,
|
client_name: S,
|
||||||
connection_name: S,
|
connection_name: S,
|
||||||
user_name: S,
|
user_name: S,
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
) -> Result<Self, Error> {
|
) -> Result<Self, SpeechDispatcherError> {
|
||||||
let clientname = CString::new(client_name.into()).unwrap();
|
let clientname = CString::new(client_name.into()).unwrap();
|
||||||
let connectionname = CString::new(connection_name.into()).unwrap();
|
let connectionname = CString::new(connection_name.into()).unwrap();
|
||||||
let username = CString::new(user_name.into()).unwrap();
|
let username = CString::new(user_name.into()).unwrap();
|
||||||
|
@ -226,14 +182,18 @@ impl Connection {
|
||||||
mode as u32,
|
mode as u32,
|
||||||
);
|
);
|
||||||
if c.is_null() {
|
if c.is_null() {
|
||||||
Err(Error::InitializationError)
|
None
|
||||||
} else {
|
} else {
|
||||||
Ok(Self::setup_connection(c))
|
Some(Self::setup_connection(c))
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let mut c = Self(Arc::new(connection?), 0);
|
if let Some(connection) = connection {
|
||||||
c.setup()?;
|
let mut c = Self(connection, 0);
|
||||||
|
c.setup();
|
||||||
Ok(c)
|
Ok(c)
|
||||||
|
} else {
|
||||||
|
Err(SpeechDispatcherError::InitializationError)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn open2<S: Into<String>>(
|
pub unsafe fn open2<S: Into<String>>(
|
||||||
|
@ -243,7 +203,7 @@ impl Connection {
|
||||||
mode: Mode,
|
mode: Mode,
|
||||||
address: *mut Address,
|
address: *mut Address,
|
||||||
autospawn: bool,
|
autospawn: bool,
|
||||||
) -> Result<Self, Error> {
|
) -> Self {
|
||||||
let auto_spawn = if autospawn { 1 } else { 0 };
|
let auto_spawn = if autospawn { 1 } else { 0 };
|
||||||
let error_result = vec![CString::new("").unwrap().into_raw()].as_mut_ptr();
|
let error_result = vec![CString::new("").unwrap().into_raw()].as_mut_ptr();
|
||||||
let clientname = CString::new(client_name.into()).unwrap();
|
let clientname = CString::new(client_name.into()).unwrap();
|
||||||
|
@ -259,15 +219,11 @@ impl Connection {
|
||||||
auto_spawn,
|
auto_spawn,
|
||||||
error_result,
|
error_result,
|
||||||
);
|
);
|
||||||
if c.is_null() {
|
Self::setup_connection(c)
|
||||||
Err(Error::InitializationError)
|
|
||||||
} else {
|
|
||||||
Ok(Self::setup_connection(c))
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
let mut c = Self(Arc::new(connection?), 0);
|
let mut c = Self(connection, 0);
|
||||||
c.setup()?;
|
c.setup();
|
||||||
Ok(c)
|
c
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe fn setup_connection(c: *mut SPDConnection) -> *mut SPDConnection {
|
unsafe fn setup_connection(c: *mut SPDConnection) -> *mut SPDConnection {
|
||||||
|
@ -280,7 +236,7 @@ impl Connection {
|
||||||
c
|
c
|
||||||
}
|
}
|
||||||
|
|
||||||
fn setup(&mut self) -> Result<(), Error> {
|
fn setup(&mut self) {
|
||||||
let client_id = self.send_data("HISTORY GET CLIENT_ID\r\n", true);
|
let client_id = self.send_data("HISTORY GET CLIENT_ID\r\n", true);
|
||||||
if let Some(client_id) = client_id {
|
if let Some(client_id) = client_id {
|
||||||
let client_id: Vec<&str> = client_id.split("\r\n").collect();
|
let client_id: Vec<&str> = client_id.split("\r\n").collect();
|
||||||
|
@ -288,26 +244,24 @@ impl Connection {
|
||||||
if let Some(client_id) = client_id {
|
if let Some(client_id) = client_id {
|
||||||
let client_id: Vec<&str> = client_id.split("-").collect();
|
let client_id: Vec<&str> = client_id.split("-").collect();
|
||||||
if let Some(client_id) = client_id.get(1) {
|
if let Some(client_id) = client_id.get(1) {
|
||||||
if let Ok(client_id) = client_id.parse::<size_t>() {
|
if let Ok(client_id) = client_id.parse::<u64>() {
|
||||||
self.1 = client_id;
|
self.1 = client_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
callbacks.lock().unwrap().insert(self.1, Default::default());
|
callbacks.lock().unwrap().insert(self.1, Default::default());
|
||||||
self.set_notification_on(Notification::All)
|
self.set_notification_on(Notification::All);
|
||||||
.map_err(|_| Error::InitializationError)?;
|
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn close(&self) {
|
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> {
|
pub fn say<S: Into<String>>(&self, priority: Priority, text: S) -> Option<u64> {
|
||||||
let text: String = text.into();
|
let text: String = text.into();
|
||||||
let param = CString::new(text).unwrap();
|
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 {
|
if rv != -1 {
|
||||||
Some(rv as u64)
|
Some(rv as u64)
|
||||||
} else {
|
} else {
|
||||||
|
@ -318,7 +272,7 @@ impl Connection {
|
||||||
pub fn sayf<S: Into<String>>(&self, priority: Priority, format: S) -> Option<i32> {
|
pub fn sayf<S: Into<String>>(&self, priority: Priority, format: S) -> Option<i32> {
|
||||||
let format: String = format.into();
|
let format: String = format.into();
|
||||||
let param = CString::new(format).unwrap();
|
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 {
|
if rv != -1 {
|
||||||
Some(rv)
|
Some(rv)
|
||||||
} else {
|
} else {
|
||||||
|
@ -326,120 +280,107 @@ impl Connection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stop(&self) -> Result<(), Error> {
|
pub fn stop(&self) -> bool {
|
||||||
let v = unsafe { spd_stop(*self.0) };
|
let v = unsafe { spd_stop(self.0) };
|
||||||
c_int_to_result(v)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stop_all(&self) -> Result<(), Error> {
|
pub fn stop_all(&self) -> bool {
|
||||||
let v = unsafe { spd_stop_all(*self.0) };
|
let v = unsafe { spd_stop_all(self.0) };
|
||||||
c_int_to_result(v)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stop_uid(&self, target_uid: i32) -> Result<(), Error> {
|
pub fn stop_uid(&self, target_uid: i32) -> bool {
|
||||||
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cancel(&self) -> Result<(), Error> {
|
pub fn cancel(&self) -> bool {
|
||||||
let v = unsafe { spd_cancel(*self.0) };
|
let v = unsafe { spd_cancel(self.0) };
|
||||||
c_int_to_result(v)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cancel_all(&self) -> Result<(), Error> {
|
pub fn cancel_all(&self) -> bool {
|
||||||
let v = unsafe { spd_cancel_all(*self.0) };
|
let v = unsafe { spd_cancel_all(self.0) };
|
||||||
c_int_to_result(v)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn cancel_uid(&self, target_uid: i32) -> Result<(), Error> {
|
pub fn cancel_uid(&self, target_uid: i32) -> bool {
|
||||||
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pause(&self) -> Result<(), Error> {
|
pub fn pause(&self) -> bool {
|
||||||
let v = unsafe { spd_pause(*self.0) };
|
let v = unsafe { spd_pause(self.0) };
|
||||||
c_int_to_result(v)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pause_all(&self) -> Result<(), Error> {
|
pub fn pause_all(&self) -> bool {
|
||||||
let v = unsafe { spd_pause_all(*self.0) };
|
let v = unsafe { spd_pause_all(self.0) };
|
||||||
c_int_to_result(v)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn pause_uid(&self, target_uid: i32) -> Result<(), Error> {
|
pub fn pause_uid(&self, target_uid: i32) -> bool {
|
||||||
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resume(&self) -> Result<(), Error> {
|
pub fn resume(&self) -> bool {
|
||||||
let v = unsafe { spd_resume(*self.0) };
|
let v = unsafe { spd_resume(self.0) };
|
||||||
c_int_to_result(v)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resume_all(&self) -> Result<(), Error> {
|
pub fn resume_all(&self) -> bool {
|
||||||
let v = unsafe { spd_resume_all(*self.0) };
|
let v = unsafe { spd_resume_all(self.0) };
|
||||||
c_int_to_result(v)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn resume_uid(&self, target_uid: i32) -> Result<(), Error> {
|
pub fn resume_uid(&self, target_uid: i32) -> bool {
|
||||||
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn key<S: Into<String>>(&self, priority: Priority, key_name: S) -> Result<(), Error> {
|
pub fn key<S: Into<String>>(&self, priority: Priority, key_name: S) -> bool {
|
||||||
let param = CString::new(key_name.into()).unwrap();
|
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn char<S: Into<String>>(&self, priority: Priority, char: S) -> Result<(), Error> {
|
pub fn char<S: Into<String>>(&self, priority: Priority, char: S) -> bool {
|
||||||
let param = CString::new(char.into()).unwrap();
|
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wchar(&self, priority: Priority, wchar: i32) -> Result<(), Error> {
|
pub fn wchar(&self, priority: Priority, wchar: i32) -> bool {
|
||||||
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) };
|
||||||
c_int_to_result(v)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn sound_icon<S: Into<String>>(
|
pub fn sound_icon<S: Into<String>>(&self, priority: Priority, icon_name: S) -> bool {
|
||||||
&self,
|
|
||||||
priority: Priority,
|
|
||||||
icon_name: S,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let param = CString::new(icon_name.into()).unwrap();
|
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_voice_type(&self, voice_type: VoiceType) -> Result<(), Error> {
|
pub fn set_voice_type(&self, voice_type: VoiceType) -> bool {
|
||||||
#[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) };
|
||||||
let v = unsafe { spd_set_voice_type(*self.0, voice_type as u32) };
|
i32_to_bool(v)
|
||||||
#[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> {
|
pub fn set_voice_type_all(&self, voice_type: VoiceType) -> bool {
|
||||||
#[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) };
|
||||||
let v = unsafe { spd_set_voice_type_all(*self.0, voice_type as u32) };
|
i32_to_bool(v)
|
||||||
#[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> {
|
pub fn set_voice_type_uid(&self, voice_type: VoiceType, target_uid: u32) -> bool {
|
||||||
#[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) };
|
||||||
let v = unsafe { spd_set_voice_type_uid(*self.0, voice_type as u32, target_uid) };
|
i32_to_bool(v)
|
||||||
#[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> {
|
pub fn get_voice_type(&self) -> VoiceType {
|
||||||
let v = unsafe { spd_get_voice_type(*self.0) };
|
let v = unsafe { spd_get_voice_type(self.0) };
|
||||||
Ok(match v {
|
match v {
|
||||||
SPDVoiceType::SPD_MALE1 => VoiceType::Male1,
|
SPDVoiceType::SPD_MALE1 => VoiceType::Male1,
|
||||||
SPDVoiceType::SPD_MALE2 => VoiceType::Male2,
|
SPDVoiceType::SPD_MALE2 => VoiceType::Male2,
|
||||||
SPDVoiceType::SPD_MALE3 => VoiceType::Male3,
|
SPDVoiceType::SPD_MALE3 => VoiceType::Male3,
|
||||||
|
@ -448,234 +389,213 @@ impl Connection {
|
||||||
SPDVoiceType::SPD_FEMALE3 => VoiceType::Female3,
|
SPDVoiceType::SPD_FEMALE3 => VoiceType::Female3,
|
||||||
SPDVoiceType::SPD_CHILD_MALE => VoiceType::ChildMale,
|
SPDVoiceType::SPD_CHILD_MALE => VoiceType::ChildMale,
|
||||||
SPDVoiceType::SPD_CHILD_FEMALE => VoiceType::ChildFemale,
|
SPDVoiceType::SPD_CHILD_FEMALE => VoiceType::ChildFemale,
|
||||||
_ => return Err(Error::OperationFailed), // can this happen?
|
_ => panic!("Invalid voice type"),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_synthesis_voice(&self, voice: &Voice) -> Result<(), Error> {
|
pub fn set_synthesis_voice<S: Into<String>>(&self, voice_name: S) -> bool {
|
||||||
let param = CString::new(voice.name.clone()).unwrap();
|
|
||||||
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 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(self.0, param.as_ptr()) };
|
||||||
c_int_to_result(v)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_synthesis_voice_uid<S: Into<String>>(
|
pub fn set_synthesis_voice_all<S: Into<String>>(&self, voice_name: S) -> bool {
|
||||||
&self,
|
|
||||||
voice_name: S,
|
|
||||||
target_uid: u32,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let param = CString::new(voice_name.into()).unwrap();
|
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_all(self.0, param.as_ptr()) };
|
||||||
c_int_to_result(v)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_data_mode(&self, mode: DataMode) -> Result<(), Error> {
|
pub fn set_synthesis_voice_uid<S: Into<String>>(&self, voice_name: S, target_uid: u32) -> bool {
|
||||||
let v = unsafe { spd_set_data_mode(*self.0, mode as u32) };
|
let param = CString::new(voice_name.into()).unwrap();
|
||||||
c_int_to_result(v)
|
let v = unsafe { spd_set_synthesis_voice_uid(self.0, param.as_ptr(), target_uid) };
|
||||||
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_notification_on(&self, notification: Notification) -> Result<(), Error> {
|
pub fn set_data_mode(&self, mode: DataMode) -> bool {
|
||||||
let v = unsafe { spd_set_notification_on(*self.0, notification as u32) };
|
let v = unsafe { spd_set_data_mode(self.0, mode as u32) };
|
||||||
c_int_to_result(v)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_notification_off(&self, notification: Notification) -> Result<(), Error> {
|
pub fn set_notification_on(&self, notification: Notification) -> bool {
|
||||||
let v = unsafe { spd_set_notification_off(*self.0, notification as u32) };
|
let v = unsafe { spd_set_notification_on(self.0, notification as u32) };
|
||||||
c_int_to_result(v)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_notification<S: Into<String>>(
|
pub fn set_notification_off(&self, notification: Notification) -> bool {
|
||||||
&self,
|
let v = unsafe { spd_set_notification_off(self.0, notification as u32) };
|
||||||
notification: Notification,
|
i32_to_bool(v)
|
||||||
state: S,
|
}
|
||||||
) -> Result<(), Error> {
|
|
||||||
|
pub fn set_notification<S: Into<String>>(&self, notification: Notification, state: S) -> bool {
|
||||||
let param = CString::new(state.into()).unwrap();
|
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_voice_rate(&self, rate: i32) -> Result<(), Error> {
|
pub fn set_voice_rate(&self, rate: i32) -> bool {
|
||||||
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_voice_rate_all(&self, rate: i32) -> Result<(), Error> {
|
pub fn set_voice_rate_all(&self, rate: i32) -> bool {
|
||||||
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_voice_rate_uid(&self, rate: i32, target_uid: u32) -> Result<(), Error> {
|
pub fn set_voice_rate_uid(&self, rate: i32, target_uid: u32) -> bool {
|
||||||
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_voice_rate(&self) -> i32 {
|
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> {
|
pub fn set_voice_pitch(&self, pitch: i32) -> bool {
|
||||||
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_voice_pitch_all(&self, pitch: i32) -> Result<(), Error> {
|
pub fn set_voice_pitch_all(&self, pitch: i32) -> bool {
|
||||||
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_voice_pitch_uid(&self, pitch: i32, target_uid: u32) -> Result<(), Error> {
|
pub fn set_voice_pitch_uid(&self, pitch: i32, target_uid: u32) -> bool {
|
||||||
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_voice_pitch(&self) -> i32 {
|
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> {
|
pub fn set_volume(&self, volume: i32) -> bool {
|
||||||
let v = unsafe { spd_set_volume(*self.0, volume) };
|
let v = unsafe { spd_set_volume(self.0, volume) };
|
||||||
c_int_to_result(v)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_volume_all(&self, volume: i32) -> Result<(), Error> {
|
pub fn set_volume_all(&self, volume: i32) -> bool {
|
||||||
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_volume_uid(&self, volume: i32, target_uid: u32) -> Result<(), Error> {
|
pub fn set_volume_uid(&self, volume: i32, target_uid: u32) -> bool {
|
||||||
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_volume(&self) -> i32 {
|
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> {
|
pub fn set_punctuation(&self, punctuation: Punctuation) -> bool {
|
||||||
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_punctuation_all(&self, punctuation: Punctuation) -> Result<(), Error> {
|
pub fn set_punctuation_all(&self, punctuation: Punctuation) -> bool {
|
||||||
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_punctuation_uid(
|
pub fn set_punctuation_uid(&self, punctuation: Punctuation, target_uid: u32) -> bool {
|
||||||
&self,
|
let v = unsafe { spd_set_punctuation_uid(self.0, punctuation as u32, target_uid) };
|
||||||
punctuation: Punctuation,
|
i32_to_bool(v)
|
||||||
target_uid: u32,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
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> {
|
pub fn set_capital_letters(&self, capital_letters: CapitalLetters) -> bool {
|
||||||
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_capital_letters_all(&self, capital_letters: CapitalLetters) -> Result<(), Error> {
|
pub fn set_capital_letters_all(&self, capital_letters: CapitalLetters) -> bool {
|
||||||
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_capital_letters_uid(
|
pub fn set_capital_letters_uid(
|
||||||
&self,
|
&self,
|
||||||
capital_letters: CapitalLetters,
|
capital_letters: CapitalLetters,
|
||||||
target_uid: u32,
|
target_uid: u32,
|
||||||
) -> Result<(), Error> {
|
) -> bool {
|
||||||
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_spelling(&self, spelling: bool) -> Result<(), Error> {
|
pub fn set_spelling(&self, spelling: bool) -> bool {
|
||||||
let s = if spelling {
|
let s = if spelling {
|
||||||
SPDSpelling::SPD_SPELL_ON
|
SPDSpelling::SPD_SPELL_ON
|
||||||
} else {
|
} else {
|
||||||
SPDSpelling::SPD_SPELL_OFF
|
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_spelling_all(&self, spelling: bool) -> Result<(), Error> {
|
pub fn set_spelling_all(&self, spelling: bool) -> bool {
|
||||||
let s = if spelling {
|
let s = if spelling {
|
||||||
SPDSpelling::SPD_SPELL_ON
|
SPDSpelling::SPD_SPELL_ON
|
||||||
} else {
|
} else {
|
||||||
SPDSpelling::SPD_SPELL_OFF
|
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_spelling_uid(&self, spelling: bool, target_uid: u32) -> Result<(), Error> {
|
pub fn set_spelling_uid(&self, spelling: bool, target_uid: u32) -> bool {
|
||||||
let s = if spelling {
|
let s = if spelling {
|
||||||
SPDSpelling::SPD_SPELL_ON
|
SPDSpelling::SPD_SPELL_ON
|
||||||
} else {
|
} else {
|
||||||
SPDSpelling::SPD_SPELL_OFF
|
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_language<S: Into<String>>(&self, language: S) -> Result<(), Error> {
|
pub fn set_language<S: Into<String>>(&self, language: S) -> bool {
|
||||||
let param = CString::new(language.into()).unwrap();
|
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_language_all<S: Into<String>>(&self, language: S) -> Result<(), Error> {
|
pub fn set_language_all<S: Into<String>>(&self, language: S) -> bool {
|
||||||
let param = CString::new(language.into()).unwrap();
|
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_language_uid<S: Into<String>>(
|
pub fn set_language_uid<S: Into<String>>(&self, language: S, target_uid: u32) -> bool {
|
||||||
&self,
|
|
||||||
language: S,
|
|
||||||
target_uid: u32,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let param = CString::new(language.into()).unwrap();
|
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_language(&self) -> Result<&str, Error> {
|
pub fn get_language(&self) -> &str {
|
||||||
let language = unsafe { spd_get_language(*self.0) };
|
let v = unsafe { CStr::from_ptr(spd_get_language(self.0)) };
|
||||||
if language.is_null() {
|
v.to_str().unwrap()
|
||||||
Err(Error::OperationFailed)
|
|
||||||
} else {
|
|
||||||
let language = unsafe { CStr::from_ptr(language) };
|
|
||||||
language.to_str().map_err(|_| Error::OperationFailed)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_output_module<S: Into<String>>(&self, output_module: S) -> Result<(), Error> {
|
pub fn set_output_module<S: Into<String>>(&self, output_module: S) -> bool {
|
||||||
let param = CString::new(output_module.into()).unwrap();
|
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_output_module_all<S: Into<String>>(&self, output_module: S) -> Result<(), Error> {
|
pub fn set_output_module_all<S: Into<String>>(&self, output_module: S) -> bool {
|
||||||
let param = CString::new(output_module.into()).unwrap();
|
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn set_output_module_uid<S: Into<String>>(
|
pub fn set_output_module_uid<S: Into<String>>(
|
||||||
&self,
|
&self,
|
||||||
output_module: S,
|
output_module: S,
|
||||||
target_uid: u32,
|
target_uid: u32,
|
||||||
) -> Result<(), Error> {
|
) -> bool {
|
||||||
let param = CString::new(output_module.into()).unwrap();
|
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)
|
i32_to_bool(v)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn send_data<S: Into<String>>(&self, data: S, wait_for_reply: bool) -> Option<String> {
|
pub fn send_data<S: Into<String>>(&self, data: S, wait_for_reply: bool) -> Option<String> {
|
||||||
|
@ -685,7 +605,7 @@ impl Connection {
|
||||||
SPD_NO_REPLY as i32
|
SPD_NO_REPLY as i32
|
||||||
};
|
};
|
||||||
let data = CString::new(data.into()).unwrap();
|
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() {
|
if rv.is_null() {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -694,7 +614,7 @@ impl Connection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_begin(&self, f: Option<Box<dyn FnMut(size_t, size_t)>>) {
|
pub fn on_begin(&self, f: Option<Box<dyn FnMut(u64, u64)>>) {
|
||||||
if let Ok(mut cbs) = callbacks.lock() {
|
if let Ok(mut cbs) = callbacks.lock() {
|
||||||
let cb = cbs.get_mut(&self.1);
|
let cb = cbs.get_mut(&self.1);
|
||||||
if let Some(cb) = cb {
|
if let Some(cb) = cb {
|
||||||
|
@ -703,7 +623,7 @@ impl Connection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_end(&self, f: Option<Box<dyn FnMut(size_t, size_t)>>) {
|
pub fn on_end(&self, f: Option<Box<dyn FnMut(u64, u64)>>) {
|
||||||
if let Ok(mut cbs) = callbacks.lock() {
|
if let Ok(mut cbs) = callbacks.lock() {
|
||||||
let cb = cbs.get_mut(&self.1);
|
let cb = cbs.get_mut(&self.1);
|
||||||
if let Some(cb) = cb {
|
if let Some(cb) = cb {
|
||||||
|
@ -712,7 +632,7 @@ impl Connection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_cancel(&self, f: Option<Box<dyn FnMut(size_t, size_t)>>) {
|
pub fn on_cancel(&self, f: Option<Box<dyn FnMut(u64, u64)>>) {
|
||||||
if let Ok(mut cbs) = callbacks.lock() {
|
if let Ok(mut cbs) = callbacks.lock() {
|
||||||
let cb = cbs.get_mut(&self.1);
|
let cb = cbs.get_mut(&self.1);
|
||||||
if let Some(cb) = cb {
|
if let Some(cb) = cb {
|
||||||
|
@ -721,7 +641,7 @@ impl Connection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_pause(&self, f: Option<Box<dyn FnMut(size_t, size_t)>>) {
|
pub fn on_pause(&self, f: Option<Box<dyn FnMut(u64, u64)>>) {
|
||||||
if let Ok(mut cbs) = callbacks.lock() {
|
if let Ok(mut cbs) = callbacks.lock() {
|
||||||
let cb = cbs.get_mut(&self.1);
|
let cb = cbs.get_mut(&self.1);
|
||||||
if let Some(cb) = cb {
|
if let Some(cb) = cb {
|
||||||
|
@ -730,7 +650,7 @@ impl Connection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_resume(&self, f: Option<Box<dyn FnMut(size_t, size_t)>>) {
|
pub fn on_resume(&self, f: Option<Box<dyn FnMut(u64, u64)>>) {
|
||||||
if let Ok(mut cbs) = callbacks.lock() {
|
if let Ok(mut cbs) = callbacks.lock() {
|
||||||
let cb = cbs.get_mut(&self.1);
|
let cb = cbs.get_mut(&self.1);
|
||||||
if let Some(cb) = cb {
|
if let Some(cb) = cb {
|
||||||
|
@ -739,7 +659,7 @@ impl Connection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn on_index_mark(&self, f: Option<Box<dyn FnMut(size_t, size_t, String)>>) {
|
pub fn on_index_mark(&self, f: Option<Box<dyn FnMut(u64, u64, String)>>) {
|
||||||
if let Ok(mut cbs) = callbacks.lock() {
|
if let Ok(mut cbs) = callbacks.lock() {
|
||||||
let cb = cbs.get_mut(&self.1);
|
let cb = cbs.get_mut(&self.1);
|
||||||
if let Some(cb) = cb {
|
if let Some(cb) = cb {
|
||||||
|
@ -748,72 +668,16 @@ impl Connection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_synthesis_voices(&self) -> Result<Vec<Voice>, Error> {
|
pub fn client_id(&self) -> u64 {
|
||||||
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
|
|
||||||
.iter()
|
|
||||||
.map(|v| v.read())
|
|
||||||
.flat_map(|v| {
|
|
||||||
if v.name.is_null() || v.language.is_null() || v.variant.is_null() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Voice::try_from(&v).ok()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.collect()
|
|
||||||
};
|
|
||||||
unsafe {
|
|
||||||
free_spd_voices(start);
|
|
||||||
}
|
|
||||||
Ok(voices)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn list_output_modules(&self) -> Result<Vec<String>, Error> {
|
|
||||||
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
|
|
||||||
.iter()
|
|
||||||
.flat_map(|v| CStr::from_ptr(*v).to_str().ok().map(String::from))
|
|
||||||
.collect()
|
|
||||||
};
|
|
||||||
unsafe {
|
|
||||||
free_spd_modules(start);
|
|
||||||
}
|
|
||||||
Ok(modules)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn client_id(&self) -> size_t {
|
|
||||||
self.1
|
self.1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Interpret a null-terminated array of pointers as a slice of pointers.
|
|
||||||
/// None of the pointers will be null if this returns Some.
|
|
||||||
unsafe fn null_term_array_ptr_to_slice<'a, T>(start: *mut *mut T) -> Option<&'a [*mut T]> {
|
|
||||||
if start.is_null() {
|
|
||||||
return None;
|
|
||||||
}
|
|
||||||
let mut current = start;
|
|
||||||
let mut len = 0;
|
|
||||||
|
|
||||||
while !current.read().is_null() {
|
|
||||||
len += 1;
|
|
||||||
current = current.add(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
Some(std::slice::from_raw_parts(start, len))
|
|
||||||
}
|
|
||||||
|
|
||||||
unsafe impl Send for Connection {}
|
unsafe impl Send for Connection {}
|
||||||
|
|
||||||
impl Drop for Connection {
|
impl Drop for Connection {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
if Arc::strong_count(&self.0) <= 1 {
|
|
||||||
self.close();
|
self.close();
|
||||||
callbacks.lock().unwrap().remove(&self.1);
|
callbacks.lock().unwrap().remove(&self.1);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user