Online Book Reader

Home Category

Beautiful Code [330]

By Root 5344 0
server.

The speech server handles queued requests to produce perceptible output.

Text is preprocessed by placing the text in a special scratch buffer. Buffers acquire specialized behavior via buffer-specific syntax tables that define the grammar of buffer contents and buffer-local variables that affect behavior. When text is handed off to the Emacspeak core, all of these buffer-specific settings are propagated to the special scratch buffer where the text is preprocessed. This automatically ensures that text is meaningfully parsed into clauses based on its underlying grammar.

31.2.4.1. Audio formatting using voice-lock

Emacs uses font-lock to syntactically color text. For creating the visual presentation, Emacs adds a text property called face to text strings; the value of this face property specifies the font, color, and style to be used to display that text. Text strings with face properties can be thought of as a conceptual visual display list.

Emacspeak augments these visual display lists with personality text properties whose values specify the auditory properties to use when rendering a given piece of text; this is called voice-lock in Emacspeak. The value of the personality property is an Aural CSS (ACSS) setting that encodes various voice properties—e.g., the pitch of the speaking voice. Notice that such ACSS settings are not specific to any given TTS engine. Emacspeak implements ACSS-to-TTS mappings in engine-specific modules that take care of mapping high-level aural properties—e.g., mapping pitch or pitch-range to engine-specific control codes.

The next few sections describe how Emacspeak augments Emacs to create aural display lists and to process these aural display lists to produce engine-specific output.

31.2.4.2. Augmenting Emacs to create aural display lists

Emacs modules that implement font-lock call the Emacs built-in function put-text-property to attach the relevant face property. Emacspeak defines an advice fragment that advices the put-text-property function to add in the corresponding personality property when it is asked to add a face property. Note that the value of both display properties (face and personality) can be lists; values of these properties are thus designed to cascade to create the final (visual or auditory) presentation. This also means that different parts of an application can progressively add display property values.

The put-text-property function has the following signature:

(put-text-property START END PROPERTY VALUE &optional OBJECT)

The advice implementation is:

Code View: Scroll / Show All

(defadvice put-text-property (after emacspeak-personality pre act)

"Used by emacspeak to augment font lock."

(let ((start (ad-get-arg 0)) ;; Bind arguments

(end (ad-get-arg 1 ))

(prop (ad-get-arg 2)) ;; name of property being added

(value (ad-get-arg 3 ))

(object (ad-get-arg 4))

(voice nil)) ;; voice it maps to

(when (and (eq prop 'face) ;; avoid infinite recursion

(not (= start end)) ;; non-nil text range

emacspeak-personality-voiceify-faces)

(condition-case nil ;; safely look up face mapping

(progn

(cond

((symbolp value)

(setq voice (voice-setup-get-voice-for-face value)))

((ems-plain-cons-p value)) ;;pass on plain cons

( (listp value)

(setq voice

(delq nil

(mapcar #'voice-setup-get-voice-for-face value))))

(t (message "Got %s" value)))

(when voice ;; voice holds list of personalities

(funcall emacspeak-personality-voiceify-faces start end voice object)))

(error nil)))))

Here is a brief explanation of this advice definition:

Bind arguments

First, the function uses the advice built-in ad-get-arg to locally bind a set of lexical variables to the arguments being passed to the adviced function.

Personality setter

The mapping of faces to personalities is controlled by user customizable variable emacspeak-personality-voiceify-faces. If non-nil, this variable specifies a function with the following signature:

(emacspeak-personality-put START END PERSONALITY OBJECT)

Emacspeak provides

Return Main Page Previous Page Next Page

®Online Book Reader