Closed tvvladimir2 closed 3 years ago
import sounddevice as sd import soundfile as sf from time import sleep import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) button1=16 button2=12
GPIO.setup(button1,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(button2,GPIO.IN,pull_up_down=GPIO.PUD_UP)
filename1 = '1.wav' filename2 = '2.wav'
data1, fs1 = sf.read(filename1, dtype='float32') data2, fs2 = sf.read(filename2, dtype='float32')
BS1=False BS2=False
while(1): if GPIO.input(button1)==0: print ("Button 1 was pressed") if BS1==False: sd.play(data1, fs1, device=0) print("Device 0 playback started") BS1=True sleep(.5) else: sd.stop() print("Device 0 playback stopped") BS1=False sleep(.5)
if GPIO.input(button2)==0: print ("Button 2 was pressed") if BS2==False: sd.play(data2, fs2, device=1) print("Device 1 playback started") BS2=True sleep(.5) else: sd.stop() print("Device 1 playback stopped") BS2=False sleep(.5)
If sd.stop() stops all audio, how do i stop only the device i need?
import sounddevice as sd import soundfile as sf from time import sleep import RPi.GPIO as GPIO GPIO.setmode(GPIO.BOARD) button1=16 button2=12
GPIO.setup(button1,GPIO.IN,pull_up_down=GPIO.PUD_UP) GPIO.setup(button2,GPIO.IN,pull_up_down=GPIO.PUD_UP)
filename1 = '1.wav' filename2 = '2.wav'
data1, fs1 = sf.read(filename1, dtype='float32') data2, fs2 = sf.read(filename2, dtype='float32')
BS1=False BS2=False
while(1): if GPIO.input(button1)==0: print ("Button 1 was pressed") if BS1==False: sd.play(data1, fs1, device=0) print("Device 0 playback started") BS1=True sleep(.5) else: sd.stop() print("Device 0 playback stopped") BS1=False sleep(.5)