Skip to content

Instantly share code, notes, and snippets.

@kristjanvariksoo
Created December 29, 2016 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kristjanvariksoo/fd31f037ecd670976e7c843f3c321e22 to your computer and use it in GitHub Desktop.
Save kristjanvariksoo/fd31f037ecd670976e7c843f3c321e22 to your computer and use it in GitHub Desktop.
Play music mixed together with your microphone through skype. Linux only. Uses pulseaudio.
from pulsectl import Pulse
import os
pulse = Pulse("volume-increaser")
N = 0
for sink in pulse.sink_list():
print str(N) + " - " + sink.description + " - " + sink.name
N += 1
mainsink = pulse.sink_list()[int(raw_input("Select your preferred sink... "))]
print "Selected sink: " + str(mainsink)
print ""
print ""
print ""
N = 0
for source in pulse.source_list():
print str(N) + " - " + source.description + " - " + source.name
N += 1
mainsource = pulse.source_list()[int(raw_input("Select your preferred source... "))]
print mainsource
print ""
print ""
print ""
print "Creating null0, Only Music..."
cmd = 'pactl load-module module-null-sink sink_name=null0 sink_properties=device.description="OnlyMusic"'
print cmd
os.system(cmd)
print "Created null0."
print "Creating null1, MusicANDMic..."
cmd = 'pactl load-module module-null-sink sink_name=null1 sink_properties=device.description="MusicANDMic"'
print cmd
os.system(cmd)
print "Created null1."
print "Creating loopback from Mic to MusicANDMic..."
cmd = 'pactl load-module module-loopback sink=null1 source=' + mainsource.name
print cmd
os.system(cmd)
print "Created loopback."
print "Creating loopback from JustMusic to Speakers..."
cmd = 'pactl load-module module-loopback sink=' + mainsink.name + ' source=null0.monitor'
print cmd
os.system(cmd)
print "Created loopback."
print "Creating loopback from JustMusic to MusicANDMic..."
cmd = 'pactl load-module module-loopback sink=null1 source=null0.monitor'
print cmd
os.system(cmd)
print "Created loopback."
print "Everything is done... Hopefully..."
print "Run pavucontrol and connect music to JustMusic and set Skype(or other similar service) to record from MusicANDMic."
@kristjanvariksoo
Copy link
Author

Mostly based on info from https://xenotoad.net/blog/?p=5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment