How to redirect from Audio Output to Mic Input using PulseAudio?
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.
Linux pipe audio file to microphone input
After many painstaking hours, I finally got something acceptable working. I undid everything I did with ALSA (since the default is for ALSA to use PulseAudio instead, which I initially overrode). I created a simple bash script install_virtmic.sh
to create a "virtual microphone" for PulseAudio to use as well as PulseAudio clients:
#!/bin/bash
# This script will create a virtual microphone for PulseAudio to use and set it as the default device.
# Load the "module-pipe-source" module to read audio data from a FIFO special file.
echo "Creating virtual microphone."
pactl load-module module-pipe-source source_name=virtmic file=/home/charles/audioFiles/virtmic format=s16le rate=16000 channels=1
# Set the virtmic as the default source device.
echo "Set the virtual microphone as the default device."
pactl set-default-source virtmic
# Create a file that will set the default source device to virtmic for all
PulseAudio client applications.
echo "default-source = virtmic" > /home/charles/.config/pulse/client.conf
# Write the audio file to the named pipe virtmic. This will block until the named pipe is read.
echo "Writing audio file to virtual microphone."
while true; do
cat audioFile0.raw > /home/charles/audioFiles/virtmic
done
A quick script uninstall_virtmic.sh
for undoing everything done by the install script:
#!/bin/bash
# Uninstall the virtual microphone.
pactl unload-module module-pipe-source
rm /home/charles/.config/pulse/client.conf
I then fired up Chromium and clicked the microphone to use its voice search feature and it worked! I also tried with arecord test.raw -t raw -f S16_LE -c 1 -r 16000
and it worked too! It isn't perfect, because I keep writing to the named pipe virtmic
in an infinite loop in the script (which quickly made my test.raw
file insanely large), but it will do for now.
Please feel free to let me know if anyone out there finds a better solution!
Pulseaudio - combined mic streams to play output on combined speaker sink
This did what I wanted:
pactl load-module module-loopback latency_msec=1 source=alsa_input.pci-0000_00_1b.0.analog-stereo sink=bluez_sink.00_02_5B_00_FF_03
pactl load-module module-loopback latency_msec=1 source=bluez_source.00_02_5B_00_FF_03 sink=alsa_output.pci-0000_00_1b.0.analog-stereo
Related Topics
Linux Find Out Hyper-Threaded Core Id
Is There Any Significant Difference Between Tcp_Cork and Tcp_Nodelay in This Use-Case
How to Trace Per-File Io Operations in Linux
How to Get Eclipse Swt Browser Component Running on Ubuntu 11.04 (Natty Narwhal) with Webkit
How to List the Files in a Zip Archive Without Decompressing It
Tail Inverse/Printing Everything Except the Last N Lines
How to Read the Second-To-Last Line in a File Using Bash
Adding Users to Sudoers Through Shell Script
Pass Private Key Password to Openvpn Command Directly in Ubuntu 10.10
How to Compile Linux Kernel with Something Other Than Gcc
Sed: How to Delete Lines Matching a Pattern That Contains Forward Slashes
How Are Percpu Pointers Implemented in the Linux Kernel
Go Http Server Testing Ab VS Wrk So Much Difference in Result
Is It Safe to Issue Blocking Write() Calls on the Same Tcp Socket from Multiple Threads
Codeigniter Url Rewriting .Htaccess Is Not Working on Centos