alumae / gst-kaldi-nnet2-online

GStreamer plugin around Kaldi's online neural network decoder
Apache License 2.0
185 stars 100 forks source link

Stopping the pipeline mid-decoding #33

Open Aelos opened 8 years ago

Aelos commented 8 years ago

Hello,

I am using Kaldi in a way similar to your gstreamer server, and this plugin is a great help.

My issue is when decoding a file, either by using a filesrc element or by pushing buffers in an appsrc element. I cannot find a way to stop the decoding before it has reached the end of the file. I see in your decoder you commented various lines that I have tried without success:

Through chance I found a kind of workaround by using a tee element with on one side the asr decoder (without a fakesink) and on the other side a pulsesink. The pulsesink would receive the eos, throw an underflow warning and for some reason the asr element will stop as well. This however is not graceful at all and the server I want to run the service on doesn't have pulseaudio drivers. I believe this might also hinder performance.

I noted that this also happens with the other kaldi gstreamer plugin (gmmdecode) in the same way, whereas when using the pocketsphinx plugin, the behavior is as expected and pushing an eos event will stop the decoding.

My code is similar to the one you use in decoder2.py.

Would you know of a graceful way to stop the pipeline in order to have the decoder immediately available again?

alumae commented 8 years ago

I don't think it's possible at the moment. In fact, I've struggled with this problem too. I think it one might need to make largish changes to the code to make it possible, and it is especially complicated with the threaded decoder.

When you push EOS to the pipeline, it gets consumed after all the buffers that have been already pushed to the pipeline. Therefore, I actually cannot see how the pocketsphinx plugin could handle it better. I used the pocketsphinx plugin as a reference when creating the the Kaldi GStreamer plugins.

Aelos commented 8 years ago

I understand.

About PocketSphinx, in my simple pipeline filesrc -> decodebin -> audioconvert -> audioresample -> pocketsphinx -> fakesink, it seems that using pipeline.send_event(Gst.Event.new_eos()) works and the EOS is consumed almost immediately and the event handler called, even if the file is far from being fully decoded.

I do not fully understand yet the way buffers and events are consumed in Gstreamer, and especially why my workaround with the pulseaudio element works.

Thank you for your answer. I will keep you updated if I find a way.

luvwinnie commented 5 years ago

Hello, Thanks for this gstreamer plugins!

I trying to use this gstreamer plugins in my gstreamer python apps with "appsrc" method. However i face the same problems for this. Does anyone figure out how to solve this problem?

In my case, I trying to use pyaudio to record the sound wave and decoding. PS:My code is similar to your decoder2.py just like @Aelos.