Trait speech_synthesis::SpeechSynthesiser
source · pub trait SpeechSynthesiser {
type EventStream: UtteranceEventStream;
// Required methods
fn negotiate_audio_format(
&self,
pref: AudioFormatPreference
) -> Option<AudioFormat>;
fn synthesise_ssml_stream<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
input: Speak,
audio_format: &'life1 AudioFormat,
config: &'life2 UtteranceConfig
) -> Pin<Box<dyn Future<Output = Result<Self::EventStream>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
fn synthesise_text_stream<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
input: impl 'async_trait + AsRef<str> + Send,
audio_format: &'life1 AudioFormat,
config: &'life2 UtteranceConfig
) -> Pin<Box<dyn Future<Output = Result<Self::EventStream>> + Send + 'async_trait>>
where Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait;
}Expand description
Common trait for a speech synthesiser.
Required Associated Types§
Required Methods§
sourcefn negotiate_audio_format(
&self,
pref: AudioFormatPreference
) -> Option<AudioFormat>
fn negotiate_audio_format( &self, pref: AudioFormatPreference ) -> Option<AudioFormat>
Negotiate an audio format supported by both the application and this synthesiser. The synthesiser returns None
if:
- Any requested sample rate is not supported.
- Any requested container is not supported.
- Any requested channel count is not supported.
If multiple values are provided for a preference by the application, the synthesiser should prioritise the highest quality configuration. For optional properties (such as bitrate), this should not fail, and instead return the highest quality bitrate closest to the user’s preference.
i.e., for a synthesiser that only supports 44100 Hz, stereo MP3 at either 128 or 192 Kbps:
- requesting a sample rate of
48000or22050should returnNone, - requesting
AudioChannels::Monoshould returnNone, - requesting OGG format should return
None, - and requesting 44100 Hz stereo MP3 at 160 Kbps should return an audio format of 44100 Hz stereo MP3 at 192 Kbps.
sourcefn synthesise_ssml_stream<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
input: Speak,
audio_format: &'life1 AudioFormat,
config: &'life2 UtteranceConfig
) -> Pin<Box<dyn Future<Output = Result<Self::EventStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn synthesise_ssml_stream<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, input: Speak, audio_format: &'life1 AudioFormat, config: &'life2 UtteranceConfig ) -> Pin<Box<dyn Future<Output = Result<Self::EventStream>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,
Stream the synthesis of an ssml document.
Audio will be streamed in chunks, in the format specified by the given AudioFormat. You can negotiate an
audio format that both your application and the synthesiser supports via
SpeechSynthesiser::negotiate_audio_format.
You’ll need to configure whether to receive events like visemes or boundaries with an UtteranceConfig.
sourcefn synthesise_text_stream<'life0, 'life1, 'life2, 'async_trait>(
&'life0 self,
input: impl 'async_trait + AsRef<str> + Send,
audio_format: &'life1 AudioFormat,
config: &'life2 UtteranceConfig
) -> Pin<Box<dyn Future<Output = Result<Self::EventStream>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
fn synthesise_text_stream<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, input: impl 'async_trait + AsRef<str> + Send, audio_format: &'life1 AudioFormat, config: &'life2 UtteranceConfig ) -> Pin<Box<dyn Future<Output = Result<Self::EventStream>> + Send + 'async_trait>>where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,
Stream the synthesis of raw text.
Note that text is hardly controllable. For more advanced control of the synthesised speech, including prosody,
pitch contour, or pronunciation of words, see SpeechSynthesiser::synthesise_ssml_stream and ssml.
This method should not be able to accept a raw string of SSML. SSML should be handled exclusively through
SpeechSynthesiser::synthesise_ssml_stream.
Audio will be streamed in chunks, in the format specified by the given AudioFormat. You can negotiate an
audio format that both your application and the synthesiser supports via
SpeechSynthesiser::negotiate_audio_format.
You’ll need to configure whether to receive events like visemes or boundaries with an UtteranceConfig.