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
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?