audio - How to use pocketsphinx (5prealpha) with gstreamer-1.0 in python? -


i trying create small python script receive audio stream on network, feed through pocketspinx translate speech text , run commands depending on output of pocketsphinx.

i've installed sphinxbase , pocketsphinx (5prealpha) on ubuntu 15.10 vm , able process content of example audiofile (part of pocketsphinx installation) in python. i'm reasonably sure sphinx install working properly. unfortunately test python script cannot process continuous audio , uses native pocketsphinx api. according cmusphinx website should use gstreamer continuous translation. unfortunately information on how use pocketsphinx gstreamer in python rather limited. based on examples find pieced following script.

import gi gi.require_version('gst', '1.0') gi.repository import gobject, gst gobject.threads_init() gst.init(none)  def element_message( bus, msg ):          msgtype = msg.get_structure().get_name()          if msgtype != 'pocketsphinx':                  return          print "hypothesis= '%s'  confidence=%s\n" % (msg.get_structure().get_value('hypothesis'), msg.get_structure().get_value('confidence'))  pipeline = gst.parse_launch('udpsrc port=3000 name=src caps=application/x-rtp ! rtppcmadepay name=rtpp ! alawdec name=decoder ! queue ! pocketsphinx name=asr ! fakesink')  asr = pipeline.get_by_name("asr") asr.set_property("configured", "true")  bus = pipeline.get_bus() bus.add_signal_watch() bus.connect('message::element', element_message)  pipeline.set_state(gst.state.playing)  # enter mainloop loop = gobject.mainloop() loop.run() 

the sending side looks like:

import gobject, pygst pygst.require("0.10") import gst  pipeline = gst.parse_launch('alsasrc ! audioconvert ! audioresample ! alawenc ! rtppcmapay ! udpsink  port=3000 host=192.168.13.120') pipeline.set_state(gst.state_playing) loop = gobject.mainloop() loop.run() 

this should receive udp stream network, fead pocketsphinx , print output terminal. if replace 'queue ! pocketsphinx ! fakesink' part 'wavenc ! filesink', valid audio file correct content known network-sending part working correctly. (i not have audio on test machine cannot test local audiosource).

when start script see pocketspinx configuration passing script doesn't seem @ anymore. when start script gst_debug=*:4 see following output:

0:00:04.789157687  2220      0x86fff70 info               gst_event gstevent.c:760:gst_event_new_segment: creating segment event time segment start=0:00:00.000000000, offset=0:00:00.000000000, stop=99:99:99.999999999, rate=1.000000, applied_rate=1.000000, flags=0x00, time=0:00:00.000000000, base=0:00:00.000000000, position 0:00:00.000000000, duration 99:99:99.999999999 0:00:04.789616981  2220      0x86fff70 info                 basesrc gstbasesrc.c:2838:gst_base_src_loop:<src> marking pending discont 0:00:04.789995780  2220      0x86fff70 info               gst_event gstevent.c:760:gst_event_new_segment: creating segment event time segment start=0:00:00.000000000, offset=0:00:00.000000000, stop=99:99:99.999999999, rate=1.000000, applied_rate=1.000000, flags=0x00, time=0:00:00.000000000, base=0:00:00.000000000, position 0:00:04.079311489, duration 99:99:99.999999999 0:00:04.790420834  2220      0x86fff70 info               gst_event gstevent.c:679:gst_event_new_caps: creating caps event audio/x-raw, format=(string)s16le, layout=(string)interleaved, rate=(int)8000, channels=(int)1 0:00:04.790851965  2220      0x86fff70 warn                gst_pads gstpad.c:3989:gst_pad_peer_query:<decoder:src> not send sticky events 0:00:04.791258320  2220      0x86fff70 warn                 basesrc gstbasesrc.c:2943:gst_base_src_loop:<src> error: internal data flow error. 0:00:04.791572605  2220      0x86fff70 warn                 basesrc gstbasesrc.c:2943:gst_base_src_loop:<src> error: streaming task paused, reason not-negotiated (-4) 0:00:04.791917073  2220      0x86fff70 info        gst_error_system gstelement.c:1837:gst_element_message_full:<src> posting message: internal data flow error. 0:00:04.792305347  2220      0x86fff70 info        gst_error_system gstelement.c:1860:gst_element_message_full:<src> posted error message: internal data flow error. 0:00:04.792633841  2220      0x86fff70 info                    task gsttask.c:315:gst_task_func:<src:src> task going paused 

i not understand going wrong based on information , examples found googling.

any highly appreciated.

nico

gstreamer element requires 16000 khz audio, trying pass 8000. you'll have modify pocketsphinx sources enable 8000 in pocketsphinx element. need update element spec rate, samprate configuration parameter of pocketsphinx , acoustic model.

alternatively need send wideband audio on network. in case should not use alaw codec.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -