mirror of https://github.com/Chizi123/Scripts.git

Joel Grunbaum
2021-08-24 d6e801a44971f9e6ee6d1282b3ae0912e0033ba3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#!/bin/sh
 
# Stream pulseaudio to remote sources
# This can be used to stream audio to a phone assuming it has an appropriate app
# I got most of this code from StackOverflow
 
server_port=8000
ip_address=$(ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p')
pulse_source=$(pactl list sources short | grep analog-stereo.monitor | awk '{print $2}')
case "$1" in
  start)
    $0 stop 
    pactl load-module module-simple-protocol-tcp rate=48000 format=s16le channels=2 source=$pulse_source record=true port=$server_port
    ;;
  stop)
    pactl unload-module `pactl list | grep tcp -B1 | grep M | sed 's/[^0-9]//g'`
    ;;
  *)
    echo "Usage: $0 start|stop" >&2
    ;;
esac