1
0
mirror of https://github.com/ndarilek/tts-rs.git synced 2024-11-17 11:09:37 +00:00

cargo fmt

This commit is contained in:
Nolan Darilek 2022-03-30 10:18:22 -05:00
parent 6057d9c968
commit c222c087b2
10 changed files with 41 additions and 37 deletions

View File

@ -77,11 +77,11 @@ fn main() -> Result<(), Error> {
let voices_list = tts.list_voices();
println!("Available voices:\n===");
for v in voices_list.iter() {
println!("{}",v);
println!("{}", v);
tts.set_voice(v)?;
println!("voice set");
println!("{}", tts.voice()?);
tts.speak(v,false)?;
tts.speak(v, false)?;
}
tts.set_voice(original_voice)?;
}

View File

@ -201,7 +201,7 @@ impl Backend for AppKit {
Ok(is_speaking != NO as i8)
}
fn voice(&self) -> Result<String,Error> {
fn voice(&self) -> Result<String, Error> {
unimplemented!()
}
@ -209,7 +209,7 @@ impl Backend for AppKit {
unimplemented!()
}
fn set_voice(&mut self, voice: &str) -> Result<(),Error> {
fn set_voice(&mut self, voice: &str) -> Result<(), Error> {
unimplemented!()
}
}

View File

@ -9,8 +9,8 @@ use log::{info, trace};
use objc::runtime::{Object, Sel};
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::{Backend, BackendId, Error, Features, UtteranceId, CALLBACKS};
mod voices;
use voices::*;
@ -280,15 +280,18 @@ impl Backend for AvFoundation {
Ok(is_speaking != NO as i8)
}
fn voice(&self) -> Result<String,Error> {
fn voice(&self) -> Result<String, Error> {
Ok(self.voice.id())
}
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();
Ok(())
}

View File

@ -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::*;
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::voices;
use crate::voices::Gender;
#[derive(Copy,Clone, Debug)]
#[derive(Copy, Clone, Debug)]
pub(crate) struct AVSpeechSynthesisVoice(*const Object);
impl AVSpeechSynthesisVoice {
pub fn new() -> Self {
let voice: *const Object;
unsafe{
unsafe {
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> {
let voices: CFArray = unsafe{msg_send![class!(AVSpeechSynthesisVoice), speechVoices]};
voices.iter().map(|v| {
AVSpeechSynthesisVoice{0: *v as *const Object}
}).collect()
let voices: CFArray = unsafe { msg_send![class!(AVSpeechSynthesisVoice), speechVoices] };
voices
.iter()
.map(|v| AVSpeechSynthesisVoice {
0: *v as *const Object,
})
.collect()
}
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()
}
fn gender(self) -> Gender {
let gender: i64 = unsafe{ msg_send![self.0, gender] };
let gender: i64 = unsafe { msg_send![self.0, gender] };
match gender {
1 => Gender::Male,
2 => Gender::Female,
@ -56,12 +58,12 @@ impl voices::Backend for AVSpeechSynthesisVoice {
}
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()
}
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()
}
}

View File

@ -181,7 +181,7 @@ impl Backend for SpeechDispatcher {
Ok(*is_speaking)
}
fn voice(&self) -> Result<String,Error> {
fn voice(&self) -> Result<String, Error> {
unimplemented!()
}
@ -189,7 +189,7 @@ impl Backend for SpeechDispatcher {
unimplemented!()
}
fn set_voice(&mut self, voice: &str) -> Result<(),Error> {
fn set_voice(&mut self, voice: &str) -> Result<(), Error> {
unimplemented!()
}
}

View File

@ -109,7 +109,7 @@ impl Backend for Tolk {
unimplemented!()
}
fn voice(&self) -> Result<String,Error> {
fn voice(&self) -> Result<String, Error> {
unimplemented!()
}
@ -117,7 +117,7 @@ impl Backend for Tolk {
unimplemented!()
}
fn set_voice(&mut self, voice: &str) -> Result<(),Error> {
fn set_voice(&mut self, voice: &str) -> Result<(), Error> {
unimplemented!()
}
}

View File

@ -198,7 +198,7 @@ impl Backend for Web {
}
}
fn voice(&self) -> Result<String,Error> {
fn voice(&self) -> Result<String, Error> {
unimplemented!()
}
@ -206,7 +206,7 @@ impl Backend for Web {
unimplemented!()
}
fn set_voice(&mut self, voice: &str) -> Result<(),Error> {
fn set_voice(&mut self, voice: &str) -> Result<(), Error> {
unimplemented!()
}
}

View File

@ -291,7 +291,7 @@ impl Backend for WinRt {
Ok(!utterances.is_empty())
}
fn voice(&self) -> Result<String,Error> {
fn voice(&self) -> Result<String, Error> {
unimplemented!()
}
@ -299,7 +299,7 @@ impl Backend for WinRt {
unimplemented!()
}
fn set_voice(&mut self, voice: &str) -> Result<(),Error> {
fn set_voice(&mut self, voice: &str) -> Result<(), Error> {
unimplemented!()
}
}

View File

@ -232,7 +232,7 @@ pub trait Backend: Clone {
fn is_speaking(&self) -> Result<bool, Error>;
fn voice(&self) -> Result<String, Error>;
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)]
@ -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();
if voices {
self.0.read().unwrap().voice()
@ -583,7 +583,7 @@ impl Tts {
/**
* 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 {
voices: voices_feature,
..

View File

@ -1,4 +1,3 @@
pub use unic_langid::LanguageIdentifier;
pub enum Gender {