From 37095733050de469476f58e6cb34cfac3378eb77 Mon Sep 17 00:00:00 2001 From: Nolan Darilek Date: Thu, 27 Jan 2022 10:26:12 -0600 Subject: [PATCH] Use `Voice` directly to avoid messing with stringly-typed voice names. --- speech-dispatcher/examples/list_voices.rs | 2 +- speech-dispatcher/src/lib.rs | 7 +++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/speech-dispatcher/examples/list_voices.rs b/speech-dispatcher/examples/list_voices.rs index d9e3217..23c90f2 100644 --- a/speech-dispatcher/examples/list_voices.rs +++ b/speech-dispatcher/examples/list_voices.rs @@ -24,6 +24,6 @@ fn main() -> Result<(), Box> { } } } - // Use connection.set_synthesis_voice(voice.name) to set the voice to use. + // Use connection.set_synthesis_voice(voice) to set the voice to use. Ok(()) } diff --git a/speech-dispatcher/src/lib.rs b/speech-dispatcher/src/lib.rs index fb436ba..a2ea3d0 100644 --- a/speech-dispatcher/src/lib.rs +++ b/speech-dispatcher/src/lib.rs @@ -44,8 +44,7 @@ pub enum VoiceType { #[derive(Clone, Debug, Hash, PartialEq)] pub struct Voice { - /// The name of this voice. Unique with regards to the output module it came from. Pass this to - /// [`Connection::set_synthesis_voice`] to use this voice. + /// 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, @@ -441,8 +440,8 @@ impl Connection { }) } - pub fn set_synthesis_voice>(&self, voice_name: S) -> Result<(), Error> { - let param = CString::new(voice_name.into()).unwrap(); + pub fn set_synthesis_voice(&self, voice: &Voice) -> Result<(), Error> { + 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) }