Reputation: 71
I'm trying to record and convert a stream with python using arecord.
In the shell this is a command more or less like:
arecord -B 5000 -f dat | lame -m j -q 5 -V 2 - test.mp3 &
In Python I tried this with subprocess.Popen:
reccmd = ["arecord", "-B", "5000", "-f", "dat"]
mp3cmd = ["lame", "-m", "j", "-q", "5", "-V", "2", "-", "test.mp3"]
p = subprocess.Popen(reccmd, stdout=subprocess.PIPE)
p2 = subprocess.Popen(mp3cmd, stdin=p.stdout)
p2.communicate()
But I don't know how to include the "&" or something similar in the code to be able to stop the recording with a
killall arecord
command
Upvotes: 7
Views: 6628
Reputation: 602465
If you don't want the main Python process to block while executing the subprocesses, simply don't call p2.communicate()
. The calls to subprocess.Popen()
don't block.
Upvotes: 9