2018-12-14 19:35:49 +00:00
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
use log::{info, trace};
|
|
|
|
use speech_dispatcher::*;
|
|
|
|
|
2019-03-24 21:30:45 +00:00
|
|
|
use crate::{Backend, Error, Features};
|
2018-12-14 19:35:49 +00:00
|
|
|
|
|
|
|
pub struct SpeechDispatcher(Connection);
|
|
|
|
|
|
|
|
impl SpeechDispatcher {
|
2019-12-23 13:37:48 +00:00
|
|
|
pub fn new() -> Self {
|
2018-12-14 19:35:49 +00:00
|
|
|
info!("Initializing SpeechDispatcher backend");
|
|
|
|
let connection = speech_dispatcher::Connection::open("tts", "tts", "tts", Mode::Single);
|
|
|
|
SpeechDispatcher(connection)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Backend for SpeechDispatcher {
|
2019-03-24 21:30:45 +00:00
|
|
|
fn supported_features(&self) -> Features {
|
|
|
|
Features {
|
|
|
|
stop: true,
|
|
|
|
rate: true,
|
|
|
|
pitch: true,
|
|
|
|
volume: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-12-30 17:13:48 +00:00
|
|
|
fn speak(&self, text: &str, interrupt: bool) -> Result<(), Error> {
|
2018-12-14 19:35:49 +00:00
|
|
|
trace!("speak({}, {})", text, interrupt);
|
|
|
|
if interrupt {
|
2018-12-30 17:13:48 +00:00
|
|
|
self.stop()?;
|
2018-12-14 19:35:49 +00:00
|
|
|
}
|
2019-09-30 15:36:51 +00:00
|
|
|
let single_char = text.to_string().capacity() == 1;
|
|
|
|
if single_char {
|
|
|
|
self.0.set_punctuation(Punctuation::All);
|
|
|
|
}
|
2018-12-14 19:35:49 +00:00
|
|
|
self.0.say(Priority::Important, text);
|
2019-09-30 15:36:51 +00:00
|
|
|
if single_char {
|
|
|
|
self.0.set_punctuation(Punctuation::None);
|
|
|
|
}
|
2018-12-30 17:13:48 +00:00
|
|
|
Ok(())
|
2018-12-14 19:35:49 +00:00
|
|
|
}
|
|
|
|
|
2018-12-30 17:13:48 +00:00
|
|
|
fn stop(&self) -> Result<(), Error> {
|
2018-12-28 14:49:02 +00:00
|
|
|
trace!("stop()");
|
|
|
|
self.0.cancel();
|
2018-12-30 17:13:48 +00:00
|
|
|
Ok(())
|
2018-12-28 14:49:02 +00:00
|
|
|
}
|
|
|
|
|
Clean up speech synthesis properties, and implement everything for WinRT.
I'd previously attempted to normalize everything to `u8`, but this had some drawbacks:
* It failed to account for some synthesis drivers defining normal as mid-range, while most define it very low.
* It didn't track the normal value for a given synthesizer.
* There was no clean way to map a curve between the minimum, normal, and maximum rates.
Here we track the minimum, normal, and maximum values of rate, pitch, and volume. Sanity checks are done on set.
Also, as a further proof-of-concept, all properties are now implemented for the WinRT driver.
2020-05-18 23:12:59 +00:00
|
|
|
fn min_rate(&self) -> f32 {
|
|
|
|
-100.
|
|
|
|
}
|
|
|
|
|
|
|
|
fn max_rate(&self) -> f32 {
|
|
|
|
100.
|
|
|
|
}
|
|
|
|
|
|
|
|
fn normal_rate(&self) -> f32 {
|
|
|
|
0.
|
2018-12-14 19:35:49 +00:00
|
|
|
}
|
|
|
|
|
Clean up speech synthesis properties, and implement everything for WinRT.
I'd previously attempted to normalize everything to `u8`, but this had some drawbacks:
* It failed to account for some synthesis drivers defining normal as mid-range, while most define it very low.
* It didn't track the normal value for a given synthesizer.
* There was no clean way to map a curve between the minimum, normal, and maximum rates.
Here we track the minimum, normal, and maximum values of rate, pitch, and volume. Sanity checks are done on set.
Also, as a further proof-of-concept, all properties are now implemented for the WinRT driver.
2020-05-18 23:12:59 +00:00
|
|
|
fn get_rate(&self) -> Result<f32, Error> {
|
|
|
|
Ok(self.0.get_voice_rate() as f32)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn set_rate(&mut self, rate: f32) -> Result<(), Error> {
|
|
|
|
self.0.set_voice_rate(rate as i32);
|
2018-12-30 17:13:48 +00:00
|
|
|
Ok(())
|
2018-12-15 15:56:13 +00:00
|
|
|
}
|
|
|
|
|
Clean up speech synthesis properties, and implement everything for WinRT.
I'd previously attempted to normalize everything to `u8`, but this had some drawbacks:
* It failed to account for some synthesis drivers defining normal as mid-range, while most define it very low.
* It didn't track the normal value for a given synthesizer.
* There was no clean way to map a curve between the minimum, normal, and maximum rates.
Here we track the minimum, normal, and maximum values of rate, pitch, and volume. Sanity checks are done on set.
Also, as a further proof-of-concept, all properties are now implemented for the WinRT driver.
2020-05-18 23:12:59 +00:00
|
|
|
fn min_pitch(&self) -> f32 {
|
|
|
|
-100.
|
2018-12-15 15:56:13 +00:00
|
|
|
}
|
|
|
|
|
Clean up speech synthesis properties, and implement everything for WinRT.
I'd previously attempted to normalize everything to `u8`, but this had some drawbacks:
* It failed to account for some synthesis drivers defining normal as mid-range, while most define it very low.
* It didn't track the normal value for a given synthesizer.
* There was no clean way to map a curve between the minimum, normal, and maximum rates.
Here we track the minimum, normal, and maximum values of rate, pitch, and volume. Sanity checks are done on set.
Also, as a further proof-of-concept, all properties are now implemented for the WinRT driver.
2020-05-18 23:12:59 +00:00
|
|
|
fn max_pitch(&self) -> f32 {
|
|
|
|
100.
|
|
|
|
}
|
|
|
|
|
|
|
|
fn normal_pitch(&self) -> f32 {
|
|
|
|
0.
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_pitch(&self) -> Result<f32, Error> {
|
|
|
|
Ok(self.0.get_voice_pitch() as f32)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn set_pitch(&mut self, pitch: f32) -> Result<(), Error> {
|
|
|
|
self.0.set_voice_pitch(pitch as i32);
|
2018-12-30 17:13:48 +00:00
|
|
|
Ok(())
|
2018-12-15 15:56:13 +00:00
|
|
|
}
|
|
|
|
|
Clean up speech synthesis properties, and implement everything for WinRT.
I'd previously attempted to normalize everything to `u8`, but this had some drawbacks:
* It failed to account for some synthesis drivers defining normal as mid-range, while most define it very low.
* It didn't track the normal value for a given synthesizer.
* There was no clean way to map a curve between the minimum, normal, and maximum rates.
Here we track the minimum, normal, and maximum values of rate, pitch, and volume. Sanity checks are done on set.
Also, as a further proof-of-concept, all properties are now implemented for the WinRT driver.
2020-05-18 23:12:59 +00:00
|
|
|
fn min_volume(&self) -> f32 {
|
|
|
|
-100.
|
|
|
|
}
|
|
|
|
|
|
|
|
fn max_volume(&self) -> f32 {
|
|
|
|
100.
|
|
|
|
}
|
|
|
|
|
|
|
|
fn normal_volume(&self) -> f32 {
|
|
|
|
0.
|
|
|
|
}
|
|
|
|
|
|
|
|
fn get_volume(&self) -> Result<f32, Error> {
|
|
|
|
Ok(self.0.get_volume() as f32)
|
2018-12-15 15:56:13 +00:00
|
|
|
}
|
|
|
|
|
Clean up speech synthesis properties, and implement everything for WinRT.
I'd previously attempted to normalize everything to `u8`, but this had some drawbacks:
* It failed to account for some synthesis drivers defining normal as mid-range, while most define it very low.
* It didn't track the normal value for a given synthesizer.
* There was no clean way to map a curve between the minimum, normal, and maximum rates.
Here we track the minimum, normal, and maximum values of rate, pitch, and volume. Sanity checks are done on set.
Also, as a further proof-of-concept, all properties are now implemented for the WinRT driver.
2020-05-18 23:12:59 +00:00
|
|
|
fn set_volume(&mut self, volume: f32) -> Result<(), Error> {
|
|
|
|
self.0.set_volume(volume as i32);
|
2018-12-30 17:13:48 +00:00
|
|
|
Ok(())
|
2018-12-14 19:35:49 +00:00
|
|
|
}
|
|
|
|
}
|