Inserting Breaks in Speech

When you listen to music, you’ll notice that the instruments and voices are not constantly producing tones. There are short pauses between most notes and longer breaks every so often. In musical notation, those longer breaks when the instrument makes no sound are called rests. Rests are just as important in music as the times when the instruments are playing notes because they help establish the proper rhythm of the song.

When we speak, we place rests or brief pauses between words, phrases, and sentences. The breaks in speech help the listener understand what we’re saying better, help establish mood or add a dramatic flair, or at very least keep us all from sounding like auctioneers.

Written word has similar pauses inferred by spaces and punctuation. A single space helps break words apart, commas add a brief pause between phrases, and periods add a longer pause between sentences. When we need an even more significant break in thought, a new paragraph—perhaps separated by a blank line—breaks the previous thought from the next thought.

In SSML, Alexa honors many of the punctuational pauses we use in written form and automatically interprets them as spoken pauses when she speaks. For example, consider the following SSML:

 <speak>
  Welcome to Star Port 75 Travel, your out of this world travel agent.
  We specialize in travel to all points in the Earth's solar system.
 
  Where would you like to go?
 </speak>

When Alexa speaks the text in that SSML document, she will put a brief pause between “Travel” and “your” and a longer pause between “agent” and “We”. And, because there’s a blank line between “system” and “Where”, she’ll pause even longer. In other words, she will speak those two sentences in much the same way that you might hear it in your head when you read it for yourself.

While Alexa honors punctuational pauses, you might want more explicit control over those breaks in speech. SSML offers three elements to help with that. The <s> element can be used around one or more words to identify the text as a sentence. And the <p> element is used much the same was to identify a chunk of text as a paragraph. Using these two elements, we can rewrite the SSML from before like this:

 <speak>
  <p>
  <s>Welcome to Star Port 75 Travel, your source for out-of-this-world
  adventures</s>
  <s>We specialize in travel to all points in the Earth's solar system</s>
  </p>
  <p><s>Where would you like to go?</s></p>
 </speak>

In most cases, it’s easier to use punctuation and whitespace to identify breaks for paragraphs and sentences. But as we’ll see later, inserting line breaks can be tricky in JavaScript and impossible when SSML is written in a YAML file such as a skill’s interaction model. In those cases, the <p> and <s> tags are much easier to use.

You can also use the <break> element for more control over the length of the pause. For example, let’s suppose you need a longer break than what <p> or <s> offer. Using the <break> tag, you can define a break several seconds long:

 <speak>
  I'll give you a moment to decide.
  <break time=​"10s"​/>
  What is your decision?
 </speak>

In this example, Alexa will pause for 10 seconds after the first sentence before continuing to the next sentence. Notice that the value is qualified in units of seconds with “s”. Although it’s unusual to need finer-grained control, you may also choose to use “ms” to define the break’s length in milliseconds:

 <break time=​"10000ms"​/>

The time attribute also accepts a handful of predefined values, including “none”, “x-weak”, “weak”, “medium”, “strong”, and “x-strong”. Both “none” and “x-weak” create no break whatsoever. Both “weak” and “medium” insert a break equivalent to the break created by a comma. Giving time a value of “strong” inserts a break that is the same as using a period or <s>. And “x-strong” is the equivalent of <p>.

We’ve seen several ways to alter how Alexa speaks. Now let’s have a look at how SSML can be used to add sound effects and music.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset