How to redirect from Audio Output to Mic Input using PulseAudio?

Yekta Leblebici picture Yekta Leblebici · Jan 18, 2011 · Viewed 16.8k times · Source

I'm working on a mobile app for Maemo/MeeGo and Maemo uses PulseAudio. I want to play a mp3 to caller (and cancel the mic when doing it, and not to listen caller, everything should be done on background), to do this, I have to redirect Audio Output from a certain (if not possible, all) app, fake it as a Input and make Phone app use it.

On my Ubuntu PC, I did it with pavucontrol. I created a NULL sink, then:

Audio Output (from Amarok) --> to NULL Output 
Skype Input <-- NULL Output
Skype Output --> NULL

And It worked, Amarok played the music and It was streaming to Skype, without playing it to me and I didn't hear anything about all process. Problem is; a) Maemo does not have pavucontrol. b) Even If it did (or if I package it) It wouldn't be any good since It's a only-GUI app and I have to do all of this stuff on background, without any user input. (mean: CLI or API)

Asked about this on Freenode #pulseaudio and a helpful guy said "It can pretty much be done via pactl or pacmd, the commands you want are move-sink-input and move-source-output, but you need to know device and stream indexes." So It looks like pavucontrol is just a GUI, pactl and pacmd are the real deal, and most importantly, they're CLI apps.

I'm really thankful to him but I don't know anything about "pactl", "pacmd", "move-sink-input" or "device/stream indexes" so I need a very simplified manual page, or a source of similar app, a one-liner command (two? whole page of commands?, just give me them! ^^) or someone with enough patience to explain this stuff to me.

Answer

izzy picture izzy · Jul 14, 2017

The manuals for pactl and pacmd are readily available if you give it a search. I found them here:

pactl

pacmd (pulse-cli-syntax)

I think you are interested in the following excerpt from the pactl manual:

move-sink-input ID SINK : Move the specified playback stream (identified by its numerical index) to the specified sink (identified by its symbolic name or numerical index).

You should be able to use pactl list sink-inputs, pactl list source-outputs, pactl list sinks, and pactl list sources combined with some grep and/or sed or something of that nature to programmatically determine the correct stream and sink.