Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I need debug my program and I need something like a virtual microphone. I would like device "microphone" where I can put sound file and this file will be input for microphone stream. And in application I get this stream from this "microphone"

File -> Microphone -> Application

is it possible?

something like bash command should by very very useful:

aplay --device=mic my_microphone.wav to run a microphone stream

share|improve this question

2 Answers 2

Your question lacks a few details, such as which programming language or which sound server you are using. Still, I'll give it a try.

I have successfully used the JACK daemon (jackd) to debug an audio application. It might be a bit of work to get jackd to work, but it's worth it. Think of it as a sound server that audio applications and hardware can register audio input and output ports with. Then you may use qjackctl to connect these ports, either manually using Connect or automatically using the Patchbay.

The steps to follow:

  • install jackd and qjackctl
  • supposing that you're using ALSA, add a device jack to your ~/.asoundrc so you can output to the jack server (see below)
  • start qjackctl and from inside, start jackd (this might be the time where you run into problems - in my rather complex audio setup, I had to move pulseaudio out of the way)
  • play your sound file using aplay --device=jack my_microphone.wav and try to connect it to your sound card - when you hear something, you're almost done
  • create a new JACK input port using the JACK API
  • use jackd's Patchbay to automatically connect your new input port to a JACK audio output port (which may the output from aplay, a media player using JACK (qmmp, VLC and others) or your sound card)

Here's the relevant part of my ~/.asoundrc

pcm.jack
{
        type plug
        slave.pcm "jack_output"
        hint
        {
                show on
                description "Alsa (JACK plugin)"
        }
}

pcm.jack_output
{
        type jack
        playback_ports
        {
                0 system:playback_1
                1 system:playback_2
        }
        capture_ports
        {
                0 system:capture_1
                1 system:capture_2
        }
        hint
        {
                show off
                description "Alsa (JACK output)"
        }
}
share|improve this answer

You can also incorporate GStreamer in your application. See here for a short introduction and here for a tutorial. The element appsink might be just what you're looking for.

Here are some command line examples. There's also an extensive API so you can call all (or part) of this from your application.

Playback pink noise on your default audio output:

gst-launch-0.10 audiotestsrc wave=6 ! autoaudiosink

Playback an MP3 (or other supported format) on your default audio output:

gst-launch-0.10 filesrc location=my_microphone.mp3 ! decodebin ! \
  audioconvert ! autoaudiosink

GStreamer is brilliant, so please don't blame me in case you start re-writing your whole application using GStreamer... :)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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