title: Fundamental issue with my Gstreamer pipeline logic in Python. Any advice?
body: <p>I have the following piece of code:</p>
  
  <pre><code>import pi
  from pi.becore import ScarlettConfig
  from recorder import Recorder
  from brain import Brain
  
  import os
  import json
  import tempfile
  #import sys
  
  import pygtk
  pygtk.require('2.0')
  import gtk
  import gobject
  import pygst
  pygst.require('0.10')
  gobject.threads_init()
  import gst
  
  scarlett_config=ScarlettConfig()
  
  class Listener:
    def __init__(self, gobject, gst):
      self.failed = 0
      # scarlettPi ( mmj2f I added this after attempting the scarlettPi change )
      self.recording = tempfile.mktemp(suffix='pi.wav')
  
      self.pipeline = gst.Pipeline("mypipeline")
  
      # alsasrc - we'll use this to connect our ps3 eye and record 
      gst.debug("Adding alsasrc")
      self.source  = gst.element_factory_make("alsasrc", "alsasrc")
      self.source.set_property("device", scarlett_config.gimmie('audio_input_device'))
      self.pipeline.add(self.source)
  
      # add a queue to allow pocketsphinx to recognize more data
      gst.debug("Adding encoding queue")
      self.qone = gst.element_factory_make("queue", "qone")
      self.pipeline.add(self.qone)
  
      # audio convert
      gst.debug("Adding encoding audioconvert")
      self.recfileconvert = gst.element_factory_make("audioconvert", "recfileconvert")
      self.pipeline.add(self.recfileconvert)
  
      # resample the wav
      gst.debug("Adding encoding audioresample")
      self.resample = gst.element_factory_make("audioresample", "resample")
      self.pipeline.add(self.resample)
  
      # Add our tee
      gst.debug("Adding tee")
      self.rectee = gst.element_factory_make("tee", "rectee")
      self.pipeline.add(self.rectee)
  
      # taken from: http://www.jonobacon.org/files/recgui-works.py
      # link tee to alsasrc
      gst.debug("Linking alsasrc to tee")
      self.source.link(self.rectee)
  
      gst.debug("Adding encoding queue")
      self.qtwo = gst.element_factory_make("queue", "qtwo")
      self.pipeline.add(self.qtwo)
  
      gst.debug("Adding vader element")
      self.vader = gst.element_factory_make("vader","vader")
      self.vader.set_property("auto-threshold",False)
      self.pipeline.add(self.vader)
  
      gst.debug("Adding pocketsphinx element")
      self.pocketsphinx = gst.element_factory_make("pocketsphinx","listener")
      print "Pocketsphinx: "
      print dir( self.pocketsphinx )
      self.pocketsphinx.set_property("lm",scarlett_config.gimmie('LM'))
      self.pocketsphinx.set_property("dict",scarlett_config.gimmie('DICT'))
      self.pocketsphinx.set_property("hmm",scarlett_config.gimmie('HMM'))
  
      gst.debug("Adding fakesink")
      self.fakesink = gst.element_factory_make("fakesink", "fakesink")
      self.fakesink.set_property("dump", True)
      self.pipeline.add(self.fakesink)
  
      # Linking fakesink to tee
      # taken from: http://www.jonobacon.org/files/recgui-works.py
      gst.debug("Linking fakesink to tee")
      self.fakesink.link(self.rectee)
  
      # creating valve now
      gst.debug("Adding Valve element")
      self.recording_valve = gst.element_factory_make('valve')
      self.record_valve.set_property("drop",False)
      self.pipeline.add(self.recording_valve)
  
      # another queue
      gst.debug("Adding encoding queue")
      self.recording_valve_queue = gst.element_factory_make("queue", "recording_valve_queue")
      self.pipeline.add(self.recording_valve_queue)
      self.recording_valve.link (self.recording_valve_queue)
  
      # adding wavenc element
      gst.debug("Adding wavenc")
      self.wavenc = gst.element_factory_make("wavenc", "wavenc")
      self.pipeline.add(self.wavenc)
  
      # adding filesink element 
      gst.debug("Adding filesink")
      self.filesink = gst.element_factory_make("filesink", "filesink")
      self.filesink.set_property("location", self.recording)
      self.filesink.set_property("async", False)
      self.pipeline.add(self.filesink)
  
      # lets add the static pads now and link them?
      # NOTE: Not sure if this is correct at all:
      # self.rectee_pad = self.rectee.get_request_pad("src%d")
      # print "Obtained request pad %s for audio branch."% self.rectee_pad.get_name()    
      self.rectee.get_request_pad('src%d').link(self.recording_valve_queue.get_pad('sink'))
      self.rectee.get_request_pad('src%d').link(self.qtwo.get_pad('sink'))
  
      # Original code going forward:
      listener = self.pipeline.get_by_name('listener')
      listener.connect('result', self.__result__)
      listener.set_property('configured', True)
      print "KEYWORDS WE'RE LOOKING FOR: " + scarlett_config.gimmie('ourkeywords')
  
  ......ETC..........
  </code></pre>
  
  <p>And I'm getting this error when I try to run my script:</p>
  
  <pre><code>pi@scarlettpi ~/dev/scarlettPi/scripts/pi $ pi
  /usr/lib/python2.7/dist-packages/gtk-2.0/gtk/__init__.py:57: GtkWarning: could not open display
    warnings.warn(str(e), _gtk.Warning)
  INFO: cmd_ln.c(691): Parsing command line:
  gst-pocketsphinx \
      -samprate 8000 \
      -cmn prior \
      -fwdflat no \
      -bestpath no \
      -maxhmmpf 2000 \
      -maxwpf 20 
  
  Current configuration:
  [NAME]      [DEFLT]     [VALUE]
  -agc        none        none
  -agcthresh  2.0     2.000000e+00
  -alpha      0.97        9.700000e-01
  -ascale     20.0        2.000000e+01
  -aw     1       1
  -backtrace  no      no
  -beam       1e-48       1.000000e-48
  -bestpath   no      no
  -bestpathlw 9.5     9.500000e+00
  -bghist     no      no
  -ceplen     13      13
  -cmn        current     prior
  -cmninit    8.0     8.0
  -compallsen no      no
  -debug              0
  -dict               
  -dictcase   no      no
  -dither     no      no
  -doublebw   no      no
  -ds     1       1
  -fdict              
  -feat       1s_c_d_dd   1s_c_d_dd
  -featparams         
  -fillprob   1e-8        1.000000e-08
  -frate      100     100
  -fsg                
  -fsgusealtpron  yes     yes
  -fsgusefiller   yes     yes
  -fwdflat    yes     no
  -fwdflatbeam    1e-64       1.000000e-64
  -fwdflatefwid   4       4
  -fwdflatlw  8.5     8.500000e+00
  -fwdflatsfwin   25      25
  -fwdflatwbeam   7e-29       7.000000e-29
  -fwdtree    yes     yes
  -hmm                
  -input_endian   little      little
  -jsgf               
  -kdmaxbbi   -1      -1
  -kdmaxdepth 0       0
  -kdtree             
  -latsize    5000        5000
  -lda                
  -ldadim     0       0
  -lextreedump    0       0
  -lifter     0       0
  -lm             
  -lmctl              
  -lmname     default     default
  -logbase    1.0001      1.000100e+00
  -logfn              
  -logspec    no      no
  -lowerf     133.33334   1.333333e+02
  -lpbeam     1e-40       1.000000e-40
  -lponlybeam 7e-29       7.000000e-29
  -lw     6.5     6.500000e+00
  -maxhmmpf   -1      2000
  -maxnewoov  20      20
  -maxwpf     -1      20
  -mdef               
  -mean               
  -mfclogdir          
  -min_endfr  0       0
  -mixw               
  -mixwfloor  0.0000001   1.000000e-07
  -mllr               
  -mmap       yes     yes
  -ncep       13      13
  -nfft       512     512
  -nfilt      40      40
  -nwpen      1.0     1.000000e+00
  -pbeam      1e-48       1.000000e-48
  -pip        1.0     1.000000e+00
  -pl_beam    1e-10       1.000000e-10
  -pl_pbeam   1e-5        1.000000e-05
  -pl_window  0       0
  -rawlogdir          
  -remove_dc  no      no
  -round_filters  yes     yes
  -samprate   16000       8.000000e+03
  -seed       -1      -1
  -sendump            
  -senlogdir          
  -senmgau            
  -silprob    0.1     1.000000e-01
  -smoothspec no      no
  -svspec             
  -tmat               
  -tmatfloor  0.0001      1.000000e-04
  -topn       4       4
  -topn_beam  0       0
  -toprule            
  -transform  legacy      legacy
  -unit_area  yes     yes
  -upperf     6855.4976   6.855498e+03
  -usewdphones    no      no
  -uw     1.0     1.000000e+00
  -var                
  -varfloor   0.0001      1.000000e-04
  -varnorm    no      no
  -verbose    no      no
  -warp_params            
  -warp_type  inverse_linear  inverse_linear
  -wbeam      7e-29       7.000000e-29
  -wip        1e-4        1.000000e-04
  -wlen       0.025625    2.562500e-02
  
  Traceback (most recent call last):
    File "/usr/local/bin/pi", line 5, in &lt;module&gt;
      pkg_resources.run_script('pi==0.1.0', 'pi')
    File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 499, in run_script
      self.require(requires)[0].run_script(script_name, ns)
    File "/usr/lib/python2.7/dist-packages/pkg_resources.py", line 1235, in run_script
      execfile(script_filename, namespace, namespace)
    File "/usr/local/lib/python2.7/dist-packages/pi-0.1.0-py2.7.egg/EGG-INFO/scripts/pi", line 38, in &lt;module&gt;
      listener = Listener(gobject, gst)
    File "/usr/local/lib/python2.7/dist-packages/pi-0.1.0-py2.7.egg/pi/listener.py", line 103, in __init__
      self.pocketsphinx.link(self.rectee)
  gst.LinkError: failed to link listener with rectee
  </code></pre>
  
  <p>I'm trying to do the following suggestion, but i'm not sure if i'm doing it correctly:</p>
  
  <p><a href="https://stackoverflow.com/a/18228933/814221">https://stackoverflow.com/a/18228933/814221</a></p>
  
  <p>Can anyone help me understand what i'm doing wrong fundamentally?</p>
  
  <p>Thanks!</p>