Vocalware API Reference
Vocalware API Reference
Table of Contents
INTRODUCTION............................................................................................................. 2 SELECT THE API FLAVOR TO USE .......................................................................... 2 THE JAVASCRIPT & ACTIONSCRIPT APIS............................................................ 3 INTRODUCTION ................................................................................................................ 3 USING YOUR EMBED CODE .............................................................................................. 3 JavaScript Instructions ............................................................................................... 4 ActionScript 3 Instructions ......................................................................................... 4 ActionScript 2 Instructions ......................................................................................... 4 PLAYBACK CONTROL FUNCTIONS .................................................................................... 5 sayText (txt,voice,lang,engine,[effect], [effLevel])..................................................... 5 loadText(txt,voice,lang,engine,[effect], [effLevel]) .................................................... 6 setPlayerVolume (level) .............................................................................................. 7 stopSpeech ()............................................................................................................... 8 freezeToggle () ............................................................................................................ 8 setStatus (interruptMode,progressInterval,reserved1,reserved2) .............................. 8 STATUS CALLBACK FUNCTIONS ....................................................................................... 9 Embedding in an HTML page: ................................................................................... 9 Embedding in a Flash movie: ..................................................................................... 9 vw_apiLoaded (apiID) .............................................................................................. 10 vw_ttsLoaded (text)................................................................................................... 10 vw_audioProgress (percentPlayed).......................................................................... 11 vw_talkStarted ()....................................................................................................... 11 vw_talkEnded () ........................................................................................................ 12 vw_audioStarted ().................................................................................................... 12 vw_audioEnded () ..................................................................................................... 12 THE HTTP REST API................................................................................................... 14 THE HTTP GEN REQUEST ............................................................................................ 14 SESSION VERIFICATION .................................................................................................. 15 EXAMPLE ....................................................................................................................... 16 GENERATING THE CHECKSUM........................................................................................ 16 Checksum Generation PHP Code Example.............................................................. 16 APPENDIX: LANGUAGES AND VOICES ................................................................ 18
Introduction
The Vocalware API enables you to use our cloud based Text-To-Speech service, to generate & play audio in real-time within your online application. By the term online application we refer to any online program, including: web pages, Flash widget, or native code apps on either desktop or mobile device. The only requirement is that your online application has an internet connection fast enough to sustain audio playback. The Vocalware API allows you to generate audio and control audio playback. The API comes in three flavors: JavaScript, ActionScript (Flash) and HTTP-REST - so it can be easily incorporated into your application. Whether your application runs in-browser or standalone, on mobile, desktop or server - one of our API flavors will work for you. The Vocalware API supports TTS in over 20 languages, with several voices available in most. The API allows you to specify the language and voice to use, as well as optional audio effects such as pitch, echo, etc. For a complete list of languages & voices see Appendix.
The embed code is a code segment unique to your account, or more specifically to an API Object within your account. Instructions and examples below explain how to incorporate the embed code.
JavaScript Instructions
Paste your embed code into your HTML pages BODY section. The exact location within your HTML is not significant, though it is best not to include it within FORM brackets or other nested HTML structures. Use the Javascript API functions defined below.
ActionScript 3 Instructions
1. Run Adobe Flash CS3 or higher. 2. Click Layer 1 3. If you do not see the Actions > Frame window label in the middle left of the screen, click Actions. 4. Add the following block of code into the Actions Frame window.
Security.allowDomain("content.oddcast.com"); var ldr:Loader; var req:URLRequest; var vw_player:MovieClip; var _example_ui:MovieClip; req = new URLRequest("EMBED_CODE"); ldr = new Loader(); ldr.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHan dler); ldr.load(req); addChild(ldr); function completeHandler($ev:Event):void { trace("EXAMPLE --- COMPLETE HANDLER "+$ev.target); vw_player = MovieClip(ldr.content); }
5. Copy your embed code and Paste where you see EMBED_CODE above. Note: In the HTML file make sure that allowScriptAccess' is set to 'always'. 6. Declare event listeners in the completeHandler function if call back functions will be used, for example:
vw_player.addEventListener(vw_apiLoaded, vw_apiLoaded);
ActionScript 2 Instructions
1. Run Adobe Flash MX or higher.
2012 Oddcast Inc. 4 Revision 1.0 9/1/2012
2. From the top level menu, choose Insert->New Symbol->Ok 3. Click on Scene 1 4. The Scene window appears as a blank white rectangle in the center of the Adobe Flash screen. 5. Drag Symbol 1 from the Library window to the upper left corner of the Scene window. Replace with instance_name. 6. Click Layer 1 7. If you do not see the Actions > Frame window label in the middle left of the screen, click Actions. 8. Copy your embed code and Paste into the Actions Frame window. 9. The line below should appear in the Actions for the first Frame of the first Scene of your movie:
System.security.allowDomain("vhost.oddcast.com", "vhssa.oddcast.com", "vhss-c.oddcast.com", "vhss-d.oddcast.com");
10. The line below should appear in the Actions for the Scene. Replace instance_name with the name of the instance name you entered for the symbol you inserted, and replace EMBED_CODE with your embed code. instance_name.loadMovie("EMBED_CODE"); 11. Declare all callback functions that you wish to use, for example:
function vw_apiLoaded(){ //any commands that should be triggered here; }
voice
Required. Integer Language ID, as listed in Appendix. Required. Integer Voice Family ID. See languages and voices listed listed in Appendix. effect Optional. Character. Audio effect one of: D Duration levels: -3, -2, -1, 1, 2, 3 P Pitch levels: -3, -2, -1, 1, 2, 3 S Speed levels: -3, -2, -1, 1, 2, 3 R Robotic: o Bullhorn level: 3 (note: levels 1 and 2 are deprecated) T Time: o Echo level: 1 o Reverb level: 2 o Flanger level: 3 o Phase level: 4 W Whisper levels: 1, 2, 3 effLevel Optional. Integer. Effect level must be provided if effect is provided. lang engine Examples: sayText(Hello World,1,1,1) sayText(Hello World,1,1,1,S,-2)
loadText(txt,voice,lang,engine,[effect], [effLevel])
Preload a specific Text To Speech audio. Calling loadText in advance can reduce the loading time when the audio is played. Calling loadText a second time, while audio is loading or after audio has been loaded has no effect. Implement the vw_ttsLoaded() event callback to be notified when the audio track is done loading. Use the sayText() function to play the audio. Note: using loadText may be unnecessary. Use it only if your application requires split second timing coordination when starting audio playback.
Arguments: txt Required. String - The text to speak. Most languages are limited to 900 characters. The exceptions are: Chinese & Japanese which are limited to 225 characters. A longer text string will be truncated. Required. Integer Voice ID, as listed in Appendix.
6 Revision 1.0 9/1/2012
voice
2012 Oddcast Inc.
Required. Integer Language ID, as listed in Appendix Required. Integer Voice Family ID. See languages and voices listed listed in Appendix. effect Optional. Character. Audio effect one of: D Duration levels: -3, -2, -1, 1, 2, 3 P Pitch levels: -3, -2, -1, 1, 2, 3 S Speed levels: -3, -2, -1, 1, 2, 3 R Robotic: o Bullhorn level: 3 (note: levels 1 and 2 are deprecated) T Time: o Echo level: 1 o Reverb level: 2 o Flanger level: 3 o Phase level: 4 W Whisper levels: 1, 2, 3 effLevel Optional. Integer. Effect level must be provided if effect is provided. lang engine Example:
loadText(Hello World,1,1,1) loadText(Hello World,1,1,1,D,3)
setPlayerVolume (level)
Set playback volume, or mute the audio. Arguments: level Required. Integer (0-10) Default = 7. a value from 0 to 10; 0 is equivalent to mute, 1 is softest, 10 is loudest.
Example: setPlayerVolume(10) Note: Setting the volume to 0, does not stop playback or the audio stream. It affects only the volume . To stop playback, use the function stopSpeech().
stopSpeech ()
Stop audio playback in progress. If audio is not currently playing, stopSpeech has no effect (i.e. it does not prevent speech that has not yet begun). Arguments: None. Example: stopSpeech()
freezeToggle ()
Toggle between the pause and play states. If playback is in progress, it is paused. If playback is paused, it is resumed from the point it was paused. Arguments: None. Example: freezeToggle()
setStatus (interruptMode,progressInterval,reserved1,reserved2)
Set several status values which govern various aspects of playback. Arguments: interruptMode Required. Integer (0/1) Default = 0. If set to 0 consecutive audio playback function calls (sayText) are queued for consecutive playback. If set to 1 current audio is interrupted when sayText is called. progressInterval Required. Non-negative Integer Default = 0. The audio progress interval value controls progress callbacks which take place during playback. The callback function vw_audioProgress(percent_played)
is called during playback if the value of progressInterval is non-zero. The non-zero value determines the frequency of the call. The value must be an integer greater than or equal to 0. When greater than 0, the callback "vw_audioProgress(percent_played)" is triggered at the frequency specified by the number (in seconds). The callback returns the percent of the current audio that has played. Callbacks will continue for all subsequent audios played once this field is set. Set back to 0 for the callbacks to cease. reserved1 Required. Integer. Set to 0. reserved2 Required. Integer. Set to 0. Example: setStatus(1,0,0,0)
functions within your movie at the _parent level. Note that you do not need to add callback functions which you do not intend to use.
ActionScript 3
To receive the status callbacks you need to register an event listener for each callback function. Heres an example of loading the content and registering as a listener for the vw_talkStarted event:
loader:Loader = new Loader(); loader.loaderContentInfo.addEventListener(Event.COMPLETE, setListeners); loader.load( /* your AS3 embed code here */ ); function setListeners():void { MovieClip(loader.content).addEventListener(vw_talkStarted,talkS tartedHandler); function talkStartedHandler():void{ trace(talk started); } }
vw_apiLoaded (apiID)
Triggered when the API is fully loaded. Use this callback to verify API is ready, prior to making any function calls. Arguments: The id of the api being loaded. Example - JavaScript & ActionScript2
apiID function vw_apiLoaded(apiID){ alert(the API is loaded); }
Example - ActionScript3
MovieClip(loader.content).addEventListener(vw_apiLoaded,ap iLoadedHandler); function apiLoadedHandler(event:*):void{ trace(api loaded. Id=+ event.data); }
vw_ttsLoaded (text)
Triggered when a Text-To-Speech audio preload is complete; returns the text that was provided as input to loadText. This callback is only triggered if loadText is called.
10
Example - ActionScript3
MovieClip(loader.content).addEventListener(vw_ttsLoaded,ttsLoadedHandle r); function ttsLoadedHandler(event:*):void{ trace(text to speak: + event.data); }
vw_audioProgress (percentPlayed)
Called during playback, if and only if the progressInterval status is set. vw_audioProgress is repeatedly called at regular intervals during playback. The intervals are determined according to the value of the progressInterval status. See setStatus API call for information about how to set this value. This callback can be used to enable synchronization between playback and other events taking place at the same time. For example: highliting text segments, or visual elements on the page in coordination with speech playback. Arguments A value between 0 and 100 which indicated the proportion of audio already played. Example - JavaScript & ActionScript2
percentPlayed function vw_audioProgress(percentPlayed) { }
Example - ActionScript3
MovieClip(loader.content).addEventListener(vw_audioProgress,audi oProgHandler); function audioProgHandler(event:*):void{ trace(percent played: + event.data.percent); }
vw_talkStarted ()
Triggered when the audio playback begins. Example - JavaScript & ActionScript2
function vw_talkStarted(){ }
Example - ActionScript3
11
vw_talkEnded ()
Triggered when audio playback is done. Example - JavaScript & ActionScript2
function vw_talkEnded(){ }
Example - ActionScript3
MovieClip(loader.content).addEventListener(vw_talkEnded,talkEnde dHandler); function talkEndedHandler ():void{ trace(talk ended); }
vw_audioStarted ()
Triggered when audio playback begins. Unlike vw_talkStarted() this event is fired for each audio playback in a sequence. In ActionScript3, the event contains a data property which provides direct references to the Sound object (event.data.sound) and the SoundChannel (event.data.sound_channel) to allow advanced control for as3 developers. Example - JavaScript & ActionScript2
function vw_audioStarted(){ }
Example - ActionScript3
MovieClip(loader.content).addEventListener(vw_audioStarted,audio StartedHandler); function audioStartedHandler(event:*):void{ var sound:Sound = event.data.sound; var sound_channel:SoundChannel = event.data.sound_channel; trace(audio started); }
vw_audioEnded ()
12
Triggered when audio playback ends. Unlike talkEnded() this event is fired for each audio playback in a sequence. Example - JavaScript & ActionScript2
function vw_audioEnded(){ }
Example - ActionScript3
MovieClip(loader.content).addEventListener(vw_audioEnded,audEnde dHandler); function audEndedHandler ():void{ trace(audio ended); }
13
CS = md5 (EID + LID + VID + TXT + IS_UTF8 + EXT + FX_TYPE + FX_LEVEL + ACC + SESSION + SECRET PHRASE) Return values: In case of success, mp3 or swf binary stream is returned. In case of failure one of the following error codes is returned. Error Code 100 101 102 103 Message No data found in request. Missing Required Parameter Missing Required Parameter Missing Required Parameter Reason Missing all request parameters. Missing EID Missing LID Missing VID
14
104 105 106 107 201 202 203 204 205 300 301 302 400
Missing Required Parameter Missing Required Parameter Missing Required Parameter Missing Required Parameter Unknown account id Invalid session Invalid checksum Authorization failure Inactive account. General error Too many TTS Requests TTS Failed APS Failed
Missing TXT Missing ACC Missing SESSION Missing CS ACC failed the verification lookup SESION failed the verification lookup Checksum failure Verification lookup failed (General) Inactive account. General error Too many TTS Requests TTS Failed APS Failed
Session Verification
Session verification is an optional feature designed to protect your account. Heres how it works: When your application makes an HTTP GEN request, and if the checksum proves to be authentic, we make a return call to a predefined URL on your servers (the callback URL). You specify the callback URL for us to use, as part of your Vocalware account security settings. The call is an HTTP POST request, with two parameters your account ID and the session ID you provided in the GEN request. When we call you you may authorize the session, or refuse it. If the callback URL for the account is not setup, or if the Session parameter is not provided, then no callback attempt is made. If the callback URL for the account is not setup, checksum is calculated without the Session parameter even if present. We cache your responses. Subsequent GEN calls that provide the same session ID do not always generate a callback. Why use session verification? If your GEN requests originate from your server, there is no need to setup session verification. But if you are making GEN requests from a client application (i.e. a web page) then session verification is highly advisable to secure your account.
Verification Syntax:
15
POST request to account callback url. Parameter ACC SESSION Return Values 1 0 Description Account id Provided session id Description SESSION is valid Error invalid session
Example
Following sample page can serve as a test/review environment http://www.vocalware.com/support/examples/ttsgen.php
16
$ext = isset($_POST['EXT']) && in_array(trim(strtolower($_POST['EXT'])), array('mp3','swf')) ? trim(strtolower($_POST['EXT'])) : ''; $fxType = isset($_POST['FX_TYPE']) && strlen($_POST['FX_TYPE']) > 0 ? $_POST['FX_TYPE'] : ''; $fxLevel= isset($_POST['FX_LEVEL']) && strlen($_POST['FX_LEVEL']) > 0 ? $_POST['FX_LEVEL'] : ''; //Construct parameters. $get = 'EID='.$_POST['EID'] .'&LID='.$_POST['LID'] .'&VID='.$_POST['VID'] .'&TXT='.urlencode($_POST['TXT']) .'&IS_UTF8='.$isUTF8 .'&EXT='.$ext .'&FX_TYPE='.$fxType .'&FX_LEVEL='.$fxLevel .'&ACC='.$_POST['ACC'] .'&SESSION='.$_POST['SESSION']; //Construct checksum $CS = md5($_POST['EID'].$_POST['LID'].$_POST['VID'].$_POST['TXT'].$isUTF8.$ext.$fxT ype.$fxLevel.$_POST['ACC'].$_POST['SESSION'].$_POST['SECRET']); //Construct full URL $url = 'http://cache.oddcast.com/tts/gen.php?' . $get . '&CS=' . $CS;
NOTE: The following special characters are stripped if included in the text: "^", "~", "`", "@", "#", "$", "%", "&", "(", ")", "<", ">", "{", "}", "[", "]", "|", "\\", "/", "_", "+", "="
17
Language
ID
Arabic Catalan Chinese Danish Dutch English Esperanto Finnish French Galician German Greek Italian Japanese Korean Norwegian Polish Portuguese Romanian Russian Spanish Swedish Turkish
27 5 10 19 11 1 31 23 4 15 3 8 7 12 13 20 14 6 30 21 2 9 16
18
Engine ID = 2 Language English English English English English English English English English English Spanish Spanish Spanish Spanish Spanish Spanish Spanish Spanish Spanish Spanish German German French French French French French Catalan Catalan Catalan Portuguese Portuguese Portuguese Portuguese Portuguese Italian Italian Italian Italian Italian Italian Italian Lang. ID 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3 4 4 4 4 4 5 5 5 6 6 6 6 6 7 7 7 7 7 7 7 Voice Name Susan Dave Elizabeth Simon Catherine Allison Steven Alan Grace Veena Carmen Juan Francisca Diego Esperanza Jorge Carlos Soledad Leonor Ximena Stefan Katrin Bernard Jolie Florence Charlotte Olivier Montserrat Jordi Empar Gabriela Amalia Eusebio Fernanda Felipe Paola Silvana Valentina Luca Marcello Roberto Matteo Voice ID 1 2 4 5 6 7 8 9 10 11 1 2 3 4 5 6 7 8 9 10 2 3 2 3 4 5 6 1 2 3 1 2 3 4 5 1 2 3 5 6 7 8 Gende r F M F M F F M M F F F M F M F M M F F F M F M F F F M F M F F F M F M F F F M M M M Description Expressive Cues* US US UK UK UK US US Australian Australian Indian Castilian Castilian Chilean Argentine Mexican Castilian American American Castilian American European European European Canadian Canadian Valencian Brasilian European European Brazilian Brazilian
19
7 Giulia 9 F Italian 7 Federica 10 F Italian 8 Afroditi 1 F Greek 8 Nikos 3 M Greek 9 Annika 1 F Swedish 9 Sven 2 M Swedish 10 Linlin 1 F Mandarin Chinese 10 Lisheng 2 F Mandarin Chinese 11 Willem 1 M Dutch 11 Saskia 2 F Dutch 14 Zosia 1 F Polish 14 Krzysztof 2 M Polish 15 Carmela 1 F Galician 16 Kerem 1 M Turkish 16 Zeynep 2 F Turkish 16 Selin 3 F Turkish 19 Frida 1 F Danish 19 Magnus 2 M Danish Vilde 1 F Norwegian 20 Henrik 2 M Norwegian 20 21 Olga 1 F Russian 21 Dmitri 2 M Russian 23 Milla 1 F Finnish 23 Marko 2 M Finnish 27 Tarik 1 M Arabic 27 Laila 2 F Arabic Ioana 1 F Romanian 30 31 Ludoviko 1 M Esperanto * Expressive Cues are a set of special tags which you may use in your text to specify distinct non-verbal expressions, such as laughing, crying, sighing, coughing, etc. Expressive Cues can be used only with a subset of voices, as indicated above. For a complete list of Expressive Cue tags see separate documentation.
Engine ID = 3 Language English English English English Spanish Chinese Chinese Lang. ID 1 1 1 1 2 10 10 Voice Name Kate Paul Julie Bridget Violeta Lily Hui Voice ID 1 2 3 4 1 1 3 Gender Description F M F F F F F US US US UK Mandarin Mandarin
20
10 12 12 13 13
4 2 3 1 2
M M F F M
Mandarin
21