I'm trying to launch 2 audio records simultaneously (with 2 different mics) using the command arecord.
First, this is the code I use to record from one mic (record.py) :
#!/usr/bin/env python2
# -*-coding:Latin-1 -*
from threading import Thread
import pyaudio, sys, wave, time, commands, os
# classe qui permet d'exécuter un second Thread qui va enregistrer en même temps
class Record(Thread):
def __init__(self, device):
super(Record, self).__init__()
self.device = device
def run(self):
# permet d'enregistrer en spécifiant le / les bons micros, et enregistre un fichier à la bonne date et heure, en spécifiant le numéro du micro
u = commands.getoutput('arecord -D plughw:' + self.device + ',0 -f cd -t wav -d 10 --use-strftime %Y/%m/%d/mic' + self.device + '-listen-%H-%M-%v.wav')
class ActionsPerMic(Thread):
def __init__(self, device):
super(ActionsPerMic, self).__init__()
self.device = device
def run(self):
rec = Record(self.device)
rec.start()
rec.join()
# pour un micro branché au Raspberry Pi
mic1 = ActionsPerMic(sys.argv[1])
mic1.start()
mic1.join()
Then, I launch another program with subprocess.Popen which calls record.py twice:
# #!/usr/bin/env python2
# # -*-coding:Latin-1 -*
import commands, time, subprocess, signal, os, pyaudio, sys, wave
from subprocess import Popen
from threading import Thread
listDevices = list()
p = pyaudio.PyAudio()
dev0 = ["python", "record.py", "3"]
dev1 = ["python", "record.py", "4"]
pDev0 = subprocess.Popen(dev0, stdin = subprocess.PIPE)
pDev1 = subprocess.Popen(dev0, stdin = subprocess.PIPE)
# pDev0.terminate()
# pDev1.terminate()
# pDev0.wait()
# pDev1.wait()
pDev0.finish()
pDev1.finish()
None of these functions (terminate, wait and finish) are permitted to launch the 2 records simultaneously.