Chatterbox - STT / TTS / TTA project. Part 2

A home for all kinds of Puppy related projects
Message
Author
User avatar
H4LF82
Posts: 123
Joined: Tue 02 Oct 2012, 04:22

#21 Post by H4LF82 »

this isnt doing it either, but i think im getting closer...

Code: Select all

#!/bin/sh
cd /usr/bin
./pocketsphinx_continuous | while read LINE; do
case "$LINE" in
  $LINE > test.txt
done
"The wise know their weakness too well to assume infallibility; and he who knows most, knows best how little he knows." - Thomas Jefferson

User avatar
H4LF82
Posts: 123
Joined: Tue 02 Oct 2012, 04:22

#22 Post by H4LF82 »

this...

Code: Select all

#!/bin/sh
pocketsphinx_continuous | while read LINE; do
$LINE > test.txt  
done
...is a whole lot closer. still not right, but it does get sphinx running and makes some change to the txt file (everytime sphinx registers a word the files contents change i can tell because geany asks me to reload the more recent page) but it is still empty each time...so j still have a syntax error somewhere.

I will keep peckin away at it until i get it right. :)
"The wise know their weakness too well to assume infallibility; and he who knows most, knows best how little he knows." - Thomas Jefferson

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#23 Post by greengeek »

Bearing in mind I have no idea what I'm talking about - should the test.txt have more path info? Like /usr/bin/test.txt or something to ensure correct permissions? Or maybe there should be some quote marks " " somewhere?

And "case" / "esac" not required?

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#24 Post by greengeek »

H4LF82 wrote:

Code: Select all

#!/bin/sh
cd /usr/bin
./pocketsphinx_continuous | while read LINE; do
case "$LINE" in
  $LINE > test.txt
done
Just looking back at this code, is there an "esac" missing? (hope you don't mind my uneducated guesses.....)

amigo
Posts: 2629
Joined: Mon 02 Apr 2007, 06:52

#25 Post by amigo »

'case' must close with 'esac':

Code: Select all

case $SOME in
  *) : ;; #if more than one entry, then each should end with double';'
esac

User avatar
Keef
Posts: 987
Joined: Thu 20 Dec 2007, 22:12
Location: Staffordshire

#26 Post by Keef »

Just a small point, but if something is in /usr/bin/, you don't need to cd into it to run it (assuming it is executable).
Open any old terminal and type 'poc' then hit the tab key for autocompletion.

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#27 Post by greengeek »

I had a look at these resources:
http://unix.stackexchange.com/questions ... nto-a-file
and
http://unix.stackexchange.com/questions ... -to-stdout
and they seem to be trying to do something similar to what we are wanting. I tried following the program > /path/to/file syntax and got the following:

Code: Select all

#!/bin/sh
pocketsphinx_continuous  > /root/test.txt &
which DOES seem to create my /root/test.txt file and it does contain the text I want.

Couple of things to note:
1) The "READY" no longer displays in the pocketsphinx terminal (although that doesn't seem to stop it running...) and the rest of the text in the terminal does not display in thetext file (which is handy because it is only the decoded text just before the READY prompt that we want anyway...)
2) If I open the test.txt file with Geany I can keep selecting "File, Reload" to see the updated decoded words.
.
Attachments
pocketsphinx_text_trap.jpg
(169.03 KiB) Downloaded 685 times

User avatar
H4LF82
Posts: 123
Joined: Tue 02 Oct 2012, 04:22

#28 Post by H4LF82 »

oh NICE! that works...we can work with that!

gimme a moment. must have caffeine.
"The wise know their weakness too well to assume infallibility; and he who knows most, knows best how little he knows." - Thomas Jefferson

User avatar
H4LF82
Posts: 123
Joined: Tue 02 Oct 2012, 04:22

#29 Post by H4LF82 »

Just looking back at this code, is there an "esac" missing? (hope you don't mind my uneducated guesses.....)
'case' must close with 'esac':
how right you both are. im uneducated guessing here too, you understand...

it seems to me that after seeiing how this...

Code: Select all

#!/bin/sh
pocketsphinx_continuous  > /root/test.txt &
...creates information in the file, we need to add another line or two to that to omit the
READY....
Listening...
Stopped listening, please wait....
part.

i will start working on that next. :D
"The wise know their weakness too well to assume infallibility; and he who knows most, knows best how little he knows." - Thomas Jefferson

User avatar
H4LF82
Posts: 123
Joined: Tue 02 Oct 2012, 04:22

#30 Post by H4LF82 »

it seems like we need to use grep to search the test.txt file for our "spoken command"; someething like this....

Code: Select all

!/bin/sh
pocketsphinx_continuous  > /root/test.txt &
if grep -q "yes" /root/test.txt; then
     peasymp3autoplay /path/to/Music 
fi
done
..but of course, that code does not do it. evidently i am FANTASTIC at writing code that does not work!

any thoughts?
"The wise know their weakness too well to assume infallibility; and he who knows most, knows best how little he knows." - Thomas Jefferson

User avatar
Keef
Posts: 987
Joined: Thu 20 Dec 2007, 22:12
Location: Staffordshire

#31 Post by Keef »

Probably hundreds of better ways of doing this, but it does have some effect:

Code: Select all

 awk '/^0/  { print $2 }' ~/test.txt
This extracts the spoken command (assuming a single word).
It just finds a line beginning with a '0' eg 000000001:, then prints out the next field.
Contents of test.txt:

Code: Select all

READY....
Listening...
Stopped listening, please wait...
000000000: hello
READY....
Listening...
Stopped listening, please wait...
000000001: bye
READY....

Just outputting to test.txt, there will be several words, as the file gets constantly written to, so it probably needs to be done 'on the fly'.
(thats not genuine output BTW, not had chance to test recognition properly)

The word then needs passing to something like:

Code: Select all

case  $wot_u_said in 
        browser)
        defaultbrowser
        ;;
        shutdown)     
        shutdown
         ;;
  esac         
}

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#32 Post by greengeek »

I think what I would be wanting to do is this:

1) Identify the most recent instance of "READY" in the file (assuming the file may at times have pages of chatter in it...)
2) "Grab" the text that is found between that "READY" and the colon that precedes it.
3) Strip out any leading and trailing spaces.
4) Use the remaining text as our command keyword.
5) Clear the file.

I've got a bit of research to do... :-)

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#33 Post by greengeek »

Thanks Keef, I didn't spot that before I posted. I will have a tinker with your code tonight.

EDIT : Could your awk script be changed to allow it to detect the "READY" string and then grab the data field BEFORE it? (I'm thinking that would ensure we were not trying to grab the data field before it was finished being written)

EDIT2 : Is there a risk involved in trying to have two programs accessing the same file? ie: what if sphinx is trying to write new data to the file while I am trying to use another program to clear the data. Do I need to handle the potential conflict resolution or does the system code handle that somehow by making one program wait politely? (and if so - how does it determine which program gets the priority?)

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#34 Post by greengeek »

I gave your awk code a try and it works well on a live file - I decided to change it to:

Code: Select all

 awk '/^0000/  { print $2 }' ~/test.txt
just so there was less chance of it picking up any other "0" that happens to get thrown in there (probably unnecessary but I feel it's more selective to look for the "0000" string)

So now the problem is to clear the file at the right time so that only a single instance is captured (last response only). (Or how to discard everything except the last line captured...?)

All I can do is have a good look at Grep, Awk and Sed and try to figure which is the best way to force discarding of everything except the most recent command word.

All suggestions truly welcome.

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#35 Post by greengeek »

Well, I've got some steps that seem to work, but I haven't combined them into an elegant form yet. Here are the steps I have been trying just as single scripts:

This first step gets pocketsphinx_continuous to run and build a chatdump file:

Code: Select all

#!/bin/sh
pocketsphinx_continuous  > /root/chatdump.txt &
This creates a raw "chatdump" file containing things like this:

Code: Select all

Listening...
Stopped listening, please wait...
000000001: Out house
READY....
Listening...
Stopped listening, please wait...
000000002: program
READY....
Listening...
Stopped listening, please wait...
000000003: beginning
READY....
Then I use Keefs awk to extract the recognised command word from each valid line as follows:

Code: Select all

#!/bin/bash
awk '/^0000/  { print $2 }' /root/chatdump.txt > /root/chat_extract.txt &
This creates a file called chat_extract.txt containing the following:

Code: Select all

Out house
program
beginning
Then I extract just the final word from this file as follows:

Code: Select all

#!/bin/bash
sed '$!d'  /root/chat_extract.txt > /root/chat_command.txt &
Which extracts the final spoken command (in this case "beginning") and lists that single word in a file called chat_command.txt

Of course this is limiting commands to a single word, but that is where I want to start. (Then the TTA protocol/menu can easily reject any meaningless command and only permit a small range of actions that it is programmed for)

At least by picking out the final word in the file I don't need to panic about clearing the chatdump file regularly yet.

Don't laugh folks - at least I feel like I'm making progress. Baby steps!
.
Last edited by greengeek on Tue 15 Oct 2013, 01:02, edited 1 time in total.

User avatar
H4LF82
Posts: 123
Joined: Tue 02 Oct 2012, 04:22

#36 Post by H4LF82 »

i dont think anybody is laughing greengeek. that looks awesome.

im trying just to keep up with your baby steps! your baby steps seem herculean compared to my baby steps.

im off to play with this now and see what little help i can offer, if any.
:)
"The wise know their weakness too well to assume infallibility; and he who knows most, knows best how little he knows." - Thomas Jefferson

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#37 Post by greengeek »

If you are succeeding in getting some degree of accurate word recognition but want to improve the overall accuracy the easiest way to do this is by running a reduced vocabulary. That way the program does not have to try to distinguish the difference between words or phrases that sound similar.
eg:
If the program has a big vocabulary to chose from the word "read" could be misinterpreted as any of the following:
red
reed
reared
wreck
wrecked
wreaked etc etc

If your vocab file only contains the word "read" then that is what will be chosen when you say "read"

To achieve this reduced vocabulary you have to make a "corpus.txt" file as discussed two thirds of the way down the page in this tutorial:
http://cmusphinx.sourceforge.net/wiki/tutoriallm

Here is a sample corpus.txt file:

Code: Select all

open browser
new e-mail
forward
backward
next window
last window
open music player
Out house
negative
right
close
Once you have set up your corpus.txt file it is necessary to get it compiled. I did this via the online webservice referred to in the tutorial. Simply go here:
http://www.speech.cs.cmu.edu/tools/lmtool-new.html
and click the "Browse" button and upload your corpus.txt

It will quickly be compiled and you will be offered a tar.gz file which contains various necessary files which will all have a numeric prefix. Save this tarball and extract it somewhere you can find the files later.
I ended up with a collection of files as follows:
6718.dic
6718.lm
6718.log_pronounce
6718.sent
6718.vocab
(I guess your number prefix will be different...)

Copy all of these files into the /usr/share/pocketsphinx/model/lm directory (see attached pic)

Start pocketsphinx with the following syntax:

Code: Select all

pocketsphinx_continuous -lm 6718.lm -dict 6718.dic
(obviously substituting your own number prefix instead of 6718...)

Pocketsphinx will now run as normal but without so many confusing options to choose from if it is struggling to make out which word you are saying. This seems to work quite well so it suggests that we would be able to create a very useful corpus.txt file which would be applicable to a puppy-specifc menu system.
.
Attachments
sphinx_vocab_files_in_lm_dir_.jpg
(81.88 KiB) Downloaded 330 times

User avatar
H4LF82
Posts: 123
Joined: Tue 02 Oct 2012, 04:22

#38 Post by H4LF82 »

that is outstanding greengeek! I was wondering how we were going to deal with that HUGE vocabulary. I will begin working on a "one size fits all" word-base today for non-visually-accessible options that hopefully will come a lot closer to fitting the bill than is currently available on other platforms.

And, for the record, i am still reeling from the shock and awe of the fine code work youve got going on here. I have nothing to compare it to, as it is unexampled.

Thank you, greengeek. I anxiously await your next words of instruction on needles and pins.

:D
"The wise know their weakness too well to assume infallibility; and he who knows most, knows best how little he knows." - Thomas Jefferson

User avatar
greengeek
Posts: 5789
Joined: Tue 20 Jul 2010, 09:34
Location: Republic of Novo Zelande

#39 Post by greengeek »

Thanks for the kind words H4LF82. This is rather a enjoyable project and I am learning quite a bit. After doing a bit of code googling I have decided to change the order of the steps I was using:

Rather than use awk to list all of the command words from the chatdump file I have decided to firstly use sed to grab only the last 3 lines of that file, then pipe that output to awk to identify the single keyword. So my new code is:

Code: Select all

#!/bin/bash
sed -e :a -e '$q;N;4,$D;ba' /root/chatdump.txt | awk '/^0000/  { print $2 }' > chat_command.txt &
My next step is to work out how to pipe the awk output to a variable (instead of a file) then I can compare it to my "preferred answer" (ie "YES") and use that directly to trigger my final action

User avatar
Keef
Posts: 987
Joined: Thu 20 Dec 2007, 22:12
Location: Staffordshire

#40 Post by Keef »

Code: Select all

 voice_prompt=`sed -e :a -e '$q;N;4,$D;ba' /root/chatdump.txt | awk '/^0000/  { print $2 }'` 
..seems to work. (try #echo $voice_prompt) Can't test it properly as only on an old laptop with built-in mike, and speech recognition is a little ropey.
Not managed to bolt all this together - there is always a delay from the speech until something gets written to the temp file. Most solutions to this seem to be done in Python, which is all Parseltongue to me. Not that my Bash is much better.

Ooh err.... got Leafpad to launch by coughing!!

run

Code: Select all

# pocketsphinx_continuous  > chatdump.txt
in one terminal,

then run this script in another:

Code: Select all

#!/bin/bash
while [ "$voice_prompt" != "quit"  ] ; do

 voice_prompt=`sed -e :a -e '$q;N;4,$D;ba' chatdump.txt | awk '/^0000/  { print $2 }'`

# Line below just for testing:
echo $voice_prompt 

# Change "edit" to what ever works best.

if [ "$voice_prompt" == "edit" ]; then 
   exec leafpad
  
fi


done
I just used "i" as the keyword, as recognition is so poor. I've tidied up my very messy code to post it, so may be the odd error.

Post Reply