4 <meta charset=
"utf-8" />
5 <title>meSpeak.js
— Multipart Example
</title>
6 <link href=
"http://fonts.googleapis.com/css?family=Open+Sans&subset=latin" rel=
"stylesheet" type=
"text/css" />
7 <link href=
"http://fonts.googleapis.com/css?family=Lato:300&subset=latin" rel=
"stylesheet" type=
"text/css" />
9 <script type=
"text/javascript" src=
"mespeak.js"></script>
11 <script type=
"text/javascript">
13 meSpeak
.loadConfig("mespeak_config.json");
14 meSpeak
.loadVoice("voices/en/en-us.json");
15 meSpeak
.loadVoice("voices/fr.json");
19 { text
: "Travel to", voice
: "en/en-us", variant
: "m3" },
20 { text
: "Paris", voice
: "fr", variant
: "f5" },
21 { text
: "at light speed", voice
: "en/en-us", variant
: "m3" }
26 meSpeak
.speakMultipart(parts
);
29 function speakItWithDefaults() {
31 meSpeak
.speakMultipart(parts
, {pitch
: 35, speed
: 160});
35 <style type=
"text/css">
39 padding: 2em 1.5em 4.5em 1.5em;
40 background-color: #e2e3e4;
45 padding: 2px 40px 60px 40px;
46 margin: 0 auto
0 auto
;
47 background-color: #fafafb;
49 font-family: 'Open Sans',sans-serif
;
55 font-family: 'Lato',sans-serif
;
80 h1 span
.pict
{ font-size: 38px; color: #ccc; margin-left: 0.5em; letter-spacing: -2px; }
89 padding: 1em 0 1em 2em;
91 font-family: monospace
;
93 background-color: #f2f3f5;
96 p
.codesample strong
{ color: #222; }
98 a:hover
,a:focus
{ color: #2681a7; }
99 a:active
{ color: #cd360e; }
100 p
.action
{ margin: 1em 0 1em 1.5em; }
105 <h1>meSpeak.js
<span class=
"pict">((
• ))
</span></h1>
106 <h2>Multipart Example
</h2>
108 <p>This is an example for mixing multiple parts into a single utterance using
<tt>meSpeak.speakMultipart()
</tt>.
</p>
110 <p>We will speak the text
<em>"Travel to Paris at light speed.
"</em> using a female French voice for the word
"Paris
".
</p>
111 <p>For this, we break up the sentence in multiple parts, each part representing a continous text to be spoken by a voice. Each part is an object, containing the text to be spoken and any options to be applied.
</p>
113 <p class=
"action">Try it:
<button onclick=
"speakIt();">Speak It
</button></p>
115 <p class=
"codesample">
116 meSpeak.loadConfig(
"mespeak_config.json
");
117 meSpeak.loadVoice(
"voices/en/en-us.json
");
118 meSpeak.loadVoice(
"voices/fr.json
");
122 { text:
"Travel to
", voice:
"en/en-us
", variant:
"m3
" },
123 { text:
"Paris
", voice:
"fr
", variant:
"f5
" },
124 { text:
"at light speed
", voice:
"en/en-us
", variant:
"m3
" }
129 meSpeak.speakMultipart(parts);
133 <p>We even may provide any options to be applied as defaults to the individual parts.
<br />
134 (You may apply any options valid for
<tt>meSpeak.speak()
</tt>.)
</p>
136 <p class=
"codesample">
137 function speakItWithDefaults() {
139 meSpeak.speakMultipart(parts, {pitch:
35, speed:
160});
142 <p class=
"action">Try it:
<button onclick=
"speakItWithDefaults();">Speak It
</button></p>
146 <p>The general form of
<tt>meSpeak.speakMultipart()
</tt> is analogous to
<tt>meSpeak.speak()
</tt>, but with an array of objects (the parts to be spoken) as the first argument (rather than a single text):
</p>
148 <p class=
"codesample">
149 <strong>meSpeak.speakMultipart(
</strong> <parts-array
> [,
<options-object
> [,
<callback-function
> ]]
<strong>)
</strong>;
151 <strong>meSpeak.speakMultipart(
</strong>
153 { text:
"text-
1",
<other options
> ] },
154 { text:
"text-
2",
<other options
> ] },
156 { text:
"text-n
",
<other options
> ] },
158 { option1: value1, option2: value2 .. },
162 <p>Only the the first argument is mandatory, any further arguments are optional.
<br />
163 The
<em>parts-array
</em> must contain a single element (of type object) at least.
<br />
164 For any other options refer to
<tt>meSpeak.speak()
</tt>.
<br />
165 The method returns
— like
<tt>meSpeak.speak()
</tt> — either an ID, or, if called with the
<tt>"rawdata
"</tt> option (in the general options / second argument), a stream-buffer representing the generated wav-file.
</p>
169 <p>N. Landsteiner,
2014</p>