SpeechSynthesiser

Trait SpeechSynthesiser 

Source
pub trait SpeechSynthesiser {
    type Error: Error + Send + Sync + 'static;

    // Required methods
    fn negotiate_audio_format(
        &self,
        pref: &AudioFormatPreference,
    ) -> Option<AudioFormat>;
    fn synthesise_ssml_stream(
        &self,
        input: &Speak<'_>,
        audio_format: &AudioFormat,
        config: &UtteranceConfig,
    ) -> impl Future<Output = Result<impl UtteranceEventStream<Self::Error> + 'static, Self::Error>> + Send;
    fn synthesise_text_stream(
        &self,
        input: &str,
        audio_format: &AudioFormat,
        config: &UtteranceConfig,
    ) -> impl Future<Output = Result<impl UtteranceEventStream<Self::Error> + 'static, Self::Error>> + Send;
}
Expand description

Common trait for a speech synthesiser.

Required Associated Types§

Source

type Error: Error + Send + Sync + 'static

Required Methods§

Source

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 48000 or 22050 should return None,
  • requesting AudioChannels::Mono should return None,
  • 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.
Source

fn synthesise_ssml_stream( &self, input: &Speak<'_>, audio_format: &AudioFormat, config: &UtteranceConfig, ) -> impl Future<Output = Result<impl UtteranceEventStream<Self::Error> + 'static, Self::Error>> + Send

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.

Source

fn synthesise_text_stream( &self, input: &str, audio_format: &AudioFormat, config: &UtteranceConfig, ) -> impl Future<Output = Result<impl UtteranceEventStream<Self::Error> + 'static, Self::Error>> + Send

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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§