I’ve been struggling to find a low latency sound solution under Windows 7 for some time now. I would like to share the current approach with winsound, though I have to test it with an oscilloscope in the coming days. Also we need to look, if the sound quality and sound length is ok.
I’m loading the wave file to memory before playing it, instead of playing it from a file. It’s not possible to play it asynchronously, when loading from memory, so I use threading instead… (thanks for the hint Jon)
the code may be useful for some of you:
import threading with open(startle_sound_file, 'rb') as f: startle_sound_str = f.read() def sendTrigger(code): p_port.setData(code) core.wait(0.1) p_port.setData(0) thread_play = threading.Thread(target=winsound.PlaySound, args=(startle_sound_str, winsound.SND_MEMORY,)) thread_play.start() sendTrigger(255)