TL;DR: I want to create a virtual mic on my pi to stream wav data to it from a named pipe, so apps that look for input from a mic instead of a file can receive it.


I'm running pocketsphinx_continuous on my pi, with really good results. I am using the -infile option to read from pre-recorded wav files that I receive from Telegram as voice messages (after converting them from ogg format, etc). So far so good.

Now, pocketsphinx_continuous runs only once when using the -infile option (ie. it starts, recognizes the speech from the wav file, and execution ends). In oposition to this, when pocketsphinx_continuous is run with the -inmic yes option to recognize voice from a mic, it runs forever in an infinite loop, detecting silences to start the recognition and loop to a stand-by state again (see the code here if you are interested).

The problem

The situation explained above causes the recognition with -infile to take considerably more time because every execution needs to initialize pocketsphinx again (parse jsgf grammar or language model, etc), while the -inmic option leaves it running and initializes it only once.

The idea

I want to use the inmic mode of pocketsphinx_continuous, that will only initialize once and run forever, but simulate the mic in the pi as a pipe or file, and cat the wav files to it (thus, simulating how audio is received from this mic)

Similar questions

I've found many questions around this subject but none seem to be exactly for this case. Some are for ubuntu, not raspbian, some need only to simulate a "dummy" mic but don't need for it to actually work, some use desktop apps like Audacity and so on, some don't have an accepted answer, etc. Some examples are:

The question

So, how can I create a virtual mic that actually works, that takes its input from a named pipe, so I can stream (cat?) an existing .wav file to it, and would be recognized as input from a mic in an application (such as pocketsphinx).


  • See Linux - Creating Virtual Audio Device.
    – CL.
    May 30, 2016 at 7:20
  • thanks @CL. I would appreciate a little elaboration on the answer because I don't know what snd-aloop is, or how to use it, etc. It looks promising though. thanks again! May 30, 2016 at 20:05

1 Answer 1


You are doing too much things with a command line. After you recognized you need to process the data, you need to handle errors and so on.

It is much better to write your server with pocketsphinx API in C or in Python or Ruby, it will just be 20-30 lines of code.

  • Hi Nikolay! Great to have an answer by you. I was thinking about that, but I wanted to know if I could "fool" pocketsphinx inmic mode, and in the process learn how to emulate a mic in the raspberry pi because it lacks one by default, and I think it come in handy for other stuff as well. May 30, 2016 at 19:56
  • Btw, I think I can imagine how that program would be, but I haven't set up my environment to develop a program using pocketsphinx API yet. Do you have any guidelines or document link on how is it recommended to do that? Thanks again! May 30, 2016 at 19:58
  • Python API would be easiest I think. You can find samples here: github.com/cmusphinx/pocketsphinx/blob/master/swig/python/test/… May 30, 2016 at 20:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.