rita
Class RiSpeech

java.lang.Object
  extended by rita.RiObject
      extended by rita.RiSpeech
All Implemented Interfaces:
processing.core.PConstants, RiConstants

public class RiSpeech
extends RiObject

Provides basic cross-platform text-to-speech facilities with control over a range of parameters including voice-selection, pitch, speed, rate, etc. When needed, multiple RiSpeech objects can be created, each with their own parameters, for concurrent speech.

Note: requires the installation of one or more FreeTTS compatible voices (see the RiTa+TTS install which includes a default 16-bit voice)...

To receive callbacks when a RiSpeech object has completed speaking a chunk of text, implement the following method in your applet:

   void onRiTaEvent(RiTaEvent re) {
     RiSpeech rs = (RiSpeech)re.getSource();
     String lastSpokenText = re.getData();
     ...
   }

Also compatible with mbrola voices (http://tcts.fpms.ac.be/synthesis/mbrola.html), but requires a local installation of the mbrola binary (which must be named 'mbrola'), as well as a call to:

   RiSpeech.setMbrolaBase(String pathToMbrola);
Specific instructions for installing and testing mbrola with RiTa can be found here.

Note: there is currently an incompatability w' FreeTTS and Mbrola on Mac OSX, but you can use the native MacTTS voices with code as follows:

    RiSpeech rs = new RiSpeech(this);
    rs.useMacTTS();
    rs.setVoice("Bruce");
    rs.speak("Hello");
The default voices included on the Mac are:
    "Victoria", "Agnes", "Kathy", "Princess", "Vicki", 
    "Bruce", "Fred", "Junior", "Ralph", "Albert",
    "Bad News", "Bahh", "Bells", "Boing", "Bubbles", 
    "Cellos", "Deranged", "Good News", "Hysterical", 
    "Pipe Organ", "Trinoids", "Whisper", "Zarvox"
    


Field Summary
 
Fields inherited from interface rita.support.RiConstants
BEHAVIOR_COMPLETED, BOUNDING_BOX_ALPHA, BRILL_POS_TAGGER, EASE_IN, EASE_IN_CUBIC, EASE_IN_EXPO, EASE_IN_OUT, EASE_IN_OUT_CUBIC, EASE_IN_OUT_EXPO, EASE_IN_OUT_QUARTIC, EASE_IN_OUT_SINE, EASE_IN_QUARTIC, EASE_IN_SINE, EASE_OUT, EASE_OUT_CUBIC, EASE_OUT_EXPO, EASE_OUT_QUARTIC, EASE_OUT_SINE, ESS, FADE_COLOR, FADE_IN, FADE_OUT, FADE_TO_TEXT, FIRST_PERSON, FUTURE_TENSE, ID, LERP, LINEAR, MAXENT_POS_TAGGER, MINIM, MOVE, MUTABLE, PAST_TENSE, PHONEME_BOUNDARY, PHONEMES, PLING_STEMMER, PLURAL, PORTER_STEMMER, POS, PRESENT_TENSE, SCALE_TO, SECOND_PERSON, SENTENCE_BOUNDARY, SINGULAR, SONIA, SPEECH_COMPLETED, STRESSES, SYLLABLE_BOUNDARY, SYLLABLES, TEXT, TEXT_ENTERED, THIRD_PERSON, TIMER, TIMER_COMPLETED, TIMER_TICK, TOKENS, UNKNOWN, WORD_BOUNDARY
 
Fields inherited from interface processing.core.PConstants
A, AB, ADD, AG, ALPHA, ALPHA_MASK, ALT, AMBIENT, AR, ARC, ARGB, ARROW, B, BACKSPACE, BASELINE, BEEN_LIT, BEVEL, BLEND, BLUE_MASK, BLUR, BOTTOM, BOX, BURN, CENTER, CENTER_DIAMETER, CENTER_RADIUS, CHATTER, CLOSE, CMYK, CODED, COMPLAINT, CONTROL, CORNER, CORNERS, CROSS, CUSTOM, DA, DARKEST, DB, DEG_TO_RAD, DELETE, DG, DIAMETER, DIFFERENCE, DILATE, DIRECTIONAL, DISABLE_ACCURATE_TEXTURES, DISABLE_DEPTH_SORT, DISABLE_DEPTH_TEST, DISABLE_OPENGL_2X_SMOOTH, DISABLE_OPENGL_ERROR_REPORT, DODGE, DOWN, DR, DXF, EB, EDGE, EG, ELLIPSE, ENABLE_ACCURATE_TEXTURES, ENABLE_DEPTH_SORT, ENABLE_DEPTH_TEST, ENABLE_NATIVE_FONTS, ENABLE_OPENGL_2X_SMOOTH, ENABLE_OPENGL_4X_SMOOTH, ENABLE_OPENGL_ERROR_REPORT, ENTER, EPSILON, ER, ERODE, ERROR_BACKGROUND_IMAGE_FORMAT, ERROR_BACKGROUND_IMAGE_SIZE, ERROR_PUSHMATRIX_OVERFLOW, ERROR_PUSHMATRIX_UNDERFLOW, ERROR_TEXTFONT_NULL_PFONT, ESC, EXCLUSION, G, GIF, GRAY, GREEN_MASK, HALF_PI, HAND, HARD_LIGHT, HINT_COUNT, HSB, IMAGE, INVERT, JAVA2D, JPEG, LEFT, LIGHTEST, LINE, LINES, LINUX, MACOSX, MAX_FLOAT, MAX_INT, MIN_FLOAT, MIN_INT, MITER, MODEL, MULTIPLY, NORMAL, NORMALIZED, NX, NY, NZ, OPAQUE, OPEN, OPENGL, ORTHOGRAPHIC, OTHER, OVERLAY, P2D, P3D, PATH, PDF, PERSPECTIVE, PI, platformNames, POINT, POINTS, POLYGON, POSTERIZE, PROBLEM, PROJECT, QUAD, QUAD_STRIP, QUADS, QUARTER_PI, R, RAD_TO_DEG, RADIUS, RECT, RED_MASK, REPLACE, RETURN, RGB, RIGHT, ROUND, SA, SB, SCREEN, SG, SHAPE, SHIFT, SHINE, SOFT_LIGHT, SPB, SPG, SPHERE, SPOT, SPR, SQUARE, SR, SUBTRACT, SW, TAB, TARGA, THIRD_PI, THRESHOLD, TIFF, TOP, TRIANGLE, TRIANGLE_FAN, TRIANGLE_STRIP, TRIANGLES, TWO_PI, TX, TY, TZ, U, UP, V, VERTEX_FIELD_COUNT, VW, VX, VY, VZ, WAIT, WHITESPACE, WINDOWS, X, Y, Z
 
Constructor Summary
RiSpeech()
          Creates a new object for Text-To-Speech and enables TTS for the system (if possible)
RiSpeech(processing.core.PApplet pApplet)
          Creates a new object for Text-To-Speech and enables TTS for the system (if possible)
RiSpeech(processing.core.PApplet pApplet, java.lang.String voiceName)
          Creates a new object for Text-To-Speech and enables TTS for the system (if possible), using the specified voice name.
RiSpeech(processing.core.PApplet pApplet, java.lang.String voiceName, java.lang.String mbrolaBase)
          Creates a new object for Text-To-Speech and enables TTS for the system
using the specified voice name, and setting the optional property 'mbrola.base' to mbrolaBase.
 
Method Summary
 void delete()
          Cleans-up resources associated with the text-to-speech engine.
 void dispose()
          Cleans-up resources on program end - not to be called in user-code.
 void fireSpeechCompletedEvent(java.lang.String text)
          Creates dynamic callback to the parent PApplet implementing:
 java.lang.String[] getAvailableVoiceNames()
          Returns the names for all currently available voices.
 java.lang.String getOutputFile()
          Returns the current output filename of null if none is specified.
 java.lang.String getVoiceDescription()
          Returns descriptive info on the current voice
 java.lang.String[] getVoiceDescriptions()
          Returns the names and descriptions for each available voice.
 java.lang.String[] getVoiceInfo()
          Deprecated.  
 java.lang.String getVoiceName()
          Returns a descriptive name for the current voice
 float getVoicePitch()
          Returns the pitch of the current voice
 float getVoicePitchRange()
          Returns the pitch range of the current voice
 float getVoicePitchShift()
          Returns the pitch shift of the current voice
 float getVoiceRate()
          Returns the rate of the current voice
 float getVoiceVolume()
          Returns the volume of the current voice
static boolean isTTSEnabled()
          Returns whether Text-To-Speech is currently enabled
 boolean isUsingMacTTS()
          Returns true if the speech engine is using the built-in Mac Speech API
static void main(java.lang.String[] args)
           
 void preload()
          Loads all speech resources immediately (on initialization) to avoid any delays on the first utterance -- only necessary if there is a noticeable delay in program execution when speech begins.
static void setMbrolaBase(java.lang.String mbrolaBase)
          Enables support for mbrola voices by specifying the path to the installed mbrola binary.
 void setOutputFile(java.lang.String wavFileName)
          Will direct output to a file instead of to the system's audio output.
static void setTTSEnabled(boolean enableTts)
          Set whether Text-To-Speech is currently enabled
 void setVoice(java.lang.String voiceDesc)
          Sets the current voice by name (default voice='kevin')
 void setVoicePitch(float hertz)
          Sets the pitch of the current voice
 void setVoicePitchRange(float range)
          Sets the pitch range of the current voice
 void setVoicePitchShift(float shift)
          Sets the pitch shift of the current voice
 void setVoiceRate(float wpm)
          Sets the rate of the current voice
 void setVoiceVolume(float vol)
          Sets the volume of the current voice
 void speak(RiString riString)
          Speaks the text string contained in a RiString object using the current voice.
 void speak(RiText riText)
          Speaks the text string contained in a RiText object using the current voice.
 void speak(java.lang.String text)
          Speaks the text string using the current voice.
 void stop()
          Stops the voice immediately if speaking.
 void useMacTTS()
          Tells the object to use the built-in Mac Speech API for all subsequent utterances
 void useMacTTS(java.lang.String voice)
          Tells the object to use the built-in Mac Speech API for all subsequent utterances, then sets the current voice to voice
 
Methods inherited from class rita.RiObject
getId, getPApplet, nextId
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RiSpeech

public RiSpeech()
Creates a new object for Text-To-Speech and enables TTS for the system (if possible)

Invisible:

RiSpeech

public RiSpeech(processing.core.PApplet pApplet)
Creates a new object for Text-To-Speech and enables TTS for the system (if possible)


RiSpeech

public RiSpeech(processing.core.PApplet pApplet,
                java.lang.String voiceName)
Creates a new object for Text-To-Speech and enables TTS for the system (if possible), using the specified voice name.


RiSpeech

public RiSpeech(processing.core.PApplet pApplet,
                java.lang.String voiceName,
                java.lang.String mbrolaBase)
Creates a new object for Text-To-Speech and enables TTS for the system
using the specified voice name, and setting the optional property 'mbrola.base' to mbrolaBase.

Method Detail

dispose

public void dispose()
Cleans-up resources on program end - not to be called in user-code.

Overrides:
dispose in class RiObject

getOutputFile

public java.lang.String getOutputFile()
Returns the current output filename of null if none is specified.


setOutputFile

public void setOutputFile(java.lang.String wavFileName)
Will direct output to a file instead of to the system's audio output. To re-enable audio output (the default), pass null to this method.


preload

public void preload()
Loads all speech resources immediately (on initialization) to avoid any delays on the first utterance -- only necessary if there is a noticeable delay in program execution when speech begins.


fireSpeechCompletedEvent

public void fireSpeechCompletedEvent(java.lang.String text)
Creates dynamic callback to the parent PApplet implementing:
     void onRiTaEvent(RiTaEvent re) {...}

Invisible:

isTTSEnabled

public static boolean isTTSEnabled()
Returns whether Text-To-Speech is currently enabled


setTTSEnabled

public static void setTTSEnabled(boolean enableTts)
Set whether Text-To-Speech is currently enabled

Parameters:
enableTts -

getVoiceDescriptions

public java.lang.String[] getVoiceDescriptions()
Returns the names and descriptions for each available voice.


getAvailableVoiceNames

public java.lang.String[] getAvailableVoiceNames()
Returns the names for all currently available voices.


speak

public void speak(RiText riText)
Speaks the text string contained in a RiText object using the current voice.


speak

public void speak(RiString riString)
Speaks the text string contained in a RiString object using the current voice.


speak

public void speak(java.lang.String text)
Speaks the text string using the current voice.


delete

public void delete()
Cleans-up resources associated with the text-to-speech engine. Automatically called on 'shutdown' when using Processing.


getVoiceName

public java.lang.String getVoiceName()
Returns a descriptive name for the current voice


getVoiceDescription

public java.lang.String getVoiceDescription()
Returns descriptive info on the current voice


getVoiceInfo

public java.lang.String[] getVoiceInfo()
Deprecated. 

See Also:
getVoiceDescriptions()
Invisible:

getVoicePitch

public float getVoicePitch()
Returns the pitch of the current voice


getVoicePitchRange

public float getVoicePitchRange()
Returns the pitch range of the current voice


getVoicePitchShift

public float getVoicePitchShift()
Returns the pitch shift of the current voice


stop

public void stop()
Stops the voice immediately if speaking.


getVoiceRate

public float getVoiceRate()
Returns the rate of the current voice


getVoiceVolume

public float getVoiceVolume()
Returns the volume of the current voice


setVoice

public void setVoice(java.lang.String voiceDesc)
Sets the current voice by name (default voice='kevin')

Additional 'mbrola' voices can also be enabled if the mbrola binary is installed and the 'mbrola.base' system property has been set by calling:

    RiSpeech.setMbrolaBase("c:\\path\\to\\mbrola\\");


setMbrolaBase

public static void setMbrolaBase(java.lang.String mbrolaBase)
Enables support for mbrola voices by specifying the path to the installed mbrola binary.

Note: this method must be called before setting the current voice to an mbrola voice.


setVoicePitch

public void setVoicePitch(float hertz)
Sets the pitch of the current voice


setVoicePitchRange

public void setVoicePitchRange(float range)
Sets the pitch range of the current voice


setVoicePitchShift

public void setVoicePitchShift(float shift)
Sets the pitch shift of the current voice


setVoiceRate

public void setVoiceRate(float wpm)
Sets the rate of the current voice


setVoiceVolume

public void setVoiceVolume(float vol)
Sets the volume of the current voice


useMacTTS

public void useMacTTS()
Tells the object to use the built-in Mac Speech API for all subsequent utterances


useMacTTS

public void useMacTTS(java.lang.String voice)
Tells the object to use the built-in Mac Speech API for all subsequent utterances, then sets the current voice to voice


isUsingMacTTS

public boolean isUsingMacTTS()
Returns true if the speech engine is using the built-in Mac Speech API


main

public static void main(java.lang.String[] args)