Fix Waveshare RLCD audio playback: initialize ES8311 DAC on audio_start event and track byte counts/errors
This commit is contained in:
@@ -502,6 +502,8 @@ def main():
|
||||
ws.send_text(json.dumps({"event": "stop"}))
|
||||
|
||||
i2s_tx = None
|
||||
received_audio_bytes = 0
|
||||
speaker_write_failed = False
|
||||
while True:
|
||||
opcode, payload = ws.recv_frame()
|
||||
if opcode is None:
|
||||
@@ -529,6 +531,15 @@ def main():
|
||||
on_val = 0 if board_config.audio_amp_active_level == 0 else 1
|
||||
amp_pin.value(on_val) # Enable Amp
|
||||
|
||||
# Initialize ES8311 Speaker DAC
|
||||
try:
|
||||
from audio_util import ES8311
|
||||
dac = ES8311(i2c)
|
||||
dac.init(sample_rate=16000)
|
||||
dac.set_volume(85)
|
||||
except Exception as dace:
|
||||
print("Failed to initialize ES8311 DAC for playback:", dace)
|
||||
|
||||
i2s_format = I2S.MONO # WebSocket audio response is mono
|
||||
i2s_tx = I2S(1,
|
||||
sck=Pin(board_config.audio_i2s_sck),
|
||||
@@ -547,6 +558,10 @@ def main():
|
||||
amp_pin.value(off_val) # Disable Amp
|
||||
i2s_tx.deinit()
|
||||
i2s_tx = None
|
||||
if speaker_write_failed:
|
||||
draw_status_bar("Speaker write failed")
|
||||
else:
|
||||
draw_status_bar(f"Recv {received_audio_bytes} bytes")
|
||||
|
||||
elif evt == "done":
|
||||
break
|
||||
@@ -567,7 +582,9 @@ def main():
|
||||
chunk = chunk[44:]
|
||||
try:
|
||||
i2s_tx.write(chunk)
|
||||
received_audio_bytes += len(chunk)
|
||||
except Exception as e:
|
||||
speaker_write_failed = True
|
||||
print("Error writing to speaker:", e)
|
||||
except Exception as he:
|
||||
print("Hermes WS query failed:", he)
|
||||
|
||||
Reference in New Issue
Block a user