mirror of https://github.com/ndarilek/tts-rs.git
cargo fmt
This commit is contained in:
parent
6057d9c968
commit
c222c087b2
|
@ -77,11 +77,11 @@ fn main() -> Result<(), Error> {
|
||||||
let voices_list = tts.list_voices();
|
let voices_list = tts.list_voices();
|
||||||
println!("Available voices:\n===");
|
println!("Available voices:\n===");
|
||||||
for v in voices_list.iter() {
|
for v in voices_list.iter() {
|
||||||
println!("{}",v);
|
println!("{}", v);
|
||||||
tts.set_voice(v)?;
|
tts.set_voice(v)?;
|
||||||
println!("voice set");
|
println!("voice set");
|
||||||
println!("{}", tts.voice()?);
|
println!("{}", tts.voice()?);
|
||||||
tts.speak(v,false)?;
|
tts.speak(v, false)?;
|
||||||
}
|
}
|
||||||
tts.set_voice(original_voice)?;
|
tts.set_voice(original_voice)?;
|
||||||
}
|
}
|
||||||
|
|
|
@ -201,7 +201,7 @@ impl Backend for AppKit {
|
||||||
Ok(is_speaking != NO as i8)
|
Ok(is_speaking != NO as i8)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn voice(&self) -> Result<String,Error> {
|
fn voice(&self) -> Result<String, Error> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ impl Backend for AppKit {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_voice(&mut self, voice: &str) -> Result<(),Error> {
|
fn set_voice(&mut self, voice: &str) -> Result<(), Error> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,8 +9,8 @@ use log::{info, trace};
|
||||||
use objc::runtime::{Object, Sel};
|
use objc::runtime::{Object, Sel};
|
||||||
use objc::{class, declare::ClassDecl, msg_send, sel, sel_impl};
|
use objc::{class, declare::ClassDecl, msg_send, sel, sel_impl};
|
||||||
|
|
||||||
use crate::{Backend, BackendId, Error, Features, UtteranceId, CALLBACKS};
|
|
||||||
use crate::voices::Backend as VoiceBackend;
|
use crate::voices::Backend as VoiceBackend;
|
||||||
|
use crate::{Backend, BackendId, Error, Features, UtteranceId, CALLBACKS};
|
||||||
|
|
||||||
mod voices;
|
mod voices;
|
||||||
use voices::*;
|
use voices::*;
|
||||||
|
@ -280,15 +280,18 @@ impl Backend for AvFoundation {
|
||||||
Ok(is_speaking != NO as i8)
|
Ok(is_speaking != NO as i8)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn voice(&self) -> Result<String,Error> {
|
fn voice(&self) -> Result<String, Error> {
|
||||||
Ok(self.voice.id())
|
Ok(self.voice.id())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list_voices(&self) -> Vec<String> {
|
fn list_voices(&self) -> Vec<String> {
|
||||||
AVSpeechSynthesisVoice::list().iter().map(|v| {v.id()}).collect()
|
AVSpeechSynthesisVoice::list()
|
||||||
|
.iter()
|
||||||
|
.map(|v| v.id())
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_voice(&mut self, voice: &str) -> Result<(),Error> {
|
fn set_voice(&mut self, voice: &str) -> Result<(), Error> {
|
||||||
self.voice = AVSpeechSynthesisVoice::new();
|
self.voice = AVSpeechSynthesisVoice::new();
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,25 +1,24 @@
|
||||||
|
use cocoa_foundation::base::{id, nil};
|
||||||
|
use cocoa_foundation::foundation::NSString;
|
||||||
|
use core_foundation::array::CFArray;
|
||||||
|
use core_foundation::string::CFString;
|
||||||
use objc::runtime::*;
|
use objc::runtime::*;
|
||||||
use objc::*;
|
use objc::*;
|
||||||
use core_foundation::array::CFArray;
|
|
||||||
use cocoa_foundation::foundation::NSString;
|
|
||||||
use cocoa_foundation::base::{nil,id};
|
|
||||||
use core_foundation::string::CFString;
|
|
||||||
|
|
||||||
use crate::backends::AvFoundation;
|
use crate::backends::AvFoundation;
|
||||||
use crate::voices;
|
use crate::voices;
|
||||||
use crate::voices::Gender;
|
use crate::voices::Gender;
|
||||||
|
|
||||||
#[derive(Copy,Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub(crate) struct AVSpeechSynthesisVoice(*const Object);
|
pub(crate) struct AVSpeechSynthesisVoice(*const Object);
|
||||||
|
|
||||||
impl AVSpeechSynthesisVoice {
|
impl AVSpeechSynthesisVoice {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
let voice: *const Object;
|
let voice: *const Object;
|
||||||
unsafe{
|
unsafe {
|
||||||
voice = msg_send![class!(AVSpeechSynthesisVoice), new];
|
voice = msg_send![class!(AVSpeechSynthesisVoice), new];
|
||||||
};
|
};
|
||||||
AVSpeechSynthesisVoice{0:voice}
|
AVSpeechSynthesisVoice { 0: voice }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,19 +34,22 @@ impl voices::Backend for AVSpeechSynthesisVoice {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn list() -> Vec<Self> {
|
fn list() -> Vec<Self> {
|
||||||
let voices: CFArray = unsafe{msg_send![class!(AVSpeechSynthesisVoice), speechVoices]};
|
let voices: CFArray = unsafe { msg_send![class!(AVSpeechSynthesisVoice), speechVoices] };
|
||||||
voices.iter().map(|v| {
|
voices
|
||||||
AVSpeechSynthesisVoice{0: *v as *const Object}
|
.iter()
|
||||||
}).collect()
|
.map(|v| AVSpeechSynthesisVoice {
|
||||||
|
0: *v as *const Object,
|
||||||
|
})
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn name(self) -> String {
|
fn name(self) -> String {
|
||||||
let name: CFString = unsafe{msg_send![self.0, name]};
|
let name: CFString = unsafe { msg_send![self.0, name] };
|
||||||
name.to_string()
|
name.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn gender(self) -> Gender {
|
fn gender(self) -> Gender {
|
||||||
let gender: i64 = unsafe{ msg_send![self.0, gender] };
|
let gender: i64 = unsafe { msg_send![self.0, gender] };
|
||||||
match gender {
|
match gender {
|
||||||
1 => Gender::Male,
|
1 => Gender::Male,
|
||||||
2 => Gender::Female,
|
2 => Gender::Female,
|
||||||
|
@ -56,12 +58,12 @@ impl voices::Backend for AVSpeechSynthesisVoice {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn id(self) -> String {
|
fn id(self) -> String {
|
||||||
let identifier: CFString = unsafe{msg_send![self.0, identifier]};
|
let identifier: CFString = unsafe { msg_send![self.0, identifier] };
|
||||||
identifier.to_string()
|
identifier.to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn language(self) -> voices::LanguageIdentifier {
|
fn language(self) -> voices::LanguageIdentifier {
|
||||||
let lang: CFString = unsafe{msg_send![self.0, language]};
|
let lang: CFString = unsafe { msg_send![self.0, language] };
|
||||||
lang.to_string().parse().unwrap()
|
lang.to_string().parse().unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -181,7 +181,7 @@ impl Backend for SpeechDispatcher {
|
||||||
Ok(*is_speaking)
|
Ok(*is_speaking)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn voice(&self) -> Result<String,Error> {
|
fn voice(&self) -> Result<String, Error> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -189,7 +189,7 @@ impl Backend for SpeechDispatcher {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_voice(&mut self, voice: &str) -> Result<(),Error> {
|
fn set_voice(&mut self, voice: &str) -> Result<(), Error> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -109,7 +109,7 @@ impl Backend for Tolk {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn voice(&self) -> Result<String,Error> {
|
fn voice(&self) -> Result<String, Error> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +117,7 @@ impl Backend for Tolk {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_voice(&mut self, voice: &str) -> Result<(),Error> {
|
fn set_voice(&mut self, voice: &str) -> Result<(), Error> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -198,7 +198,7 @@ impl Backend for Web {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn voice(&self) -> Result<String,Error> {
|
fn voice(&self) -> Result<String, Error> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,7 +206,7 @@ impl Backend for Web {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_voice(&mut self, voice: &str) -> Result<(),Error> {
|
fn set_voice(&mut self, voice: &str) -> Result<(), Error> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -291,7 +291,7 @@ impl Backend for WinRt {
|
||||||
Ok(!utterances.is_empty())
|
Ok(!utterances.is_empty())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn voice(&self) -> Result<String,Error> {
|
fn voice(&self) -> Result<String, Error> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +299,7 @@ impl Backend for WinRt {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn set_voice(&mut self, voice: &str) -> Result<(),Error> {
|
fn set_voice(&mut self, voice: &str) -> Result<(), Error> {
|
||||||
unimplemented!()
|
unimplemented!()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -232,7 +232,7 @@ pub trait Backend: Clone {
|
||||||
fn is_speaking(&self) -> Result<bool, Error>;
|
fn is_speaking(&self) -> Result<bool, Error>;
|
||||||
fn voice(&self) -> Result<String, Error>;
|
fn voice(&self) -> Result<String, Error>;
|
||||||
fn list_voices(&self) -> Vec<String>;
|
fn list_voices(&self) -> Vec<String>;
|
||||||
fn set_voice(&mut self, voice: &str) -> Result<(),Error>;
|
fn set_voice(&mut self, voice: &str) -> Result<(), Error>;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -569,9 +569,9 @@ impl Tts {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the current speaking voice.
|
* Return the current speaking voice.
|
||||||
*/
|
*/
|
||||||
pub fn voice(&self) -> Result<String,Error> {
|
pub fn voice(&self) -> Result<String, Error> {
|
||||||
let Features { voices, .. } = self.supported_features();
|
let Features { voices, .. } = self.supported_features();
|
||||||
if voices {
|
if voices {
|
||||||
self.0.read().unwrap().voice()
|
self.0.read().unwrap().voice()
|
||||||
|
@ -583,7 +583,7 @@ impl Tts {
|
||||||
/**
|
/**
|
||||||
* Set speaking voice.
|
* Set speaking voice.
|
||||||
*/
|
*/
|
||||||
pub fn set_voice<S: Into<String>>(&mut self, voice: S) -> Result<(),Error> {
|
pub fn set_voice<S: Into<String>>(&mut self, voice: S) -> Result<(), Error> {
|
||||||
let Features {
|
let Features {
|
||||||
voices: voices_feature,
|
voices: voices_feature,
|
||||||
..
|
..
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
pub use unic_langid::LanguageIdentifier;
|
pub use unic_langid::LanguageIdentifier;
|
||||||
|
|
||||||
pub enum Gender {
|
pub enum Gender {
|
||||||
|
|
Loading…
Reference in New Issue