diff options
Diffstat (limited to 'chess-announce.el')
| -rw-r--r-- | chess-announce.el | 45 |
1 files changed, 26 insertions, 19 deletions
diff --git a/chess-announce.el b/chess-announce.el index 873531c..ba3e052 100644 --- a/chess-announce.el +++ b/chess-announce.el @@ -14,33 +14,37 @@ (?r . "rook") (?p . "pawn"))) -(defvar chess-announce-function 'chess-announce-festival - "The function to call for announcing moves audially. -It is passed the string of English text to announce.") +(autoload 'festival-start-process "festival") +(autoload 'festival-kill-process "festival") -(defun chess-announce-for-game (game perspective) - "Announce moves in GAME on behalf of PERSPECTIVE. -This means that if PERSPECTIVE is t (for white), only black's moves -will be announced." - (chess-game-add-hook game 'chess-announce-event-handler perspective)) +(defvar chess-announce-functions + (if (executable-find "festival") + (if (fboundp 'festival-say-string) + '(festival-start-process festival-say-string festival-kill-process) + '(ignore chess-announce-festival ignore)) + '(ignore message ignore)) + "These three functions are used to for announcing moves. +The first is called one start of the announcer. The second is called +with the string to announce each time. The third is called to +shutdown the announcer process, if necessary.") -(defun chess-announce-change-perspective (game perspective) - "Change the announce perspective in GAME to PERSPECTIVE." - (let ((cell (assq 'chess-announce-event-handler (chess-game-hooks game)))) - (if cell - (setcdr cell perspective)))) +(defun chess-announce-for-game (game) + "Announce the opponent's moves in GAME." + (chess-game-add-hook game 'chess-announce-event-handler) + (funcall (nth 0 chess-announce-functions))) -(defun chess-announce-event-handler (game perspective event &rest args) +(defun chess-announce-event-handler (game ignore event &rest args) "This display module presents a standard chessboard. See `chess-display-type' for the different kinds of displays." (cond - ((eq event 'pass) - (chess-announce-change-perspective game (not perspective))) + ((eq event 'shutdown) + (funcall (nth 2 chess-announce-functions))) ((memq event '(move game-over)) (let* ((ply (chess-game-ply game (1- (chess-game-index game)))) (pos (chess-ply-pos ply))) - (unless (eq perspective (chess-pos-side-to-move pos)) + (unless (eq (chess-game-get-data game 'my-color) + (chess-pos-side-to-move pos)) (let* ((changes (chess-ply-changes ply)) (source (car changes)) (target (cadr changes)) @@ -69,10 +73,13 @@ See `chess-display-type' for the different kinds of displays." (if (memq :stalemate changes) (setq text (concat text ", stalemate"))) - (funcall chess-announce-function text))))))) + (funcall (nth 1 chess-announce-functions) text))))))) (defun chess-announce-festival (text) - "Announce the given text using festival." + "Announce the given text using festival. +This is less efficient than festival.el, which should be installed if +possible. Debian installs it automatically when you apt-get install +festival." (let ((proc (start-process "announce" nil "/usr/bin/festival" "--tts"))) (when (and proc (eq (process-status proc) 'run)) (process-send-string proc (concat text "\n")) |
