meSpeak.js (( • ))

Multipart Example

This is an example for mixing multiple parts into a single utterance using meSpeak.speakMultipart().

We will speak the text "Travel to Paris at light speed." using a female French voice for the word "Paris".

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.

Try it:

meSpeak.loadConfig("mespeak_config.json"); meSpeak.loadVoice("voices/en/en-us.json"); meSpeak.loadVoice("voices/fr.json"); var parts = [ { text: "Travel to", voice: "en/en-us", variant: "m3" }, { text: "Paris", voice: "fr", variant: "f5" }, { text: "at light speed", voice: "en/en-us", variant: "m3" } ]; function speakIt() { // called by button meSpeak.speakMultipart(parts); }

We even may provide any options to be applied as defaults to the individual parts.
(You may apply any options valid for meSpeak.speak().)

function speakItWithDefaults() { // called by button meSpeak.speakMultipart(parts, {pitch: 35, speed: 160}); }

Try it:

 

Syntax

The general form of meSpeak.speakMultipart() is analogous to meSpeak.speak(), but with an array of objects (the parts to be spoken) as the first argument (rather than a single text):

meSpeak.speakMultipart( <parts-array> [, <options-object> [, <callback-function> ]] ); meSpeak.speakMultipart( [ { text: "text-1", <other options> ] }, { text: "text-2", <other options> ] }, ... { text: "text-n", <other options> ] }, ], { option1: value1, option2: value2 .. }, callback );

Only the the first argument is mandatory, any further arguments are optional.
The parts-array must contain a single element (of type object) at least.
For any other options refer to meSpeak.speak().
The method returns — like meSpeak.speak() — either an ID, or, if called with the "rawdata" option (in the general options / second argument), a stream-buffer representing the generated wav-file.

 

N. Landsteiner, 2014