Puppy Linux Discussion Forum Forum Index Puppy Linux Discussion Forum
Puppy HOME page : puppylinux.com
"THE" alternative forum : puppylinux.info
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

The time now is Wed 26 Nov 2014, 07:18
All times are UTC - 4
 Forum index » Advanced Topics » Puppy Projects
Chatterbox - STT / TTS / TTA project. Part 2
Moderators: Flash, JohnMurga
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
Page 3 of 6 Posts_count   Goto page: Previous 1, 2, 3, 4, 5, 6 Next
Author Message
Keef


Joined: 20 Dec 2007
Posts: 646
Location: Staffordshire

PostPosted: Sun 13 Oct 2013, 17:42    Post_subject:  

Probably hundreds of better ways of doing this, but it does have some effect:
Code:
 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:
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:
case  $wot_u_said in
        browser)
        defaultbrowser
        ;;
        shutdown)     
        shutdown
         ;;
  esac         
}
Back to top
View user's profile Send_private_message 
greengeek

Joined: 20 Jul 2010
Posts: 2669
Location: New Zealand

PostPosted: Sun 13 Oct 2013, 17:47    Post_subject:  

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... Smile
Back to top
View user's profile Send_private_message 
greengeek

Joined: 20 Jul 2010
Posts: 2669
Location: New Zealand

PostPosted: Sun 13 Oct 2013, 17:55    Post_subject:  

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?)
Back to top
View user's profile Send_private_message 
greengeek

Joined: 20 Jul 2010
Posts: 2669
Location: New Zealand

PostPosted: Mon 14 Oct 2013, 06:07    Post_subject:  

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

Code:
 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.
Back to top
View user's profile Send_private_message 
greengeek

Joined: 20 Jul 2010
Posts: 2669
Location: New Zealand

PostPosted: Mon 14 Oct 2013, 15:14    Post_subject:  

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:

#!/bin/sh
pocketsphinx_continuous  > /root/chatdump.txt &


This creates a raw "chatdump" file containing things like this:
Code:
Listening...
Stopped listening, please wait...
000000001: kitchen
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:
#!/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:
kitchen
program
beginning


Then I extract just the final word from this file as follows:
Code:
#!/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!
.

Edited_time_total
Back to top
View user's profile Send_private_message 
H4LF82


Joined: 02 Oct 2012
Posts: 124

PostPosted: Mon 14 Oct 2013, 19:26    Post_subject:  

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.
Smile

_________________
"The wise know their weakness too well to assume infallibility; and he who knows most, knows best how little he knows." - Thomas Jefferson
Back to top
View user's profile Send_private_message 
greengeek

Joined: 20 Jul 2010
Posts: 2669
Location: New Zealand

PostPosted: Tue 15 Oct 2013, 14:55    Post_subject:  

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:
open browser
new e-mail
forward
backward
next window
last window
open music player
kitchen
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:
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.
.
sphinx_vocab_files_in_lm_dir_.jpg
 Description   
 Filesize   81.88 KB
 Viewed   238 Time(s)

sphinx_vocab_files_in_lm_dir_.jpg

Back to top
View user's profile Send_private_message 
H4LF82


Joined: 02 Oct 2012
Posts: 124

PostPosted: Wed 16 Oct 2013, 10:01    Post_subject:  

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.

Very Happy

_________________
"The wise know their weakness too well to assume infallibility; and he who knows most, knows best how little he knows." - Thomas Jefferson
Back to top
View user's profile Send_private_message 
greengeek

Joined: 20 Jul 2010
Posts: 2669
Location: New Zealand

PostPosted: Wed 16 Oct 2013, 12:15    Post_subject:  

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:
#!/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
Back to top
View user's profile Send_private_message 
Keef


Joined: 20 Dec 2007
Posts: 646
Location: Staffordshire

PostPosted: Wed 16 Oct 2013, 13:27    Post_subject:  

Code:
 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:
# pocketsphinx_continuous  > chatdump.txt
in one terminal,

then run this script in another:
Code:

#!/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.
Back to top
View user's profile Send_private_message 
greengeek

Joined: 20 Jul 2010
Posts: 2669
Location: New Zealand

PostPosted: Wed 16 Oct 2013, 14:02    Post_subject:  

Thanks keef!

ps: I just realised this whole project to kick off randomly playing music is only going to work if I wear headphones to isolate my microphone from the speakers. I just had Katy Perry filling up my chatdump....
Very Happy
Back to top
View user's profile Send_private_message 
H4LF82


Joined: 02 Oct 2012
Posts: 124

PostPosted: Wed 16 Oct 2013, 15:00    Post_subject:  

...this is what makes an "OFF"switch so handy. for this moment, its not a big deal because we are still working out form and function...but ultimately an off switch will be vital.

i will be using a bluetooth headset, and even this (which cannot hear its own speaker) will need a software-side mute button in addition to the actual physical hardware MUTE button on the headset itself.

that is my 2 cents...

Very Happy
edit:

Code:
amixer set Master 0 mute


Code:
amixer set Master 35 unmute
[/code]
_________________
"The wise know their weakness too well to assume infallibility; and he who knows most, knows best how little he knows." - Thomas Jefferson
Back to top
View user's profile Send_private_message 
greengeek

Joined: 20 Jul 2010
Posts: 2669
Location: New Zealand

PostPosted: Wed 16 Oct 2013, 15:49    Post_subject:  

H4LF82 wrote:
Code:
amixer set Master 0 mute
amixer set Master 35 unmute
Is that muting mic only? (ie: no effect on speakers?)

so...
- mute mic
- ask question
- unmute mic
- process voice_prompt
- possibly re-mute mic
- take action
- prepare next question
- repeat process
Back to top
View user's profile Send_private_message 
H4LF82


Joined: 02 Oct 2012
Posts: 124

PostPosted: Wed 16 Oct 2013, 16:27    Post_subject:  

that mutes speakers ....

look here to control others...
Code:

sh-4.1# amixer -h
Usage: amixer <options> [command]

Available options:
  -h,--help       this help
  -c,--card N     select the card
  -D,--device N   select the device, default 'default'
  -d,--debug      debug mode
  -n,--nocheck    do not perform range checking
  -v,--version    print version of this program
  -q,--quiet      be quiet
  -i,--inactive   show also inactive controls
  -a,--abstract L select abstraction level (none or basic)
  -s,--stdin      Read and execute commands from stdin sequentially

Available commands:
  scontrols       show all mixer simple controls
  scontents     show contents of all mixer simple controls (default command)
  sset sID P      set contents for one mixer simple control
  sget sID        get contents for one mixer simple control
  controls        show all controls for given card
  contents        show contents of all controls for given card
  cset cID P      set control contents for one control
  cget cID        get control contents for one control
sh-4.1# amixer scontrols
Simple mixer control 'Master',0
Simple mixer control 'PCM',0
Simple mixer control 'IEC958',0
Simple mixer control 'IEC958 Default PCM',0
Simple mixer control 'Capture',0
Simple mixer control 'Digital',0
Simple mixer control 'Input Source',0
Simple mixer control 'Mux',0



so for the mic youll probably do something like

Code:
amixer set Capture 0 mute


or...
Code:

amixer set Input Source 35 unmute


and to be clear...32 is 100% volume on any control... 16 is half (50%)

35 is overkill for LOUD

_________________
"The wise know their weakness too well to assume infallibility; and he who knows most, knows best how little he knows." - Thomas Jefferson
Back to top
View user's profile Send_private_message 
H4LF82


Joined: 02 Oct 2012
Posts: 124

PostPosted: Wed 16 Oct 2013, 19:22    Post_subject:  

you may also find it helpful to use the sleep/usleep command and an audible "ding.wav" to mark the "beginning" and the ""end" of the voice-prompt window, if timing or "lag" is an issu and to make no mistake that the machine is listening/stopped listening and is processing a valid input option/choking on an invalid response input.

XSE from the xdotool package would allow you to assign a "hotkey" to a specific functiom...ie..start recording imput by holding down the left shift key for 4 seconds opens the voice-prompt...but im having issue with xse and dont know another way to emulate keystrokes or assign value to them...

maybbe an if statement with some command ive yet to learn....
Code:

 if RIGHT_SHIFT DOWN => 5SECONDS, run listen.sh


sorry i cant be more help...

edit--i meant Xaut not xse or xdotool---sorry.

_________________
"The wise know their weakness too well to assume infallibility; and he who knows most, knows best how little he knows." - Thomas Jefferson
Back to top
View user's profile Send_private_message 
Display_posts:   Sort by:   
Page 3 of 6 Posts_count   Goto page: Previous 1, 2, 3, 4, 5, 6 Next
Post_new_topic   Reply_to_topic View_previous_topic :: View_next_topic
 Forum index » Advanced Topics » Puppy Projects
Jump to:  

Rules_post_cannot
Rules_reply_cannot
Rules_edit_cannot
Rules_delete_cannot
Rules_vote_cannot
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group
[ Time: 0.1165s ][ Queries: 12 (0.0057s) ][ GZIP on ]