zsh-workers
 help / color / mirror / code / Atom feed
From: Mario Lang <mlang@home.delysid.org>
To: zsh-workers@sunsite.dk
Subject: ZSpeak! Only Zsh can do this!
Date: 16 Mar 2001 15:21:17 +0100	[thread overview]
Message-ID: <874rwtzteq.fsf@home.delysid.org> (raw)

Hi guys.

First of all, I want to introduce myself:
I am a fanatic linux user/developer since 1997
and recently (its a shame that it took so long) I discovered
Zsh and I want to say: You guys did a great job!

As I am a blind Linux user I began to wonder if ZLE (and other things)
could be extended to support Speech output.
This could be nice for various reasons:
1. For blind/visually impaired persons who want to get
a simple speech output from cli without much setup efforts.
2. Perhaps for mobile devices with are limited in space
for a large comprehensive speech output system.

As I said, I am fairly new to Zsh and shell programming in general.
But I couldn't resist to try my best, and here
is how far I got.

But it is far from being finished.
I wanted to post this here for various reasons:
1. Perhaps someone finds a way to do something much
   better than I currently do.
2. Perhaps someone can find some solutions for my TODO
   list.

OK, here we go. Please mail me with every (minor|major) suggestion.
I can use everything. Especially to learn nice Zsh techniques.


#
# Zspeak - Zsh Function to get speech feedback.
#
# by Mario Lang <lang@zid.tu-graz.ac.at>
#
# Currently only ZLE (the line editor) is supported.
# TODO:
# * Find a nice way to add/remove keybindings in speech-(on|off)
# * Find a way to make the prefix key-sequence configurable (^[v)
# * Add self-insert replacement functions to speak typed chars
#   * Add parameter and keybinding to control character echo
#   * Word-echo?? (magic-space??)
# * Add replacement function for up/down to speak new BUFFER content
# * Modify the completion system so that menu-completion inserted
#   text gets spoken.
# * Find a way to read stdout/stderr of commands too! is exec my friend?
#   If this can be done in a nice way, all kinds of non-interactive
#   console programs can be used eye-free with Zsh and a soft/hard-speechsynth.
# * Add speech rate parameter (and keybinding to change it)
# 
# Comments:
#   I am fairly new to Zsh and all its specialities.
#  If you find anything in this code which could be done
#  better, please tell me. I am eager to find the best way
#  to do this. Especially am I interested in ways
#  to get the last TODO item to work (stdout and stderr review).
#
#  This file should be called speech-on and placed
#  in fpath.
#  autoload it, and execute speech-on
#

speech-on () {
    zle -N speech-on
    zle -N speech-off
    zle -N speak-buffer
    zle -N speak-current-character
    zle -N speak-help
    zle -N forward-char speak-new-position
    zle -N backward-char speak-new-position
    #speech-load-spell-list
    bindkey "^[vb" speak-buffer
    bindkey "^[vc" speak-current-char
    bindkey "^[vh" speak-help
    bindkey "^[vo" speech-off
}

speech-off () {
    unset zspeak_spell
    bindkey "^[vo" speech-on
}

# BUG: Doesnt read in the spell list?? Any Zmagician?
speech-load-spell-list () {
    typeset -A zspeak_spell
    [[ -z $ZSPEAK_SPELL_LIST ]] && [[ -s "~/.zsh/spell.list" ]] \
				&& ZSPEAK_SPELL_LIST='~/.zsh/spell.list'
    if [[ -s "$ZSPEAK_SPELL_LIST" ]]; then
        zspeak_spell=(${$(<${ZSPEAK_SPELL_LIST})})
    else
        # Some fallback defaults
        zspeak_spell=(. dot , comma ; colon / slash _ underscore - dash)
    fi
}

speak-string () {
    # Here goes the compatibility code. All synth specific
    # decissions when outputting text should be done here.
    case $ZSPEAK_SYNTH in
	festival)
	    [[ -x `which festival` ]] && print "$@"|festival --tts
	    ;;
        speechd)
	    [[ -e "/dev/speech" ]] && print "$@">/dev/speech
	    ;;
	*)
    esac
}

spell-char () {
    speak-string $zspeak_spell[${1}]
}

# All following functions use the above as a backend
# So all speech synthesizer specific tweaks should go above this
# separator, and all Zsh/ZLE/whatever specific modifications below.

speak-buffer () {
    speak-string $BUFFER
}

speak-current-character () {
    spell-char $BUFFER["$CURSOR"]
}

speak-help () {
    speak-string `bindkey|grep "^\"^\[v"|sed 's/\"\(.*\)\" \(.*\)/\1 invokes \2. /'|sed 's/^^\[\([a-zA-Z0-9]\)/Alt \1 plus /'`
}

speak-new-position () {
    zle .$WIDGET "$@"
    speak-current-character
}

[[ -o kshautoload ]] || speech-on "$@"
 
-- 
CYa,
   Mario <mlang@delysid.org>
Homepage(s): http://delysid.org | http://piss.at/

Theory is gray, but the golden tree of life is green.
		-- Goethe


             reply	other threads:[~2001-03-16 14:22 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-16 14:21 Mario Lang [this message]
2001-03-16 14:39 ` Peter Stephenson
2001-03-16 18:23 ` Bart Schaefer
2001-03-19 10:07 Sven Wischnowsky
2001-03-21 17:18 ` Mario Lang
2001-03-22  6:52   ` Bart Schaefer
2001-03-23  8:42     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=874rwtzteq.fsf@home.delysid.org \
    --to=mlang@home.delysid.org \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).