pub trait Synthesizer:
Send
+ Sync
+ 'static {
// Required methods
fn sample_rate(&self) -> u32;
fn synthesize_with(
&self,
text: &SpeechText,
voice: Option<&Voice>,
rate: SpeakingRate,
out: SpeechWriter,
cancel: &CancelToken,
) -> Result<(), SynthesisError>;
// Provided method
fn plays_audio_itself(&self) -> bool { ... }
}Expand description
The contract every text-to-speech engine implements.
An implementation must:
- write PCM into
outas it is produced, so playback starts before the whole utterance is synthesized; - poll
cancelat its natural pause points and answerSynthesisError::Cancelled; - treat a closed writer as the listener being gone and stop, answering
SynthesisError::Cancelled; - close the writer on every exit —
SpeechWriter::finishon success,SpeechWriter::failwith the cause on failure; - wrap its own failures in
BackendError::engineunderSynthesisError::LoadorSynthesisError::Inference; - refuse a voice it does not have as
SynthesisError::UnsupportedVoice.
Required Methods§
Sourcefn sample_rate(&self) -> u32
fn sample_rate(&self) -> u32
The rate of the PCM this engine writes, fixed by its model.
Sourcefn synthesize_with(
&self,
text: &SpeechText,
voice: Option<&Voice>,
rate: SpeakingRate,
out: SpeechWriter,
cancel: &CancelToken,
) -> Result<(), SynthesisError>
fn synthesize_with( &self, text: &SpeechText, voice: Option<&Voice>, rate: SpeakingRate, out: SpeechWriter, cancel: &CancelToken, ) -> Result<(), SynthesisError>
Synthesizes speech into out, chunk by chunk. voice of None means
the engine’s configured default.
Provided Methods§
Sourcefn plays_audio_itself(&self) -> bool
fn plays_audio_itself(&self) -> bool
Whether this engine delivers sound itself rather than writing PCM: a
platform voice program synthesizes and plays in one stroke.
Synthesis::speak skips its own playback for such an engine. A
wrapper around another synthesizer must forward this, or start
hands back an empty session instead of refusing.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".
Implementations on Foreign Types§
Source§impl<T: Synthesizer + ?Sized> Synthesizer for Arc<T>
A shared engine synthesizes like the engine itself.
impl<T: Synthesizer + ?Sized> Synthesizer for Arc<T>
A shared engine synthesizes like the engine itself.