Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Simulate Microphone (virtual mic)

I've got a problem where I need to "simulate" microphone output.

Data will be coming over the network, decoded into PCM and basically needs to be written into the mic - which then other programs can read/record/whatever.

I've been reading up on alsa but information is pretty sparse. The file plugin seemes promising - I was thinking of having a named pipe as "infile" which I could then deliver data to from my application. I can't get it to work however (vlc/audacity just segfault).

pcm.testing {
  type file
  slave {
    pcm {
      type hw
      card 0
      device 0
    }
  }
  infile "/dev/urandom"
  format "raw"
}

Are there any better ways of doing this? Any suggestions on alsa plug-ins (particularly the file plugin)?

like image 323
ag_ Avatar asked Jan 02 '11 23:01

ag_


People also ask

How do I make a virtual microphone?

Activate Virtual Mic by going to the menubar and finding Outputs ➝ Virtual Mic and switching it to On. If this is your first time using the feature, choose to install the Virtual Mic. Then, in the other app's camera menu, you'll see Ecamm Live Virtual Mic as a choice.

What is a virtual microphone?

A virtual microphone is, in fact, a “real” microphone that relies on digital signal processing (DSP) to create facsimiles of the sound pickup characteristics and frequency response of another microphone.

How do I get audio output as mic input?

Open the setting of one your microphone devices and enable "Listen to device", select your current output device from the list. Playback audio on that same output device. The mic signal equals the output signal.

How does a virtual microphone work?

It is a real microphone that uses digital signal processing (DSP) to artificially emulate the sound pickup characteristics and frequency response of another microphone. Virtual mics are essentially neutral and transparent sounding with an equally neutral mic preamplifier.


1 Answers

Your sound will come over the network and what would cache it until something wants to read? Or would data be discarded? In general something like the below (only barely tested) should work as a virtual mic, but I think that it will always read file from beginning when device opened and you need to check how does it handle end of file. Perhaps what you would try it using pipes but then caching/discarding incoming data needs to be handled by the app reading from network.

pcm.virtmic {
    type file
    format "raw"
    slave.pcm "default"
    file '/dev/null'
    infile '/dev/urandom'
}

See alsa docs for more options.

Again, not sure if this tool is what you really need for the task. It would have been really nifty if you could start a command with the 'infile' option, like you can with 'file' but unfortunately you can't...

Hope that helps.

UPDATE: slave.pcm must not be "null" but some real device. It seems that is used for timing or I don't know but using null causes the recorder process to block forever. This device could force you at a given sample rate though so be careful. Using "default" is a sane default value. infile needs to provide a raw sound data with the correct/matching format and rate. btw you can look at alsa server and jackd and other sound systems and libraries for alternative solutions for your task

like image 63
akostadinov Avatar answered Sep 27 '22 22:09

akostadinov