SpeechBuilder

Struct SpeechBuilder 

Source
pub struct SpeechBuilder { /* private fields */ }
Expand description

Helper type that can construct a Speech from a sequence of rendering instructions.

It’s important to understand that the instructions do not override the configuration of the synthesizer, but adjust them instead. For example, if you call set_volume(80) on the synthesizer, and your speech starts with the instruction start_volume(50), the volume at that point will be set to 40 (i.e. 50% of 80%).

NOTE: Although any complex speech is encoded as XML, the builder performs no validation. This is because SAPI itself is very lax when processing speech. For example, SAPI will be perfectly happy to render the following XML:

<emph><volume level="50">Hello</emph>world</volume>

Implementations§

Source§

impl SpeechBuilder

Source

pub fn new() -> Self

Constructs a new, empty instance.

Source

pub fn start_emphasis(&mut self) -> &mut Self

Emphasizes all subsequent speech until the corresponding end_emphasis call.

Source

pub fn start_pitch<P: Into<Pitch>>(&mut self, pitch: P) -> &mut Self

Changes the pitch of all subsequent speech until the corresponding end_pitch call.

Source

pub fn start_rate<R: Into<Rate>>(&mut self, rate: R) -> &mut Self

Changes the rate of all subsequent speech until the corresponding end_rate call.

Source

pub fn start_voice(&mut self, voice: &Voice) -> &mut Self

Switches to the specified voice until the corresponding end_voice call.

Source

pub fn select_and_start_voice( &mut self, required: Option<VoiceSelector>, optional: Option<VoiceSelector>, ) -> &mut Self

Switches to a voice that matches the specified criteria until the corresponding end_voice call. For the explanation of required and optional criteria, see installed_voices.

Source

pub fn start_volume<V: Into<Volume>>(&mut self, volume: V) -> &mut Self

Changes the volume of all subsequent speech until the corresponding end_rate call.

Source

pub fn say<S: AsRef<str>>(&mut self, text: S) -> &mut Self

Appends text to pronounce.

Source

pub fn say_as<S: AsRef<str>>(&mut self, text: S, ctx: SayAs<'_>) -> &mut Self

Appends text to pronounce, along witha hint on how to pronounce it.

Source

pub fn pronounce<S: AsRef<str>>(&mut self, pronunciation: S) -> &mut Self

Appends a specific pronunciation to render. The pronunciation specification depends on the language of the current voice. For example, “m ah dh ax r” in American English is pronounced as “mother”.

Source

pub fn silence(&mut self, duration: Duration) -> &mut Self

Appends a silence with a specified duration. Does not support sub-millisecond precision.

Source

pub fn end_emphasis(&mut self) -> &mut Self

Ends the effect of the corresponding start_emphasis call.

Source

pub fn end_pitch(&mut self) -> &mut Self

Ends the effect of the corresponding start_pitch call.

Source

pub fn end_rate(&mut self) -> &mut Self

Ends the effect of the corresponding start_rate call.

Source

pub fn end_voice(&mut self) -> &mut Self

Ends the effect of the corresponding start_voice or select_and_start_voice call.

Source

pub fn end_volume(&mut self) -> &mut Self

Ends the effect of the corresponding start_volume call.

Source

pub fn build<'s>(&mut self) -> Speech<'s>

Builds the Speech from instructions received so far. Clears the contents of the builder.

Trait Implementations§

Source§

impl<'s> From<&mut SpeechBuilder> for Speech<'s>

Source§

fn from(builder: &mut SpeechBuilder) -> Self

Converts to this type from the input type.
Source§

impl<'s> From<SpeechBuilder> for Speech<'s>

Source§

fn from(builder: SpeechBuilder) -> Self

Converts to this type from the input type.
Source§

impl Write for SpeechBuilder

Source§

fn write_str(&mut self, s: &str) -> Result

Writes a string slice into this writer, returning whether the write succeeded. Read more
1.1.0 · Source§

fn write_char(&mut self, c: char) -> Result<(), Error>

Writes a char into this writer, returning whether the write succeeded. Read more
1.0.0 · Source§

fn write_fmt(&mut self, args: Arguments<'_>) -> Result<(), Error>

Glue for usage of the write! macro with implementors of this trait. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.