I'm working on a tensorflow project that learns from an audio stream. I'm using the subprocess module (with Popen
) and FFMPEG to read in the audio data from an mp3. I successfully open the audio file with Popen()
and I can print the output through stdout
. However, I can't seem to capture it.
I have tried both read()
and communicate()
I'm following a tutorial here
read()
simply returns nothing and communicate()
throws the error: AttributeError: 'file' object has no attribute 'communicate'
Here's my code:
for image_index, image in enumerate(image_files):
count += 1
image_file = os.path.join(folder, image)
try:
output_files = "output/output" + str(count) + ".png"
if image_file != 'train/rock/.DS_Store':
command = [FFMPEG_BIN,
'-i', image_file,
'-f', 's16le',
'-acodec', 'pcm_s16le',
'-ar', '44100',
'-ac', '2',
output_files]
pipe = sp.Popen(command, stdout=sp.PIPE)
print (pipe)
raw_audio = pipe.stdout.communicate(88200*4)