1

I am currently live streaming some audio to and from a raspberry Pi Zero W using the waveshare audio hat however I have found that the audio periodically cuts out when I do this. When I used my logic analyzer on it I found the the I2C stream seems to stop sending data to the hat periodically. Here is what the data stream looks like for the Pi Z and the Pi 3 enter image description here

The PIZDin is the I2C data in from the Pi Zero and you can see that it cuts out frequently and the Pi 3 on PI3Din cuts out some as well. You can also see that the audio input from the Pi Z is constant. The data is continuously streamed even when the I2C stops sending it to the audio hat. Here is the driving code:

Sender on Pi Z W

#!/usr/bin/env python3
import alsaaudio
import socket
import struct
import sys
from gpiozero import Button

#button to start broadcasting
button = Button(17)

#prepare audio devices
device = "default"

audioIn = alsaaudio.PCM(alsaaudio.PCM_CAPTURE, alsaaudio.PCM_NORMAL, device=device, periodsize=1, format=alsaaudio.PCM_FORMAT_S8)
audioOut = alsaaudio.PCM(device=device, periodsize=1,format=alsaaudio.PCM_FORMAT_S8)

#prepare network connection
broadcastIP = ('192.168.100.255',10000)
recieve_group = ('',10000)

cast = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
cast.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)

#read data and play it locally and broadcast to network
while (True):
   if (button.is_pressed):
      length, data = audioIn.read()
      audioOut.write(data)
      # broadcast data
      print(len(data), sys.stderr)
      cast.sendto(data,broadcastIP)

Reciever on Pi 3

#!/usr/bin/env python3
import alsaaudio
import socket
import struct
import sys

#prepare audio device
device = "default"

audioOut = alsaaudio.PCM(device=device,periodsize=1,format=alsaaudio.PCM_FORMAT_S8)

#prepare network connection
receive_group = ('',10000)
receive = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

receive.bind(receive_group)

#read data from network and play it on audio hat
while(True):
   data, address = receive.recvfrom(65536)
   audioOut.write(data)
   print(len(data),sys.stderr)

I can't figure out why it is cutting out does anyone have some ideas?

1 Answer 1

0

Try running sudo apt purge pulseaudio and rebooting. It can sometimes cause problems with audio output.

If it's not installed, try running sudo apt install pulseaudio which ironically can also fix things.

4
  • Pulseaudio was never installed on my system so I can't remove it
    – Binvention
    Jul 17, 2020 at 20:54
  • Then try installing it
    – dominic03
    Jul 17, 2020 at 20:56
  • I'm using alsaaudio through libasound2-dev and the python library pyaslaaudo
    – Binvention
    Jul 17, 2020 at 20:56
  • I could use pulse audio but since it is Livestream I'm going for minimal latency and from what I've seen the latency from pulseaudio can be significant
    – Binvention
    Jul 17, 2020 at 22:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.