Module Audio :: Class Audio
[hide private]
[frames] | no frames]

Class Audio

source code

??-294 --+
         |
        Audio

Defines the base class for all audio output devices. Provides default implementations of sendStringSync and parseString specific to audio devices.

Some methods defined here raise NotImplementedError to ensure that derived classes create appropriate implementions. Implementing sendIndex is optional. The AccessEngine.AEDeviceManager catches the not implemented exception in this case.

Nested Classes [hide private]
  STYLE
Defines the basic style attributes for all AEOutput.Audio devices.
Instance Methods [hide private]
 
__init__(self)
Initializes the empty listeners list.
source code
list of string
getCapabilities(self)
Returns: 'audio' as the only capability of this device.
source code
 
addIndexListener(self, listener)
Adds a listener that should be notified when speech has progressed to the point where a marker was inserted with sendIndex.
source code
 
removeIndexListener(self, listener)
Removes the specified listener.
source code
AEOutput
getProxy(self)
Looks at the USE_THREAD flag to see if the device implementing this interface wants a thread proxy or not.
source code
string
_parseMain(self, word, style, ch, part)
Adds support for the AEOutput.Style.AudioStyle settings of CapExpand and NumExpand.
source code
3-tuple of lists of string, AEPor, AEOutput.Style
parseString(self, text, style, por, sem)
Provides a default implementation of parsing that formats words for audio devices supporting speech output.
source code
object
send(self, name, value, style=None)
Dispatches known commands to their appropriate handlers.
source code
 
sendString(self, text, style)
Sends a string of one or more characters to the device.
source code
 
sendFilename(self, fn, style)
Sends a string filename to the device, the contents of which should be output.
source code
 
sendStop(self, style=None)
Purges buffered text and styles, and interrupts on-going output.
source code
 
sendTalk(self, style=None)
Indicates all text buffered by sendString should now be output.
source code
integer
sendIndex(self, style)
Inserts a marker in the output stream.
source code
 
sendStringSync(self, text, style)
Buffers a complete string to send to the device synchronously.
source code
string
sendGetClosestLang(self, tag)
Maps a language tag to the closest one possible as supported by this device.
source code
Instance Variables [hide private]
list listeners
List of callables that should be notified when a marker inserted with sendIndex is encountered
Method Details [hide private]

getCapabilities(self)

source code 
Returns: list of string
'audio' as the only capability of this device.

addIndexListener(self, listener)

source code 
Adds a listener that should be notified when speech has progressed to the point where a marker was inserted with sendIndex.
Parameters:
  • listener (callable) - The method that should be called when markers received.

removeIndexListener(self, listener)

source code 
Removes the specified listener.
Parameters:
  • listener (callable) - The method that should no longer be called when markers received.
Raises:
  • ValueError - When the given listener is not already registered

getProxy(self)

source code 
Looks at the USE_THREAD flag to see if the device implementing this interface wants a thread proxy or not.
Returns: AEOutput
self or ThreadProxy.AudioThreadProxy

_parseMain(self, word, style, ch, part)

source code 
Adds support for the AEOutput.Style.AudioStyle settings of CapExpand and NumExpand. This method is notified during parsing of the main part of a Word.
Parameters:
  • word (Word) - Word currently parsing its source text
  • style (AEOutput.Style.AudioStyle) - Style used to configure the parsing process
  • ch (string) - Character in the word
  • part (list) - List of characters already processed in this part of the word
Returns: string
Character(s) to be appended to the list

parseString(self, text, style, por, sem)

source code 
Provides a default implementation of parsing that formats words for audio devices supporting speech output. The base Word class is used plus some additional processing for:
  • blank words
  • expanded caps
  • expanded numbers
  • spelling format
  • individual characters
Parameters:
  • text (string) - Text to be parsed
  • style (AEOutput.Style) - Style object defining how the text should be parsed
  • por (AEPor) - Point of regard for the first character in the text, or None if the text is not associated with a POR
  • sem (integer) - Semantic tag for the text to aid parsing
Returns: 3-tuple of lists of string, AEPor, AEOutput.Style
Parsed words

send(self, name, value, style=None)

source code 
Dispatches known commands to their appropriate handlers.
Parameters:
  • name (object) - Descriptor of the data value sent
  • value (object) - Content value
  • style (AEOutput.Style) - Style with which this value should be output
Returns: object
Return value specific to the given command
Raises:
  • NotImplementedError - When the handler for a common command is not implemented by a subclass

sendString(self, text, style)

source code 
Sends a string of one or more characters to the device. The style object is used by the device in deciding how the given text should be presented.
Parameters:
  • text (string) - Text to send to the device
  • style (AEOutput.Style) - Style with which this text should be output
Raises:
  • NotImplementedError - When not overridden in a subclass

sendFilename(self, fn, style)

source code 

Sends a string filename to the device, the contents of which should be output. The style object is used by the device in decided how the given text should be presented.

Typically, this method should be implemented by an audio device that supports playback of waveform or sequencer files. It might also be used by devices as a way of synthesizing the entire contents of a file without having to pass all of the contents through the rest of the system.
Parameters:
  • fn (string) - Absolute filename
  • style (AEOutput.Style) - Style with which this text should be output
Raises:
  • NotImplementedError - When not overridden in a subclass

sendStop(self, style=None)

source code 
Purges buffered text and styles, and interrupts on-going output.
Parameters:
  • style (AEOutput.Style) - Style indicating which channel on which the stop should be performed; None indicates stop on all channels
Raises:
  • NotImplementedError - When not overridden in a subclass

sendTalk(self, style=None)

source code 
Indicates all text buffered by sendString should now be output. For devices that do the buffering in the driver, this action may mean simply sending the command. For devices that do not buffer, this action means sending text and styles buffered in the SUE device definition.
Parameters:
  • style (AEOutput.Style) - Style indicating which channel on which the talk should be performed; None indicates talk on all channels
Raises:
  • NotImplementedError - When not overridden in a subclass

sendIndex(self, style)

source code 
Inserts a marker in the output stream. The device should notify all listeners when the marker is reached. The marker is typically a monotonically increase integer number mod the maximum integer value supported by the device.
Parameters:
  • style (AEOutput.Style) - Style indicating which channel on which the marker should be inserted
Returns: integer
Unique marker identifying the index inserted
Raises:
  • NotImplementedError - When not overridden in a subclass

sendStringSync(self, text, style)

source code 

Buffers a complete string to send to the device synchronously.

This should not be used in place of sendString since this will not return until the string is finished being output. This is provided only for the convenience of utility writers. Uses sendStop, sendString, sendTalk, and then sleeps until AEOutput.isActive returns False.

This method sends the stop, string, and talk commands directly to the device, bypassing any thread proxy. This could be problematic if the audio library in question cannot be used in more than one thread.
Parameters:
  • text (string) - String to send to the device
  • style (AEOutput.Style) - Style on which this string should be output; None implies some reasonable default should be used

sendGetClosestLang(self, tag)

source code 
Maps a language tag to the closest one possible as supported by this device. The result may be an exact match or only a partial match. If absolutely nothing matches the requested tag, not even starting at the major language, None should be returned.
Parameters:
  • tag (string) - IANA language tag, lower case
Returns: string
IANA language tag or None