Skip to content

Instantly share code, notes, and snippets.

@markizano
Created November 23, 2024 16:54
Show Gist options
  • Select an option

  • Save markizano/a7008a261d14688a84294552c08abb7b to your computer and use it in GitHub Desktop.

Select an option

Save markizano/a7008a261d14688a84294552c08abb7b to your computer and use it in GitHub Desktop.
Binds Audio from one Pulse Audio server to another
#!/usr/bin/env python3
import os, sys
import pasimple
# Set this variable to the IP address of another system running Pulse where you want send playback.
PA_SERVER = os.environ.get('PA_SERVER', '192.168.1.3')
# NOTE: Remove the file /tmp/pa-bind.pid to kill the bridge
PIDFILE = '/tmp/pa-bind.pid'
def main():
play = pasimple.PaSimple(
direction=pasimple.PA_STREAM_PLAYBACK,
rate=48000,
format=pasimple.PA_SAMPLE_S16LE,
channels=2,
app_name='pa-bind',
stream_name='pa-bind-speaker',
server_name=PA_SERVER
)
record = pasimple.PaSimple(
direction=pasimple.PA_STREAM_RECORD,
rate=48000,
format=pasimple.PA_SAMPLE_S16LE,
channels=2,
app_name='pa-bind',
stream_name='pa-bind-instance',
)
open(PIDFILE, 'w').write(str(os.getpid()) + '\n')
while os.path.exists(PIDFILE):
# Read a chunk of audio data from the microphone
data = record.read(4096)
# Write the audio data to the speaker
play.write(data)
return 0
if __name__ == '__main__':
sys.exit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment