1

I want to record voice, process it, than play it on the fly. The code below should describe more.

arecord -D plughw:USER -f S16_LE -t raw | python my_app.py | aplay -D plughw:USER -f S16_LE

I was able to capture input from arecord for my_app.py by using raw_input(). Now, I have problem on how to send my_app.py output to aplay.

I've tried using subprocess inside my_app.py to run aplay,

cmdPlay = 'aplay -D plughw:USER -f S16_LE'
p = subprocess.Popen(
    cmdPlay,
    stdout = subprocess.PIPE,
    stdin = subprocess.PIPE,
    stderr = subprocess.PIPE,
    shell = True
)
p.communicate(input=dataHex.decode('hex'))

But, I heard no voice played on speaker.

So, how do you piping between python app and other processes (as input and output)? n.b.: Please also suggest a better method, if any, than raw_input() for capture data from arecord.

arsenalist
  • 167
  • 4
  • 13
  • Why don't you just write the data to `stdout`? – CL. Mar 04 '15 at 08:08
  • @CL., I've tried with `sys.stdout.write(data)`, but it not received by the `aplay`. Could you provide with an example of your idea? I might just be wrong in using `stdout`. thanks – arsenalist Mar 04 '15 at 10:41
  • see [Python 2.x - Write binary output to stdout?](http://stackoverflow.com/questions/2374427/python-2-x-write-binary-output-to-stdout) – CL. Mar 04 '15 at 11:25

0 Answers0