;;; uko-speak.speechserver.el -- speechserver routines

;; Copyright (C) 2003 Sasa Hasan, Universität Koblenz-Landau

;; Author: Sasa Hasan  <sasa.hasan@uni-koblenz.de>
;; Maintainer: Michael Kuehn <kuehn@uni-koblenz.de>
;; Created: March 2003
;; 
;; $Id: uko-speak.speechserver.el,v 1.2 2003/08/26 10:38:09 deee Exp $


(defvar uko-speak-host "localhost"
  "Name or address of the host running the speech server.")

(defvar uko-speak-port 10100
  "Port of the socket used to communicate with the speech server.")

(defvar uko-speak-process-name "uko-speak"
  "Name of the process name associated with the speech server.")

(defvar uko-speak-buffer-name "*UKO Speak*"
  "Name of the buffer where the output from the speech server is stored.")




(defun uko-speak-connect ()
  "Connect to the speech server."
  (interactive)
  (when (null (get-process uko-speak-process-name))
    (open-network-stream uko-speak-process-name uko-speak-buffer-name uko-speak-host uko-speak-port)
    ) )

(defun uko-speak-disconnect ()
  "Disconnect from the speech server."
  (interactive)
  (delete-process uko-speak-process-name)
  )

(defun uko-speak-buffer (&optional buffer-name)
  "Speaks the content of buffer with name 'buffer-name'."
  (interactive "bBuffer: ")
  (save-excursion
    (when buffer-name
	(set-buffer (get-buffer buffer-name))
	)
    (uko-speak-send-string (buffer-string))
    ) )

(defun uko-speak-current-buffer ()
  "Speaks the content of the current buffer."
  (interactive)
  (uko-speak-send-string (buffer-string))
  )

(defun uko-speak-region ()
  "Speaks the currently selected region."
  (interactive)
  (when (region-exists-p)
    (uko-speak-send-string (buffer-substring (region-beginning) (region-end)))
    ) )

(defun uko-speak-stop ()
  "Stops the current speech synthesis."
  (interactive)
  (uko-speak-send-string "/stop")
  )

(defun uko-speak-pause ()
  "Pauses the current speech synthesis."
  (interactive)
  (uko-speak-send-string "/pause")
  )

(defun uko-speak-resume ()
  "Resumes the current speech synthesis."
  (interactive)
  (uko-speak-send-string "/resume")
  )

(defun uko-speak-get-mode-names ()
  "Returns a list with available mode names (speakers)."
  (interactive)
  (uko-speak-send-string "/list")
  )

(defun uko-speak-set-mode (mode)
  "Selects the speaker of mode 'mode' (number or mode substring)."
  (interactive "sMode name or number: ")
  (if (> (string-to-number mode) 0)
      (uko-speak-send-string (concat "/modenum " mode))
    (uko-speak-send-string (concat "/mode " mode))
    ) )

(defun uko-speak-set-mode-german-male ()
  "Sets the speaker to default German male speaker."
  (interactive)
  (uko-speak-send-string "/mode Thomas 16Khz")
  )

(defun uko-speak-set-mode-german-female ()
  "Sets the speaker to default German female speaker."
  (interactive)
  (uko-speak-send-string "/mode Dagmar 16Khz")
  )

(defun uko-speak-set-mode-english-male ()
  "Sets the speaker to default English male speaker."
  (interactive)
  (uko-speak-send-string "/mode Gordon 16Khz")
  )

(defun uko-speak-set-mode-english-female ()
  "Sets the speaker to default English female speaker."
  (interactive)
  (uko-speak-send-string "/mode Vicky 16Khz")
  )

(defun uko-speak-set-mode-french-male ()
  "Sets the speaker to default French male speaker."
  (interactive)
  (uko-speak-send-string "/mode Robert 16Khz")
  )

(defun uko-speak-set-mode-french-female ()
  "Sets the speaker to default French female speaker."
  (interactive)
  (uko-speak-send-string "/mode Cathy 16Khz")
  )

(defun uko-speak-send-string (message)
  "Sends a string to the speech server."
  (interactive "sString: ")
  (process-send-string uko-speak-process-name message)
  )
