WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: TTS for underlined text (WORK!)  (Read 4869 times)

Offline vinnie

  • Hero Member
  • *****
  • Posts: 1187
  • HandMace informatic works
TTS for underlined text (WORK!)
« on: June 17, 2013, 10:23:21 AM »
Today i make a script to automatically read what is underlined after pressing a shortcut

The script is this:
Code: [Select]
tce-load -i espeak xclip &>/dev/null


clip=`xclip -o`
lang="it"
if [[ $1 = en ]]; then
    lang="en"
fi


if [[ `echo "$clip" | cut -c 1-8` = "file:///" ]]
    then #if browser link
        if [[ `echo "$clip" | tail -c 6` = ".html" ]] || [[ `echo "$clip" | tail -c 5` = ".htm" ]]
            then #if is webpage
                echo -e "\nweb page\n"
                espeak -v "$lang" -s 150 -a 200 -g 5 --punct="." -k10 -m -f `echo "$clip" | sed -e "s/^file:\/\///g"` &>/dev/null
            else #if isn't webpage
                echo -e "\ntext file\n"
                espeak -v "$lang" -s 150 -a 200 -g 5 --punct="." -k10 -f `echo "$clip" | sed -e "s/^file:\/\///g"` &>/dev/null
        fi
    elif [[ `echo "$clip" | cut -c 1-7` = "http://" ]] || [[ `echo "$clip" | cut -c 1-4` = "www." ]]
        then #if is link
            echo -e "\nhyperlink\n"
            curl -s "$clip" | espeak -v "$lang" -s 150 -a 200 -g 5 --punct="." -k10 -m
    else  #if isn't browser link
        if [ -f "$clip" ]
            then #if is file
                echo -e "\ntext file\n"
                espeak -v "$lang" -s 150 -a 200 -g 5 --punct="." -k10 -f "$clip" &>/dev/null
            else #if is not file
                echo -e "\nread direct\n"
                espeak -v "$lang" -s 150 -a 200 -g 5 --punct="." -k10 "$clip" &>/dev/null
        fi
fi


return 0

I used the keybindings of enlightenment to start the script after highlighting the text; win+s to read the text in Italian and win+d to read it in English

However, I would use actkbd to make the shortcut more universal, but I was not able to do so.
In order i have:
1) downloaded actkbd
2) used xev to find the keycode of the keys win, s and d (in my case 115, 39 and 40)
3) insert this configuration in /usr/local/etc/actkbd.conf file:
Code: [Select]
#win+s
115+39:key:exec:~/.local/bin/_read_script
115+40:key:exec:~/.local/bin/_read_script en
4)start the daemon with sudo actkbd -d /dev/input/event1 -D
5)try the shortcut that however does yet not work

What little I knew of actkbd I read in this topic, someone could give me a hand?
« Last Edit: June 19, 2013, 08:56:02 AM by vinnie »

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: TTS for underlined text
« Reply #1 on: June 17, 2013, 03:34:32 PM »
- actkbd doesn't use X keycodes, it uses raw keycodes. Close X, and use showkey from the linux console.
- make sure event1 is the right device, use the function mentioned in the thread you linked if unsure
The only barriers that can stop you are the ones you create yourself.

Offline vinnie

  • Hero Member
  • *****
  • Posts: 1187
  • HandMace informatic works
Re: TTS for underlined text
« Reply #2 on: June 18, 2013, 07:14:13 AM »
Ok, thanks curaga, I followed your advice but I have not been able to make it still work

actkbd.conf after retrieve keycodes with showkey
Code: [Select]
#win+s win+d win+f
125+31:key:exec:~/.local/bin/_read_script
125+32:key:exec:~/.local/bin/_read_script en
125+33:key:exec:~/.local/bin/_read_script end

actkbd_start
Code: [Select]
#!/bin/sh

getKeyEventDevice() {
e=0
for i in /sys/class/input/input*/name; do
  if grep -q "eyboard" $i; then break; fi
  e=`busybox expr "$e" + 1`
done
#[ $e > 0 ] || exit 1
[ $e -gt 0 ] || exit 1
echo /dev/input/event$e
}

event=`getKeyEventDevice`

sudo killall actkbd && sleep 1
sudo actkbd -d $event -D

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: TTS for underlined text
« Reply #3 on: June 18, 2013, 07:58:14 AM »
One more thing is that actkbd runs as root. Root by default doesn't have access to your X session, and DISPLAY may not be set either. So unless you give those rights, xclip can't access the clip board.
The only barriers that can stop you are the ones you create yourself.

Offline vinnie

  • Hero Member
  • *****
  • Posts: 1187
  • HandMace informatic works
Re: TTS for underlined text
« Reply #4 on: June 18, 2013, 08:33:08 PM »
I did some tests and I think it's a bad configuration of actkbd and not a xclip problem:

test of xclip used by root:
Code: [Select]
tc@box:~$ sudo xclip -o
some underlined text tc@box:~$
tc@box:~$ sudo su
root@box:~# xclip -o
some underlined text root@box:~#
root@box:~#


I tried to set other shorcut in actkbd.conf with ctrl and alt using an event of aplay, but does not work
Code: [Select]
#aplay ctrl29 z44 alt56
56+49:key:exec:aplay /usr/local/share/sounds/purple/alert.wav
56+44:key:exec:aplay /usr/local/share/sounds/purple/alert.wav
29+48:key:exec:aplay /usr/local/share/sounds/purple/alert.wav

what i can have missed?

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: TTS for underlined text
« Reply #5 on: June 19, 2013, 05:52:20 AM »
If the sounds don't play either, I don't think the events are getting there. Try actkbd's debug mode.
The only barriers that can stop you are the ones you create yourself.

Offline vinnie

  • Hero Member
  • *****
  • Posts: 1187
  • HandMace informatic works
Re: TTS for underlined text
« Reply #6 on: June 19, 2013, 06:25:00 AM »
Is this actkbd -n -s  the "debug mode"?
Code: [Select]
tc@box:~$ actkbd -n -s
Error: could not open /dev/input/event1: Permission denied
tc@box:~$ sudo actkbd -n -s
asd test test^C
tc@box:~$

i make this test with actkbd-d /dev/input/event5-D: in start:
Code: [Select]
tc@box:~$ ps aux | grep event
18108 root     actkbd -d /dev/input/event5 -D
18589 tc       grep event

this mode should return the keycodes? I do not seem to do it, for the keys like ctrl and alt not even write anything

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 11044
Re: TTS for underlined text
« Reply #7 on: June 19, 2013, 06:33:00 AM »
sudo actkbd -s -d /dev/input/eventFOO
The only barriers that can stop you are the ones you create yourself.

Offline vinnie

  • Hero Member
  • *****
  • Posts: 1187
  • HandMace informatic works
Re: TTS for underlined text
« Reply #8 on: June 19, 2013, 06:37:47 AM »
Code: [Select]
tc@box:~$ sudo actkbd -s -d /dev/input/eventFOO
Error: failed to read event from /dev/input/eventFOO: Successtc@box:~$
tc@box:~$

Offline vinnie

  • Hero Member
  • *****
  • Posts: 1187
  • HandMace informatic works
Re: TTS for underlined text
« Reply #9 on: June 19, 2013, 06:56:28 AM »
foo... I misunderstood!

Code: [Select]
tc@box:~$ sudo actkbd -s -d /dev/input/event5 
das^C
tc@box:~$ ^C
tc@box:~$
tc@box:~$ kill
kill      killall   killall5 
tc@box:~$ sudo killall actkbd
tc@box:~$
tc@box:~$ sudo actkbd -s -d /dev/input/event5
12^C
tc@box:~$ sudo actkbd -s -d /dev/input/event0
adsw^C
tc@box:~$ sudo actkbd -s -d /dev/input/event1
asdd^C
tc@box:~$ sudo actkbd -s -d /dev/input/event2
asasd^C
tc@box:~$ sudo actkbd -s -d /dev/input/event3
sad^C
tc@box:~$ sudo actkbd -s -d /dev/input/event4
Keys: 31
sKeys: 30+31
aKeys: 30+31+32
dKeys: 31
sKeys: 30+31
aKeys: 29
Keys: 29
Keys: 56
Keys: 29
Keys: 29+46
^C
tc@box:~$

BINGO!
strangely the startup script gave me as a keyboard event5  and not event4

If i press aplay shortcut in debug mode I get an error:
Code: [Select]
aplay: playback:2455: read error
if I try to use it out of the debug mode with the event4 launched, I do not hear anything anyway.
The configuration of the command in /usr/local/etc/actkd.conf is this for example

Code: [Select]
56+49:key:exec:su tc -c -l aplay /usr/local/share/sounds/purple/alert.wav &
setting commands  "aplay /usr/local/share/sounds/purple/alert.wav" in debug mode works!
but only in debug mode!!! with daemon started (sudo actkbd -d /dev/input/event4 -D) the shortcut does not work  :O
« Last Edit: June 19, 2013, 07:05:39 AM by vinnie »

Offline vinnie

  • Hero Member
  • *****
  • Posts: 1187
  • HandMace informatic works
Re: TTS for underlined text
« Reply #10 on: June 19, 2013, 08:55:09 AM »
Scuse me for multiposting but now work!
of crucial importance was to test all the events with the debug mode of actkbd until they were pulled out the keycodes

This is the exec script in /home/tc/.X.d/:
Code: [Select]
sudo actkbd -d /dev/input/event4 -D
This is the /usr/local/etc/actkbd.conf file:
Code: [Select]
#win+s win+d win+f
125+31:key:exec:su tc -c -l "/home/tc/.local/bin/_leggi_clipboard" &
125+32:key:exec:su tc -c -l "/home/tc/.local/bin/_leggi_clipboard en" &
125+33:key:exec:su tc -c -l "/home/tc/.local/bin/_leggi_clipboard end" &

#win+2 win+3
125+2:key:exec:su tc -c -l "/home/tc/.local/bin/_touchpad on" &
125+3:key:exec:su tc -c -l "/home/tc/.local/bin/_touchpad off" &

#asd  ctrl29 z44 alt56
125+48:key:exec:su tc -c -l "aplay -d 1 /usr/local/share/sounds/alsa/Noise.wav" &

And this is updated script for read text:
Code: [Select]
tce-load -i espeak xclip &>/dev/null

clip=`xclip -o`
lang="it"
if [[ $1 = en ]]; then
    lang="en"
fi


if [[ $1 = end ]]; then
    echo -e "\nexit\n"
    killall espeak
    rm -rf ./espeak
    exit
fi


if [[ `echo "$clip" | cut -c 1-8` = "file:///" ]]
    then #if browser link
        if [[ `echo "$clip" | tail -c 6` = ".html" ]] || [[ `echo "$clip" | tail -c 5` = ".htm" ]]
            then #if is webpage
                echo -e "\nweb page\n"
                espeak -v "$lang" -s 150 -a 200 -g 5 --punct="." -k10 -m -f `echo "$clip" | sed -e "s/^file:\/\///g"` &>/dev/null
            else #if isn't webpage
                echo -e "\ntext file\n"
                espeak -v "$lang" -s 150 -a 200 -g 5 --punct="." -k10 -f `echo "$clip" | sed -e "s/^file:\/\///g"` &>/dev/null
        fi
    elif [[ `echo "$clip" | cut -c 1-7` = "http://" ]] || [[ `echo "$clip" | cut -c 1-4` = "www." ]]
        then #if is link
            echo -e "\nhyperlink\n"
            curl -s "$clip" | espeak -v "$lang" -s 150 -a 200 -g 5 --punct="." -k10 -m
    else  #if isn't browser link
        if [ -f "$clip" ]
            then #if is file
                echo -e "\ntext file\n"
                espeak -v "$lang" -s 150 -a 200 -g 5 --punct="." -k10 -f "$clip" &>/dev/null
            else #if is not file
                echo -e "\nread direct\n"
                espeak -v "$lang" -s 150 -a 200 -g 5 --punct="." -k10 "$clip" &>/dev/null
        fi
fi

return 0

In sum, with: win+s the text is read in italian, win+d in english and win+f each reading  text being stopped.

there is only one small problem, the programs still intercept the key combination, I think I should use the attribute grab/ungrab but would become too complex to use.
If you have any hint on this, I am listening.

Thanks Curaga