HOW2 intrpt/reset?

I'm using a rPi every day to `aplay *.wav` files which are derived
from TextToSpeech. [as if I was blind].
By powering off during the particular , or during one of
2 prompts after it's played, I can select 1 of 3 effects on the
latest played *
.wav on the stack of *.wav files.
This primitive method controlled by only an on/off-switch, has worked
hundred of times, but needs a re-boot-wait, after each power-down.
Now I'd like to refine the control and remove the wait time, by
having one more switch.
Presently the control is via a simple bash-script, which uses the idea
1. start playing the TTS or prompt;
2. rename/re-classify the TTS according to the prompt;
3. restore the TTS's name [IF power was not cut between 2 & 3].
What is a simple way to detect a switch during the prompt?
Simple by hardware and by just extending the existing script.
== TIA.
Reply to
Unknown
Loading thread data ...
Unknown schrieb:
Hello Unkonwn!
My Raspberry Pi runs without display all the time. I use espeak to output audio instead of showing text.
I have not fully uderstood your question but I can tell you what implemented to control my Raspberry without display usage.
I use a single TACT switch, may be not so different from yours. A script loops every second which checks the status of the key. A simple state machine checks if the key has been pressed. If so the next possible action is outputted by espeak. If the key is not pressed after one second the next action is performed. If the key is kept pressed the next action is outputted by espeak and so on.
The actions are as simple as playing different internet radio stations or to shut down the Raspberry. If the last action is proposed everything starts from the beginning. Just the option to shut down is always the first proposed item.
I have dismounted the cinch connector to have space for the switch. May be this is useful as an idea. Of course more switches give more flexibility.
Kind regards,
Christoph
Reply to
Christoph Brinkhaus
Can `espeak` synthesise text, or it it just a play-back? Do you know of any German text sythesizers for linux?
OK, it's not easy to understand other's explanation, so I'll paste my little script, and hope to see yours too.
That 'sounds' good. But if I want to have control WHILE `aplay a.wav` is running ....? Perhaps aplay can pause? IF KeyPressed THEN {pauseAplay; Cycle:PromptAccept} For selecting alternatives you need: 1. knowledge of which item is offered 2. ability of signal "yes I'll have that one".
Since the 'menu' is offered in time sequence, you need an audio prompt to know that item N is being offered. But probably `aplay` is not available to prompt, because it's been suspended/paused [assuming THAT is possible]. Or perhaps another invocation of `aplay` is available?
Isn't 'cinch' just a manufacture's name? Which connector? Can you paste your code, especially for detecting the switch? Here's mine:---- ##!/bin/bash
sPlaySkip() { if [ -f $1.wav ]; then mv $1.wav Q$1.wav sync aplay Q$1.wav mv Q$1.wav $1.wax sync # mv $1.wav $1.wax v->Q->x->v aplay Prompt.wav mv $1.wax $1.wav sync
aplay SafeLand.wav fi }
# Need to append means can't have: exit 0
sPlaySkip saLaw1 sPlaySkip mythIraq sPlaySkip saLaw3 sPlaySkip QQssl sPlaySkip saLaw2 sPlaySkip grwthDivrt sPlaySkip saLaw4 sPlaySkip SpcTCmts splay Eskom sPlaySkip saLaw5 sPlaySkip QQNR3 ===================================== It was interesting to note that code for: 1. start playing prompt 2. rename file did NOT `rename file` while the prompt-playing, unless `sync` after `2. rename file`. Apparently because file updating is done when it suits linux.
==TIA.
Reply to
Unknown
$ whatis espeak espeak (1) - A multi-lingual software speech synthesizer.
On my ubuntu laptop I have to go through aplay, I think that is because of pulseaudio:
--stdout | aplay
Reply to
Stefan Enzinger
Unknown schrieb:
Hello Unknown and Stefan!
This has answered my Stefan already. Thank you.
I have no idea if aplay can pause. I use my Raspberry for listening internetradio with mplayer. If I want to change the station mplayer is stopped and re-started. I am not sure if this is possible with aplayer, or may be to re-start at some known position.
This is the job of espeak. BTW: If mplayer would kept running the audio of espeak would just be added on top of the mplayer output. It is a matter of volume balance which is better audible.
This is the connector next to the 3.5mm audio jack. It is round, has some metal outside and an inner connector.
This is the code to enable the gpios where the switch is connected to:
#!/bin/sh
echo "17" > /sys/class/gpio/export echo "in" > /sys/class/gpio/gpio17/direction
echo "22" > /sys/class/gpio/export echo "out" > /sys/class/gpio/gpio22/direction echo "0" > /sys/class/gpio/gpio22/value chown pi /sys/class/gpio/gpio22/value
GPIO22 is an output but not used. It has been used for testing only.
This is the state machine which runs all the time. I have added some comments inline with ###.
status=0 radio=1 msg=`/usr/bin/cut -f 1 -d# radio.txt | /usr/bin/head -n $radio | /usr/bin/tail -n 1` addr=`/usr/bin/cut -f 2 -d# radio.txt | /usr/bin/head -n $radio | /usr/bin/tail -n 1` lnk=`/usr/bin/cut -f 3 -d# radio.txt | /usr/bin/head -n $radio | /usr/bin/tail -n 1` output=" 2> /dev/null | tr \"\\r\" \"\\n\" | grep --line-buffered -v -e \"^A:\" -e \"^Cache fill\" >> /run/shm/out.txt & " echo $msg | espeak --stdin 2> /dev/null ### some radio stations can be contacted directly and some offer a link. if test -z $lnk then player="/usr/bin/mplayer $addr" else id=`/usr/bin/wget -q -T 5 -O - --no-cookies $lnk| grep pls| head -n 1 | \ sed -e s/.*href=// | sed -e s/onclick.*$// | sed -e s/'//g | sed -e s/\ $//` player="/usr/bin/mplayer \"
formatting link
$id\"" fi ### Here is output to a file system in RAM. echo $player > /run/shm/out.txt eval $player$output
while true do ### k is the status of the key. k=`cat /sys/class/gpio/gpio17/value` case $status in 0) # Check input by hardware key if (($k==0)) then PID=`pgrep mplayer` kill $PID 2> /dev/null echo "shutdown" | espeak --stdin 2> /dev/null status=1 ### the gpio22 is not used. It could be an LED or so. echo '0' > /sys/class/gpio/gpio22/value fi # Check input from web server if test -r /run/shm/tuning.txt then PID=`pgrep mplayer` kill $PID 2> /dev/null radio=`cat /run/shm/tuning.txt` unlink /run/shm/tuning.txt msg=`/usr/bin/cut -f 1 -d# radio.txt | /usr/bin/head -n $radio | /usr/bin/tail -n 1` echo $msg | espeak --stdin 2> /dev/null status=3 fi ;; 1) if (($k==0)) then status=2 else echo "shutdown now" | espeak --stdin 2> /dev/null sudo halt fi ;; 2) if (($k==0)) then radio_max=`wc -l < radio.txt 2> /dev/null` radio=$((radio+1)) if (($radio==$radio_max+1)) then radio=1 fi msg=`/usr/bin/cut -f 1 -d# radio.txt | /usr/bin/head -n $radio | /usr/bin/tail -n 1` echo $msg | espeak --stdin 2> /dev/null else status=3 ### the gpio22 is not used. It could be an LED or so. echo '1' > /sys/class/gpio/gpio22/value fi ;; 3) msg=`/usr/bin/cut -f 1 -d# radio.txt | /usr/bin/head -n $radio | /usr/bin/tail -n 1` addr=`/usr/bin/cut -f 2 -d# radio.txt | /usr/bin/head -n $radio | /usr/bin/tail -n 1` lnk=`/usr/bin/cut -f 3 -d# radio.txt | /usr/bin/head -n $radio | /usr/bin/tail -n 1` if test -z $lnk then player="mplayer $addr" else id=`/usr/bin/wget -q -T 5 -O - --no-cookies $lnk| grep pls| head -n 1 | \ sed -e s/.*href=// | sed -e s/onclick.*$// | sed -e s/'//g | sed -e s/\ $//` player="mplayer \"
formatting link
$id\"" fi status=0 echo $player > /run/shm/out.txt eval $player$output ;; esac ### The script runs every 500ms. sleep 0.5 Done
Kind regards,
Christoph
Reply to
Christoph Brinkhaus
OK. If espeak can read-the-newspaper-to-me while I'm lying-down; like Festival does, I'd try it. But investigating TextToSpeech is a non-trivial job.
OK, your code gave me the idea to try . bash is rather complex; so I'm puting some of the man & info to TTS, to listen to. "unix" is a spoof on the name of "Multics" which was so complex that it failed.
OK, I have difficulty in accepting the multiproc: several can talk .
We call it 'RCA'. It's gives me a good display on a 1970's b/w monitor.
Great! I think I've got a record of which physical pins those are.
Very nice, Thanks!
Reply to
fld

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.