I was following this guide to learn how to trigger sound with the GPIO input.
What I learned is that there is some latency between the press of the button and the played sound. Is it possible to play the sound immediately? Like reading it into a buffer and play from there?
If yes, what is the best practice to achieve this result? I am working with a Pi 2B, language can be anything, I am flexible. Any guideance is appreciated.
To be more specific, this is the Python code I ended up with:
import pygame.mixer from pygame.mixer import Sound from gpiozero import Button from signal import pause button = Button(3) pygame.mixer.init() sDob=pygame.mixer.Sound('mintak2/drum_tom_lo_soft.wav') while True: button.when_pressed = sDob.play
There is around half second latency between the press of the button and the play of the sound.