Online Book Reader

Home Category

Beautiful Code [331]

By Root 5236 0
different implementations of this function that either append or prepend the new personality value to any existing personality properties.

Guard

Along with checking for a non-nil emacspeak-personality-voiceify-faces, the function performs additional checks to determine whether this advice definition should do anything. The function continues to act if:

The text range is non-nil.

The property being added is a face.

The first of these checks is required to avoid edge cases where put-text-property is called with a zero-length text range. The second ensures that we attempt to add the personality property only when the property being added is face. Notice that failure to include this second test would cause infinite recursion because the eventual put-text-property call that adds the personality property also triggers the advice definition.

Get mapping

Next, the function safely looks up the voice mapping of the face (or faces) being applied. If applying a single face, the function looks up the corresponding personality mapping; if applying a list of faces, it creates a corresponding list of personalities.

Apply personality

Finally, the function checks that it found a valid voice mapping and, if so, calls emacspeak-personality-voiceify-faces with the set of personalities saved in the voice variable.

31.2.4.3. Audio-formatted output from aural display lists

With the advice definitions from the previous section in place, text fragments that are visually styled acquire a corresponding personality property that holds an ACSS setting for audio formatting the content. The result is to turn text in Emacs into rich aural display lists. This section describes how the output layer of Emacspeak is enhanced to convert these aural display lists into perceptible spoken output.

The Emacspeak tts-speak module handles text preprocessing before finally sending it to the speech server. As described earlier, this preprocessing comprises a number of steps, including:

Applying pronunciation rules

Processing repeated strings of punctuation characters

Splitting text into appropriate clauses based on context

Converting the personality property into audio formatting codes

This section describes the tts-format-text-and-speak function, which handles the conversion of aural display lists into audio-formatted output. First, here is the code for the function tts-format-text-and-speak:

Code View: Scroll / Show All

(defsubst tts-format-text-and-speak (start end )

"Format and speak text between start and end."

(when (and emacspeak-use-auditory-icons

(get-text-property start 'auditory-icon)) ;;queue icon

(emacspeak-queue-auditory-icon (get-text-property start 'auditory-icon)))

(tts-interp-queue (format "%s\n" tts-voice-reset-code))

(cond

(voice-lock-mode ;; audio format only if voice-lock-mode is on

(let ((last nil) ;; initialize

(personality (get-text-property start 'personality )))

(while (and (

< start end ) ;; chunk at personality changes

(setq last

(next-single-property-change start 'personality

(current-buffer) end)))

(if personality ;; audio format chunk

(tts-speak-using-voice personality (buffer-substring start last ))

(tts-interp-queue (buffer-substring start last)))

(setq start last ;; prepare for next chunk

personality (get-text-property last 'personality)))))

;; no voice-lock just send the text

(t (tts-interp-queue (buffer-substring start end )))))

The tts-format-text-and-speak function is called one clause at a time, with arguments start and end set to the start and end of the clause. If voice-lock-mode is turned on, this function further splits the clause into chunks at each point in the text where there is a change in value of the personality property. Once such a transition point has been determined, tts-format-text-and-speak calls the function tts-speak-using-voice, passing the personality to use and the text to be spoken. This function, described next, looks up the appropriate device-specific codes before dispatching the audio-formatted

Return Main Page Previous Page Next Page

®Online Book Reader