2

I could not find a suitable music player for my text-based python program, as they were all based off of pygame. Thus, I resorted to use my sox program from python with an os.system. However, whenever I play a file with play mymusic.wav, it prints this:

flap.wav:
 File Size: 11.3k     Bit Rate: 257k
  Encoding: Signed PCM    
  Channels: 1 @ 16-bit   
Samplerate: 16000Hz      
Replaygain: off         
  Duration: 00:00:00.35  
In:100%  00:00:00.35 [00:00:00.00] Out:15.6k [      |      ]        Clip:0    
Done.

How can I stop it from printing this?

  • open it as a `subprocess` and redirect stdout to /dev/null – ebarr Mar 20 '14 at 05:08
  • The only code is `play flap.wav`. The sox program does the rest (It is not **my** program. I got it through `brew install sox`. –  Mar 20 '14 at 05:09
  • @ebarr did you mean like this: `subprocess.call(['play', 'flap.wav'], stdout=FNULL, stderr=subprocess.STDOUT)`? –  Mar 20 '14 at 05:12
  • related: [How to hide output of subprocess in Python 2.7](http://stackoverflow.com/q/11269575/4279) – jfs Mar 20 '14 at 07:26

1 Answers1

2

So the output can just be redirected to /dev/null like:

import subprocess
import os

devnull = open(os.devnull,"w")
subprocess.call(['play', 'flap.wav'], stdout=devnull)
devnull.close()

That will just pipe anything your call sends to stdout into /dev/null.

ebarr
  • 7,704
  • 1
  • 29
  • 40