2016-04-01 16 views
0

Bir ses akışından öğrenen tensorflow projesinde çalışıyorum. Altprogram modülünü (Popen ile) ve bir mp3'den ses verilerini okumak için FFMPEG kullanıyorum. Ses dosyasını Popen() ile başarıyla açtım ve çıkışı stdout üzerinden yazdırabilirim. Ancak, onu yakalayamıyorum.Python yakalama altişlem çıktısı

denedim hem read() ve communicate()

Ben here

read() basitçe hiçbir şey döner ve communicate() hata atıyor bir öğretici takip ediyorum:

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) 
: AttributeError: 'file' object has no attribute 'communicate' İşte

kod bu

Ben stdout'u iletişim gelmiştir herşeyi here ve here

cevap

4

POPEN nesneyi denedim:

pipe.communicate(str(88200*4)) 

da Stdout'a yoluyla Stderr yakalamak için:

pipe = sp.Popen(command, stdout=sp.PIPE, stderr=sp.STDOUT, stdin=sp.PIPE) 
raw_audio, _ = pipe.communicate(str(88200*4).encode()) 
print(raw_audio) 
+0

teşekkür ederiz! Kafamı duvara çarpıyordum ve tabii ki basit bir şey. Print (raw_audio) 'nun yazdırılmasının bir nedeni var mı? ('', Yok)'? –

+1

@KendallWeihe, 'stderr = sp.STDOUT' –

+0

' Popen 'öğesine eklemeyi deneyin. Şimdi sadece bu son çıkışı '