Python FFMPEG AttributeError: 'Popen' object has no attribute 'proc'
Question: I'm working on a tensorflow project that learns from an audio stream. I'm
trying to open an audio file and store the data in an array using FFMPEG. I'm
following the tutorial [here](http://zulko.github.io/blog/2013/10/04/read-and-
write-audio-files-in-python-using-ffmpeg/)

My code looks like this:

    
    
    import subprocess as sp
    FFMPEG_BIN = "ffmpeg"
    try:
        if image_file != 'train/rock/.DS_Store':
            command = [FFMPEG_BIN,
                '-i', image_file,
                '-f', 's16le',
                '-acodec', 'pcm_s16le',
                '-ar', '44100',
                '-ac', '2',
                'output.png']
            pipe = sp.Popen(command, stdout=sp.PIPE, bufsize=10**8)
            # pipe = sp.Popen(command, stdout=sp.PIPE)
            raw_audio = pipe.proc.stdout.read(88200*4)
    

But I'm getting the error:

    
    
    AttributeError: 'Popen' object has no attribute 'proc'
    


Answer: I am working with `ffmpeg` and `pyaudio`. This code works for me.

    
    
    import pyaudio   
    import subprocess as sp  
    import numpy  
    command = [ 'ffmpeg',
            '-i', "Filename", # I used a url stream 
        '-loglevel','error',
            '-f', 's16le',
            '-acodec', 'pcm_s16le',
            '-ar', '44100', # ouput will have 44100 Hz
            '-ac', '2', # stereo (set to '1' for mono)
            '-']  
    pipe = sp.Popen(command, stdout=sp.PIPE, bufsize=10**8)  
    p = pyaudio.PyAudio()  #PyAudio helps to reproduce raw data in pipe.  
    stream = p.open(format = pyaudio.paInt16,
                    channels = 2,
                    rate = 44100,
                    output = True)  
    while True:  
        raw_audio = pipe.stdout.read(44100*2) #get raw data   
        stream.write(raw_audio) # reproduce  
        # Convert raw data in array with numpy  
        audio_array = numpy.fromstring(raw_audio, dtype="int16")  
        audio_array = audio_array.reshape((len(audio_array)/2,2))  
    stream.stop_stream()  
    stream.close()
    

  

In ubuntu you can install `pyaudio` with:

    
    
    sudo apt-get install python-pyaudio python3-pyaudio 
    

or

    
    
    pip install pyaudio 
    

