Audio

Struct Audio 

Source
pub struct Audio<'s> { /* private fields */ }
Expand description

Audio supports the insertion of recorded audio files and the insertion of other audio formats in conjunction with synthesized speech output.

Implementations§

Source§

impl<'s> Audio<'s>

Source

pub fn new(src: impl Into<Cow<'s, str>>) -> Self

Creates a new Audio element with an audio source URI.

ssml::audio("https://example.com/Congratulations_You_Won.wav");
Source

pub fn src(&self) -> &str

Source

pub fn set_src(&mut self, src: impl Into<Cow<'s, str>>)

Source

pub fn with_alternate<S: Into<Element<'s>>, I: IntoIterator<Item = S>>( self, elements: I, ) -> Self

Appends alternate (fallback) elements. Alternate elements will be spoken or displayed if the audio document located at the specified URI is unavailable for whatever reason.

See also Audio::with_desc to provide an accessible description for this audio element.

ssml::audio("cat_purr.ogg").with_alternate(["PURR (sound didn't load)"]);
Source

pub fn with_desc(self, desc: impl Into<Cow<'s, str>>) -> Self

Sets an accessible description for this audio element.

ssml::audio("cat_purr.ogg").with_desc("a purring cat");
Source

pub fn desc(&self) -> Option<&str>

Source

pub fn set_desc(&mut self, desc: impl Into<Cow<'s, str>>)

Source

pub fn take_desc(&mut self) -> Option<Cow<'s, str>>

Source

pub fn with_clip( self, begin: impl Into<TimeDesignation>, end: impl Into<TimeDesignation>, ) -> Self

Specify an offset from the beginning and to the end of which to clip this audio’s duration to.

// Play the sound starting from 0.25s, and stop at 0.75s, for a total duration of 0.5s.
ssml::audio("cat_purr.ogg").with_clip("0.25s", "750ms");
Source

pub fn with_clip_begin(self, begin: impl Into<TimeDesignation>) -> Self

Specify an offset from the beginning of the audio to start playback.

// maybe skip some silence at the beginning
ssml::audio("cat_purr.ogg").with_clip_begin("0.15s");
Source

pub fn clip_begin(&self) -> Option<&TimeDesignation>

Source

pub fn set_clip_begin(&mut self, begin: impl Into<TimeDesignation>)

Source

pub fn take_clip_begin(&mut self) -> Option<TimeDesignation>

Source

pub fn with_clip_end(self, end: impl Into<TimeDesignation>) -> Self

Specify an offset from the beginning of the audio to end playback.

// maybe skip some silence at the end
ssml::audio("cat_purr.ogg").with_clip_begin("0.75s");
Source

pub fn clip_end(&self) -> Option<&TimeDesignation>

Source

pub fn set_clip_end(&mut self, end: impl Into<TimeDesignation>)

Source

pub fn take_clip_end(&mut self) -> Option<TimeDesignation>

Source

pub fn with_repeat(self, repeat: AudioRepeat) -> Self

Repeat this audio source for a set amount of times, or for a set duration. See AudioRepeat.

// Play the beep sound effect 3 times
ssml::audio("beep.ogg").with_repeat(ssml::AudioRepeat::Times(3.0));
// Happy kitty!
ssml::audio("cat_purr.ogg").with_repeat(ssml::AudioRepeat::Duration("30s".into()));
Source

pub fn repeat(&self) -> Option<&AudioRepeat>

Source

pub fn set_repeat(&mut self, repeat: AudioRepeat)

Source

pub fn take_repeat(&mut self) -> Option<AudioRepeat>

Source

pub fn with_sound_level(self, db: impl Into<Decibels>) -> Self

Specify the relative volume of the referenced audio, in decibels. Setting to a large negative value like -100dB will effectively silence the audio clip. A value of -6.0dB will play the audio at approximately half the volume, and likewise +6.0dB will play the audio at twice the volume.

ssml::audio("cat_meow.ogg").with_sound_level("+6.0dB");
Source

pub fn sound_level(&self) -> Option<&Decibels>

Source

pub fn set_sound_level(&mut self, db: impl Into<Decibels>)

Source

pub fn take_sound_level(&mut self) -> Option<Decibels>

Source

pub fn with_speed(self, speed: f32) -> Self

Specify the speed at which to play the audio clip (where 1.0 is normal speed).

// panic beeping at 2x speed
ssml::audio("beep.ogg").with_repeat(ssml::AudioRepeat::Times(12.0)).with_speed(2.0);
Source

pub fn speed(&self) -> Option<f32>

Source

pub fn set_speed(&mut self, speed: f32)

Source

pub fn take_speed(&mut self) -> Option<f32>

Source

pub fn alternate(&self) -> &[Element<'s>]

Returns a reference to the elements contained in this audio element’s alternate/fallback section.

Source

pub fn alternate_mut(&mut self) -> &mut Vec<Element<'s>>

Returns a reference to the elements contained in this audio element’s alternate/fallback section.

Source

pub fn to_owned(&self) -> Audio<'static>

Source

pub fn into_owned(self) -> Audio<'static>

Trait Implementations§

Source§

impl<'s> Clone for Audio<'s>

Source§

fn clone(&self) -> Audio<'s>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'s> Debug for Audio<'s>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'s> Default for Audio<'s>

Source§

fn default() -> Audio<'s>

Returns the “default value” for a type. Read more
Source§

impl<'s> From<Audio<'s>> for Element<'s>

Source§

fn from(val: Audio<'s>) -> Element<'s>

Converts to this type from the input type.
Source§

impl<'s> Serialize for Audio<'s>

Source§

fn serialize_xml<W: Write>( &self, writer: &mut XmlWriter<W>, options: &SerializeOptions, ) -> Result<()>

Serialize this SSML element into an XmlWriter.
Source§

fn serialize<W: Write>( &self, writer: &mut W, options: &SerializeOptions, ) -> Result<()>

Serialize this SSML element into an std Writer.
Source§

fn serialize_to_string(&self, options: &SerializeOptions) -> Result<String>

Serialize this SSML element into a string.

Auto Trait Implementations§

§

impl<'s> Freeze for Audio<'s>

§

impl<'s> RefUnwindSafe for Audio<'s>

§

impl<'s> Send for Audio<'s>

§

impl<'s> Sync for Audio<'s>

§

impl<'s> Unpin for Audio<'s>

§

impl<'s> UnwindSafe for Audio<'s>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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<'s, T> IntoElement<'s> for T
where T: Into<Element<'s>>,

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.