Package speakeasy :: Module text_to_speech :: Class TextToSpeechProvider
[hide private]
[frames] | no frames]

Class TextToSpeechProvider

source code

object --+
         |
        TextToSpeechProvider

Abstraction for interacting with text-to-speech engines on Ubuntu, Mac, and (unimplemented:) Windows. Detects Festival and Cepstral engines on Ubuntu. Main public facilities: Speak an utterance immediately, given a string, and generate a .wav file from the text-to-speech conversion.

Instance Methods [hide private]
 
__init__(self)
x.__init__(...) initializes x; see help(type(x)) for signature
source code
 
sayToFile(self, text, voiceName=None, t2sEngineName=None, destFileName=None)
Create a sound file with the result of turning the string passed in parameter 'text' to sound.
source code
 
say(self, text, voiceName=None, t2sEngineName=None, blockTillDone=False)
Immediately speak the given string with the given voice on the given engine.
source code
 
stop(self)
Stop text-to-speech that is currently playing.
source code
 
busy(self)
Return True if any of the text-to-speech engines is currently synthesizing.
source code
 
waitForSoundDone(self)
Block until speech finished playing.
source code
[string]
availableTextToSpeechEngines(self)
Returns an array of text-to-speech engine names that are available on the current machine.
source code
{string : [string]}
availableVoices(self)
Returns a dictionary of all available voices for each text-to-speech engine.
source code
 
getEngineObj(self, engineName)
From a text-to-speech engine name that may be None, return an engine object.
source code
TextToSpeechEngine subclass
findAvailableTTSEngines(self)
Try to sense the underlying OS.
source code
TexToSpeechEngine
linuxTTSEngines(self)
Called if underlying machine is Linux.
source code
TexToSpeechEngine
macTTSEngines(self)
Called if underlying machine is Mac.
source code
 
windowsTTSEngines(self) source code

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Static Methods [hide private]
 
which(program)
Implements the Unix 'which' shell command, extended to consider not just $PATH, but also $PYTHONPATH when searching for an executable of the given name (the program parameter).
source code
Properties [hide private]

Inherited from object: __class__

Method Details [hide private]

__init__(self)
(Constructor)

source code 

x.__init__(...) initializes x; see help(type(x)) for signature

Overrides: object.__init__
(inherited documentation)

sayToFile(self, text, voiceName=None, t2sEngineName=None, destFileName=None)

source code 

Create a sound file with the result of turning the string passed in parameter 'text' to sound. The given voice engine and voice are used. If no destination file is provided, a temporary file is created, and its filename is returned after the file is closed. The caller bears responsibility for removing that temporary file.

Parameters:
  • text (string) - String to convert into sound.
  • t2sEngineName (string) - Name of text-to-speech engine: "festival", "cepstral", "mact2s"
  • voiceName (string) - Name of voice to use. Must be a voice supported by the given t2s engine.
  • destFileName (string) - Path into which the resulting sound should be directed. If not provided, a temp file is created.
Raises:
  • NotImplementedError - if voice is not supported by the given engine.
  • ValueError - if given engine name does not correspond to any know text-to-speech engine.

say(self, text, voiceName=None, t2sEngineName=None, blockTillDone=False)

source code 

Immediately speak the given string with the given voice on the given engine. If voice or engine are not provided, defaults are used.

Parameters:
  • text (string) - String to speak
  • voiceName (string) - Designation of the voice to use.
  • t2sEngineName (string) - Name of text-to-speech engine to use.
  • blockTillDone (boolean) - If true, method will sleep till speech done, then method returns.
Raises:
  • ValueError - if unknown text-to-speech engine.
  • OSError - if failure in running the text-to-speech command in underlying shell

busy(self)

source code 

Return True if any of the text-to-speech engines is currently synthesizing. Else return False;

availableTextToSpeechEngines(self)

source code 

Returns an array of text-to-speech engine names that are available on the current machine. Exampele: ['festival', 'cepstral']

Returns: [string]
Array of text-to-speech engine names as appropriate for ROS t2s messages. Order within the array is not necessarily the same between calls.

availableVoices(self)

source code 

Returns a dictionary of all available voices for each text-to-speech engine. Keys are the engine names. Example:

  1. Cepstral : ['David', 'Anna']
  2. Festival : ['voice_kal_diphone']

The default voice for each engine is guaranteed to be the first in the voice lists. Order of the remaining voices is arbitrary.

Returns: {string : [string]}
Dictionary mapping text-to-speech engine names to lists of voice names.

getEngineObj(self, engineName)

source code 

From a text-to-speech engine name that may be None, return an engine object.

Parameters:
  • engineName (string) - Name of text-to-speech engine to use
Returns:
Subclass of TextToSpeechEngine

findAvailableTTSEngines(self)

source code 

Try to sense the underlying OS. Then identify the available text-to-speech engines. Return the default engine to be used.

Returns: TextToSpeechEngine subclass
Default engine instance.
Raises:
  • ValueError - if no speech engine is found.

linuxTTSEngines(self)

source code 

Called if underlying machine is Linux. Explores which text-to-speech engines are available. Festival is built into Ubuntu. Cepstral is a for-pay engine.

Returns: TexToSpeechEngine
Text-to-speech engine instance to use as default. None if no text-to-speech-engine is available.

macTTSEngines(self)

source code 

Called if underlying machine is Mac. Explores which text-to-speech engines are available.

Returns: TexToSpeechEngine
Text-to-speech engine instance to use as default. None if no text-to-speech-engine is available.

which(program)
Static Method

source code 

Implements the Unix 'which' shell command, extended to consider not just $PATH, but also $PYTHONPATH when searching for an executable of the given name (the program parameter). $PATH is given preference; it is searched first.

Parameters:
  • program (string) - Name of the executable with or without path
Returns:
None if no executable found, else full path to executable.