I'm trying to play a sound file play to two different devices and so I've tried the multiprocessing and threading modules but it doesn't yield the wanted result
At first, I wanted to execute the function that plays the file twice at the same time but then I realized that it wasn't possible so I want to execute both in a very small time window. I tried the threading and multiprocessing module to make two processes. after I tried to simply execute it with the play function returning immediately so it can execute the next play but it just plays them one after the other
import sounddevice as sd
import soundfile as sf
from multiprocessing import Process
import argparse
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("filename", help="audio file to be played back")
args = parser.parse_args()
def _play_(d):
try:
data, fs = sf.read(args.filename, dtype='float32')
sd.play(data, fs, device=d, blocking = False)
status = sd.wait()
if status:
parser.exit('Error during playback: ' + str(status))
except KeyboardInterrupt:
parser.exit('\nInterrupted by user')
except Exception as e:
parser.exit(type(e).__name__ + ': ' + str(e))
if __name__ == '__main__':
Process(target =_play_(8),name = 'playing1').start()
Process(target =_play_(9),name = 'playing2').start()
I expect it to play twice the file I specified to two different devices at almost the same time but instead, it just plays one at a time