Re: [Tutor] a Pygtk question sort of

2013-01-12 Thread ALAN GAULD
Forwarding to the List

Pleae use ReplyAll for list responses.

 
Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/




 From: richard kappler richkapp...@gmail.com
To: Alan Gauld alan.ga...@btinternet.com 
Sent: Saturday, 12 January 2013, 2:15
Subject: Re: [Tutor] a Pygtk question sort of
 




I'm not sure what you mean by down pretty hard but this definitely looks 
like a question for a pocketsphinx forum...



CMU Sphinx runs forums that would have been appropriate on Sourceforge, but 
those are down hard eg trying to access them gives a 404 error (this is new, 
they have never been down before, at least in my experience).  The 
help/discussion forums at python.org are apparently in the midst of migrating 
to a new format/software and, while there, are unsearchable and mostly missing 
for the next few days.
 
I want to use this code or code
like it in my bot program, so I don't need the gui, button or any of 
that. I

need pocketsphinx to work exactly as below, but send the text output
back to the main program or to a different program (chatbot) instead of
the gui. Make sense?

Sadly no.
Can you explain exactly how you intend running pocketspinx?
What is the main program? A Python script? Or some other external program? 
Where does chatbot fit in? Is it just an arbitrary example or is there some 
specific symbiosis going on?


It's a robot I've been working on for some months. It consists of a laptop 
interfaced with an Arduino board that reads sensors, sends the data to the 
laptop for decision making and controls the motors based on commands generated 
by the main bot program on the laptop, written in python (2.73). 


Among the many separate programs called by the python program that is the 
main part of the bot, will be pocketsphinx for speech recognition, festival 
for text to speech, Chatscript for the chatbot, the Arduino which coms through 
serial and other things still being worked out. The Arduino is coded and 
communicating quite well with the laptop/python program. Chatscript (via 
boost) and Festival are working well enough for now. I'm trying to work the 
pocketsphinx bit now.


What pocketsphinx needs to do is convert the user's speech to text and send it 
to the python program (main program think master control) via the gst pipe 
set up in the script I appended to the original post. Come to think of it my 
terminology is way off here, as I believe the appended script will ultimately 
be a class within the bot's python program, so think of it more as a main loop 
within the python program. In that loop the sensors will be read, the AI will 
determine priorities based on needs or commands, pocketsphinx will listen and 
convert speech to text returning the text output to the main loop, where the 
text will be either matched with a few preset sentences for commands like 
move forward, turn left, etc or, if there are no matches there, the text 
is sent out to Chatscript (a separate, C++ program) for NLP processing and 
response, which response will be returned to the python program and sent out 
to Festival for text to speech response,
 then the loop starts over unless the end program command is given, in which 
case the loop is exited and the program terminates.


Hopefully better?


 
gui method and the button. The problem is the button controls the vader
(determines begin and end of utterances) as well. Detailed explanation


Nope, you lost me again...


The previously appended code basically does three things: 
1) it creates a little gui text box with a button.  
2) it uses gst to receive real time audio from the mic and opens a pipeline to 
---
3) send the audio to pocketsphinx speech rec engine for decoding to text


How it works: start the program, a gui pops up with a button labeled speak 
and behind the scenes gst and pocketsphinx are started/initialized. The vader 
(voice activity detector), controlled by the button method, determines the 
beginning and endpoint of an utterance (think sentence). So, once the 
program/script is started and everything up and running, when you push the 
speak button, gstreamer receives the audiostream from the mic, the button 
changes to stop and the vader sets to work breaking the audio stream into 
utterances for pocketsphinx to process/convert to text. The output from 
pocketshinx, what the engine thinks you said, is displayed in real time in the 
text box of the gui.


I want that text directed into the python program for further processing 
instead of the text box.


regards, Richard

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] a Pygtk question sort of

2013-01-11 Thread richard kappler
Before anybody jumps me about this question being inappropriate for this
list, yes, I know it probably is BUT, the two places where it might be
appropriate are down pretty hard, so this is my only option (I think).

The question is in regards to pygtk I think, and pocketsphinx obliquely.
Appended below is code from the CMU Sphinx website that I wish to ever so
slightly modify, but am not quite sure how to proceed. This code creates a
gui with a button that stops and starts the pocketsphinx speech recognition
engine. When the button reads speak and you push it, the button goes
blank iirc, pocketsphinx listens, performs speech recognition and sends the
resulting text to the gui, changing the button text back to speak and
putting the pocketsphinx engine ostensibly (though not in actuality) on
pause.

I understand how the below code does all of this, including how
pocketsphinx works. Here's the issue: I want to use this code or code like
it (pocketsphinx can be imported and run directly in python but apparently
only to decode wav files, not as a real-time decoder unless you run it
through gst as shown in the appended code as I understand it) in my bot
program, so I don't need the gui, button or any of that. I need
pocketsphinx to work exactly as below, but send the text output back to the
main program or to a different program (chatbot) instead of the gui. Make
sense? I've been pouring over this code off and on for months as I've been
learning, and it's not quite as simple as dump the gui method and the
button. The problem is the button controls the vader (determines begin and
end of utterances) as well. Detailed explanation here:
http://cmusphinx.sourceforge.net/wiki/gstreamer

So can anyone give me some guidance here or point me towards a place to
discuss this? The forums at Python.org are under construction, the
CMUSphinx forums at Sourceforge are down (404) so I'm not quite sure where
to go for help.

regards, Richard

#!/usr/bin/env python

# Copyright (c) 2008 Carnegie Mellon University.
#
# You may modify and redistribute this file under the same terms as
# the CMU Sphinx system.  See
# http://cmusphinx.sourceforge.net/html/LICENSE for more information.

import pygtk
pygtk.require('2.0')
import gtk

import gobject
import pygst
pygst.require('0.10')
gobject.threads_init()
import gst

class DemoApp(object):
GStreamer/PocketSphinx Demo Application
def __init__(self):
Initialize a DemoApp object
self.init_gui()
self.init_gst()

def init_gui(self):
Initialize the GUI components
self.window = gtk.Window()
self.window.connect(delete-event, gtk.main_quit)
self.window.set_default_size(400,200)
self.window.set_border_width(10)
vbox = gtk.VBox()
self.textbuf = gtk.TextBuffer()
self.text = gtk.TextView(self.textbuf)
self.text.set_wrap_mode(gtk.WRAP_WORD)
vbox.pack_start(self.text)
self.button = gtk.ToggleButton(Speak)
self.button.connect('clicked', self.button_clicked)
vbox.pack_start(self.button, False, False, 5)
self.window.add(vbox)
self.window.show_all()

def init_gst(self):
Initialize the speech components
self.pipeline = gst.parse_launch('gconfaudiosrc ! audioconvert
! audioresample '
 + '! vader name=vad
auto-threshold=true '
 + '! pocketsphinx name=asr ! fakesink')
asr = self.pipeline.get_by_name('asr')
asr.connect('partial_result', self.asr_partial_result)
asr.connect('result', self.asr_result)
asr.set_property('configured', True)

bus = self.pipeline.get_bus()
bus.add_signal_watch()
bus.connect('message::application', self.application_message)

self.pipeline.set_state(gst.STATE_PAUSED)

def asr_partial_result(self, asr, text, uttid):
Forward partial result signals on the bus to the main thread.
struct = gst.Structure('partial_result')
struct.set_value('hyp', text)
struct.set_value('uttid', uttid)
asr.post_message(gst.message_new_application(asr, struct))

def asr_result(self, asr, text, uttid):
Forward result signals on the bus to the main thread.
struct = gst.Structure('result')
struct.set_value('hyp', text)
struct.set_value('uttid', uttid)
asr.post_message(gst.message_new_application(asr, struct))

def application_message(self, bus, msg):
Receive application messages from the bus.
msgtype = msg.structure.get_name()
if msgtype == 'partial_result':
self.partial_result(msg.structure['hyp'], msg.structure['uttid'])
elif msgtype == 'result':
self.final_result(msg.structure['hyp'], msg.structure['uttid'])
self.pipeline.set_state(gst.STATE_PAUSED)
self.button.set_active(False)

def partial_result(self, hyp, uttid):

Re: [Tutor] a Pygtk question sort of

2013-01-11 Thread Alan Gauld

On 12/01/13 01:18, richard kappler wrote:

Before anybody jumps me about this question being inappropriate for this
list, yes, I know it probably is BUT, the two places where it might be
appropriate are down pretty hard, so this is my only option (I think).


I'm not sure what you mean by down pretty hard but this definitely 
looks like a question for a pocketsphinx forum...



I want to use this code or code
like it in my bot program, so I don't need the gui, button or any of that. I
need pocketsphinx to work exactly as below, but send the text output
back to the main program or to a different program (chatbot) instead of
the gui. Make sense?


Sadly no.
Can you explain exactly how you intend running pocketspinx?
What is the main program? A Python script? Or some other external 
program? Where does chatbot fit in? Is it just an arbitrary example or 
is there some specific symbiosis going on?



gui method and the button. The problem is the button controls the vader
(determines begin and end of utterances) as well. Detailed explanation


Nope, you lost me again...


So can anyone give me some guidance here or point me towards a place to
discuss this? The forums at Python.org are under construction, the
CMUSphinx forums at Sourceforge are down (404) so I'm not quite sure
where to go for help.


Googling pocketsphinx python threw up at least half a dozen useful 
looking links


You could also try the main python mailing list (or its mirror on
the comp.lang.python newsgroup)

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor