Why is `subprocess.call` not invoking the command
Question: I'm trying to run a .wav file through ffmpeg using the
`subprocess.call(shell=True)` in the following code and it doesn't seem to
run. I know this because the `output_file` isn't created and I'm getting an
exception in the `open()` method. What am I doing wrong?

    
    
    try:
        import pocketsphinx
    
    except:
        import pocketsphinx as ps
        import sphinxbase
        import subprocess
        import os
    
    hmmd = "../../Pocketsphinx_Files/en-us-8khz"
    lmdir = "../../Pocketsphinx_Files/cmusphinx-5.0-en-us.lm"
    dictp = "../../Pocketsphinx_Files/cmu07a.dic"
    
    output_filename = "../../temp/ps_output.wav"
    
    def recognize(filename="../../temp/temp_output.wav"):
    
        command = "ffmpeg -i "+filename+" -ac 1 -ab 16 -ar 16000 "+output_filename
    
        subprocess.call(command,shell=True)
    
        wavFile = open(output_filename,"rb")
    
        speechRec = ps.Decoder(hmm = hmmd, lm = lmdir, dict = dictp)
    
        wavFile.seek(44)
    
        speechRec.decode_raw(wavFile)
    
        result = speechRec.get_hyp()
    
        #os.remove(filename)
        #os.remove(output_filename)
    
        return result
    
    if __name__=="__main__":
        print(recognize())
    

edit: I've got ffmpeg installed. Furthermore, when I run the subprocess.call()
command from the python interpreter it seems to work. This is why I'm stumped.


Answer: I would recommend that you try using `subprocess.check_call()` or
`check_output` instead of simply `call`. They will raise an exception if your
program fails to execute correctly, instead of leaving you wondering why no
output was generated.

I'm going to guess that you may somehow be having path issues with your
executable in a Python environment

Try using this function with 'ffmpeg':

    
    
    def is_exe(prog):
        for path in os.environ["PATH"].split(os.pathsep):
            if os.path.isfile(os.path.join(path, prog)):
                if os.access(os.path.join(path, prog), os.X_OK):
                    return os.path.join(path, prog)
                else:
                    print "Program '%s' found in '%s', but lacks executable permissions." % (prog, path)
        return False
    

If it returns `False`, you're having problems with Python running ffmpeg,
otherwise it's ffmpeg which is having problems making sense of your arguments.

