mirror of
https://github.com/ndarilek/tts-rs.git
synced 2024-11-17 13:09:37 +00:00
implement set_voice for AVFoundation backend
- TODO: test the implementation - fixed: set_voice mutability of self parameter
This commit is contained in:
parent
5b0d1b6621
commit
6ed94686f3
|
@ -204,7 +204,7 @@ impl Backend for AppKit {
|
|||
unimplemented!()
|
||||
}
|
||||
|
||||
fn set_voice(&self, voice: String) -> Result<(),Error> {
|
||||
fn set_voice(&mut self, voice: String) -> Result<(),Error> {
|
||||
unimplemented!()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,7 +29,7 @@ impl AvFoundation {
|
|||
rate: 0.5,
|
||||
volume: 1.,
|
||||
pitch: 1.,
|
||||
voice: AVSpeechSynthesisVoice::new(),
|
||||
voice: AVSpeechSynthesisVoice::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -59,6 +59,7 @@ impl Backend for AvFoundation {
|
|||
let _: () = msg_send![utterance, setRate: self.rate];
|
||||
let _: () = msg_send![utterance, setVolume: self.volume];
|
||||
let _: () = msg_send![utterance, setPitchMultiplier: self.pitch];
|
||||
let _: () = msg_send![utterance, setVoice: self.voice];
|
||||
let _: () = msg_send![self.synth, speakUtterance: utterance];
|
||||
}
|
||||
Ok(())
|
||||
|
@ -149,7 +150,8 @@ impl Backend for AvFoundation {
|
|||
AVSpeechSynthesisVoice::list().iter().map(|v| {v.identifier()}).collect()
|
||||
}
|
||||
|
||||
fn set_voice(&self, voice: String) -> Result<(),Error> {
|
||||
fn set_voice(&mut self, voice: String) -> Result<(),Error> {
|
||||
self.voice = AVSpeechSynthesisVoice::new(voice);
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,8 +8,14 @@ use core_foundation::string::CFString;
|
|||
pub struct AVSpeechSynthesisVoice(*const Object);
|
||||
|
||||
impl AVSpeechSynthesisVoice {
|
||||
pub fn new() -> Self {
|
||||
Self::list()[0]
|
||||
pub fn new(identifier: String) -> Self {
|
||||
let i: CFString = CFString::from(identifier.as_str());
|
||||
let voice: *const Object = unsafe{msg_send![class!(AVSpeechSynthesisVoice).metaclass(), voiceWithIdentifier: i]};
|
||||
AVSpeechSynthesisVoice{0: voice}
|
||||
}
|
||||
|
||||
pub fn default() -> Self {
|
||||
AVSpeechSynthesisVoice::list()[0]
|
||||
}
|
||||
|
||||
pub fn list() -> Vec<Self> {
|
||||
|
|
|
@ -102,7 +102,7 @@ pub trait Backend {
|
|||
fn is_speaking(&self) -> Result<bool, Error>;
|
||||
fn voice(&self) -> Result<String, Error>;
|
||||
fn list_voices(&self) -> Vec<String>;
|
||||
fn set_voice(&self, voice: String) -> Result<(),Error>;
|
||||
fn set_voice(&mut self, voice: String) -> Result<(),Error>;
|
||||
}
|
||||
|
||||
pub struct TTS(Box<dyn Backend>);
|
||||
|
@ -399,7 +399,7 @@ impl TTS {
|
|||
/**
|
||||
* Set speaking voice.
|
||||
*/
|
||||
pub fn set_voice(&self, voice: String) -> Result<(),Error> {
|
||||
pub fn set_voice(&mut self, voice: String) -> Result<(),Error> {
|
||||
let Features {
|
||||
voices: voices_feature,
|
||||
..
|
||||
|
|
Loading…
Reference in New Issue
Block a user