pub struct XmlWriter {
    pub writer: Writer<Cursor<Vec<u8>>>,
}
Expand description

An XML Writer. Used for manual manipulation of the SSML Output (which uses XML).

You should probably never use this directly, instead interacting with the parser, however if you’d like to build your own parser, and just reuse the XML Rendering then you’d want to use this.

Fields

writer: Writer<Cursor<Vec<u8>>>

The XML Writer instance. The thing that actually writes the XML.

Implementations

Creates a new XML Writer. This writerr writes into a std::vec::Vec, and at any point can be turned into a string. It is your job to close all tags before rendering this. We don’t close everything when you render it. You render what you put in.

It should also note we automatically write the header:

<?xml version="1.0"?>

Upon creation of an XML Writer. This is to try, and keep as close to the W3C docs for SSML v1.1. Which you can read about HERE.

Examples
use text_to_polly_ssml::xml_writer::XmlWriter;
let result = XmlWriter::new();
assert!(result.is_ok());

Starts an SSML tag. For AWS Polly this is the root tag, and should only have one decleration as mentioned in their docs (As of April 20th, 2017):

The <speak> tag is the root element of all Amazon Polly SSML text.
All SSML-enhanced text to be spoken must be included within this tag.

It should be noted although AWS Docs do not mention any attributes you can pass in to the tag, we still have an optional lang, and onlangfailure attributes to closely mirror the W3C Standard, as seen: HERE.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let start_speak_result = new_xml_writer.unwrap().start_ssml_speak(None, None);
assert!(start_speak_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
<speak xml:lang="en-US" onlangfailure="processorchoice"
   xmlns="http://www.w3.org/2001/10/synthesis"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

Ends an SSML tag. For AWS Polly this should be the root tag, and you should only close it when you are done.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let end_speak_result = new_xml_writer.unwrap().end_ssml_speak();
assert!(end_speak_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
</speak>

Creates an SSML tag. AWS Polly follows the W3C SSMLv1.1 standard for this tag.

You can find the SSML tag documented in the W3C’s guide: HERE. Although you can find the specific implementation details on AWS’s site: HERE.

According to the W3C 1.1 Standard both the strength, and time are optional. Though both can be used in combination.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let mut xml_writer = new_xml_writer.unwrap();
let result = xml_writer.ssml_break(None, None);
assert!(result.is_ok());

Generated SSML:

<?xml version="1.0"?>
<break />

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
use text_to_polly_ssml::ssml_constants::{BreakStrength, BreakTime};
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let mut xml_writer = new_xml_writer.unwrap();
let result = xml_writer.ssml_break(Some(BreakStrength::XStrong), Some(BreakTime::new(10, true)));
assert!(result.is_ok());

Generated SSML:

<?xml version="1.0"?>
<break strength="x-strong" time="10s" />

Starts an SSML Lang tag. The Lang tag is useful for telling say someone speaking in english that they’re about to speak a french word. You can keep the overall text english, but have a mix of french words in there. Although AWS polly only documents support the xml:lang attribute, we also pass in onlangfailure which is documented inside the W3C SSML 1.1 standard which can be found: HERE.

You can find the AWS Documentation that mentions the lang tag: HERE.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let start_lang_result = new_xml_writer.unwrap().start_ssml_lang("fr-FR".to_owned(), None);
assert!(start_lang_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
<lang xml:lang="fr-FR" onlangfailure="processorchoice">

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let start_lang_result = new_xml_writer.unwrap().start_ssml_lang("fr-FR".to_owned(),
  Some("changevoice".to_owned()));
assert!(start_lang_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
<lang xml:lang="fr-FR" onlangfailure="changevoice">

Ends an SSML tag.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let end_lang_result = new_xml_writer.unwrap().end_ssml_lang();
assert!(end_lang_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
</lang>

Starts an SSML Mark tag. Although this will make no difference in the voice of the text, this will place a marker inside the SSML Metadata returned from Polly. This can be useful if you want to perform some sort of actions on certain words. AWS Polly follows the W3C SSML v1.1 Spec here, and documentation can be found: HERE.

You can find the AWS Documentation that mentions the mark tag: HERE.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let start_mark_result = new_xml_writer.unwrap().start_ssml_mark("animal".to_owned());
assert!(start_mark_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
Mmark name="animal">

Ends an SSML tag.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let end_mark_result = new_xml_writer.unwrap().end_ssml_mark();
assert!(end_mark_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
</mark>

Starts an SSML Paragraph Tag. The Paragraph Tag is useful for breaking up multiple paragraphs of text. AWS Polly follows the W3C SSML v1.1 Standard Here. As such the documentation for the paragraph tag can be found: HERE.

You can find the AWS Documentation that mentions the paragraph tag: HERE.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let start_p_result = new_xml_writer.unwrap().start_ssml_paragraph();
assert!(start_p_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
<p>

Ends an SSML

tag.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let end_p_result = new_xml_writer.unwrap().end_ssml_paragraph();
assert!(end_p_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
</p>

Starts an SSML Phoneme Tag. The Phoneme Tag is useful for custom pronunciation for words. The Phoneme Tag should really only be used on a per word/short phrase basis. You don’t want to use a phoneme tag for an entire paragraph of text. The Phoneme Tag in polly has two required attributes both “ph”, and “alphabet”. Which deviates from the W3C Standard, which says only “ph” is required. However since Polly implements close to perfect the W3C SSML v1.1 Standard here you should still probably read their documentation on the tag: HERE.

You can find the AWS Documentation that mentions the phoneme tag: HERE.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
use text_to_polly_ssml::ssml_constants::PhonemeAlphabet;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let start_phoneme_result = new_xml_writer.unwrap().start_ssml_phoneme(PhonemeAlphabet::Ipa,
 "d͡ʒt͡ʃΘɚoʊɛ".to_owned());
assert!(start_phoneme_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
<phoneme alphabet="ipa" ph="d͡ʒt͡ʃΘɚoʊɛ">

Ends an SSML tag.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let end_phoneme_result = new_xml_writer.unwrap().end_ssml_phoneme();
assert!(end_phoneme_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
</phoneme>

Starts an SSML Prosody Tag. The prosody tag seems to be the one that derives the most from the SSML Specification. Which in some instances is fine because it makes for easier reading (e.g. +20% pitch), but in other places is kind of sad we can’t do that. (e.g. things like duration). As such I’ll only link to the AWS documentation. HERE.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let start_prosody_result = new_xml_writer.unwrap().start_ssml_prosody(Some("+5db".to_owned()), None, None);
assert!(start_prosody_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
<prosody volume="+6db">

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
use text_to_polly_ssml::ssml_constants::ProsodyRate;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let start_prosody_result = new_xml_writer.unwrap()
  .start_ssml_prosody(Some("+6dB".to_owned()), Some(ProsodyRate::XFast),
   Some("+100%".to_owned()));
assert!(start_prosody_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
<prosody volume="+6db" rate="x-fast" pitch="+100%">

Ends an SSML tag.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let end_prosody_result = new_xml_writer.unwrap().end_ssml_prosody();
assert!(end_prosody_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
</prosody>

Starts an SSML Sentence Tag. The Sentence Tag is useful for breaking up multiple sentences of text. AWS Polly follows the W3C SSML v1.1 Standard Here. As such the documentation for the sentence tag can be found: HERE.

You can find the AWS Documentation that mentions the sentence tag: HERE.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let start_s_result = new_xml_writer.unwrap().start_ssml_sentence();
assert!(start_s_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
<s>

Ends an SSML tag.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let end_s_result = new_xml_writer.unwrap().end_ssml_sentence();
assert!(end_s_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
</s>

Starts an SSML say-as Tag. The say-as tag is used for determing how a body of text should be interpreted, for example a phone number, or if you want something spelled out letter by letter. However AWS polly only supports the interpret-as attribute which is required, and does not support the format, and detail attributes. However for posterity you can read the W3C SSML v1.1 Spec: HERE. It should be noted the parameter for interpret-as is kept dynamic, since in the spec it says this list should change rapidly.

You can find the AWS Documentation that mentions the say-as tag: HERE.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let start_say_as_result = new_xml_writer.unwrap().start_ssml_say_as("character".to_owned());
assert!(start_say_as_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
<say-as interpret-as="character">

Ends an SSML tag.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let end_say_as_result = new_xml_writer.unwrap().end_ssml_say_as();
assert!(end_say_as_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
</say-as>

Starts an SSML sub Tag. The sub tag is used for a substitution of a word. For example in elememtal symbols you may want to show the elememtal symbol, but have the engine say the actual element name. AWS polly follows the W3C SSML v1.1 Spec: HERE.

You can find the AWS Documentation that mentions the sub tag: HERE.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let start_sub_result = new_xml_writer.unwrap().start_ssml_sub("mercury".to_owned());
assert!(start_sub_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
<sub alias="mercury">

Ends an SSML tag.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let end_sub_result = new_xml_writer.unwrap().end_ssml_sub();
assert!(end_sub_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
</sub>

Starts an SSML Word/Token tag. The Word/Token tag for AWS Polly also deviates pretty far from the W3C Spec. So here like a few tags who shall not be named I will also only ilnk to the AWS Documentation for this tag. Which can be found: HERE.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
use text_to_polly_ssml::ssml_constants::WordRole;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let start_w_result = new_xml_writer.unwrap().start_ssml_w(WordRole::Verb);
assert!(start_w_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
<w role="amazon:VB">

Ends an SSML tag.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let end_w_result = new_xml_writer.unwrap().end_ssml_w();
assert!(end_w_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
</w>

Starts an SSML amazon effect tag. These tags are unique to AWS Polly. As such the only place they are documented is inside the AWS Docs themsleves which are: HERE.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
use text_to_polly_ssml::ssml_constants::AmazonEffect;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let start_amazon_effect_result = new_xml_writer.unwrap()
  .start_ssml_amazon_effect(AmazonEffect::Whispered);
assert!(start_amazon_effect_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
<amazon:effect name="whispered">

Ends an SSML amazon:effect tag.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let end_amazon_effect_result = new_xml_writer.unwrap().end_ssml_amazon_effect();
assert!(end_amazon_effect_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
</amazon:effect>

Starts an SSML vocal tract tag. These tags are unique to AWS Polly. As such the only place they are documented is inside the AWS Docs themsleves which are: HERE.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let start_amazon_effect_result = new_xml_writer.unwrap()
  .start_ssml_vocal_tract_length("+10%".to_owned());
assert!(start_amazon_effect_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
<amazon:effect vocal-tract-length="+10%">

Starts an SSML phonation tag. These tags are unique to AWS Polly. As such the only place they are documented is inside the AWS Docs themsleves which are: HERE.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
use text_to_polly_ssml::ssml_constants::PhonationVolume;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let start_amazon_phonation_result = new_xml_writer.unwrap()
  .start_ssml_phonation(PhonationVolume::Soft);
assert!(start_amazon_phonation_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
<amazon:effect phonation="soft">

Starts an SSML amazon:auto-breaths tag.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
use text_to_polly_ssml::ssml_constants::*;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let start_amazon_auto_breaths_result = new_xml_writer.unwrap().start_ssml_auto_breaths(
  BreathVolumes::Def,
  AutoBreathFrequency::Def,
  BreathDuration::Def,
);
assert!(start_amazon_auto_breaths_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
<amazon:auto-breaths volume="default" frequency="default" duration="default">

Ends an SSML amazon:auto-breaths tag.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let end_amazon_auto_breaths_result = new_xml_writer.unwrap().end_ssml_amazon_auto_breaths();
assert!(end_amazon_auto_breaths_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
</amazon:auto-breaths>

Starts an SSML amazon:breath tag.

Examples

Rust Code:

use text_to_polly_ssml::xml_writer::XmlWriter;
use text_to_polly_ssml::ssml_constants::*;
let mut new_xml_writer = XmlWriter::new();
assert!(new_xml_writer.is_ok());
let start_amazon_breath_result = new_xml_writer.unwrap().write_amazon_breath(
  BreathVolumes::Def,
  BreathDuration::Def,
);
assert!(start_amazon_breath_result.is_ok());

Generated SSML:

<?xml version="1.0"?>
<amazon:breath volume="default" duration="default" />

Writes some raw text to the XML Document. Should only be used inbetween

tags.

Renders the XML document in it’s current state. This expects the document to be completely valid UTF-8, and will do no closing of tags for you.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.