2014-10-15 5 views
4

Win7에서 PySudio와 함께 PreSonus AudioBox 1818VSL에 인터페이스를 시도하고 있지만 한 번에 2 채널 (스테레오) 이상을 녹음하는 데 문제가 있습니다. PreSonus 드라이버는 많은 스테레오 입력 오디오 장치 (예 : 스테레오 채널 1 & 2, 3 & 4 등)와 18 개의 입력 채널 ASIO 장치를 만듭니다. 아무런 문제없이 스테레오 장치에서 녹음 할 수 있습니다. 대기 시간을 최소화하고> 2 채널에서 녹음하려면 ASIO 장치를 사용하려고합니다.ASIO 지원 다중 채널 PyAudio

나는 ASIO, DS, WMME, WASAPI, WDMKS에 대한 지원을 컴파일 한 http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyaudio의 PyAudio 빌드를 사용 해왔다.

pyaudio_handle.is_format_supported()을 호출하면 ASIO 디바이스가 44.1, 48 및 96 kHz에서 8-32 비트 데이터를 지원함을 보여줍니다. 다음은

다음은 내가 PyAudio 입력 스트림을 생성하기 위해 사용 된 코드는 pa.get_device_info_by_index(32)

{'defaultHighInputLatency': 0.046439909297052155, 
'defaultHighOutputLatency': 0.046439909297052155, 
'defaultLowInputLatency': 0.046439909297052155, 
'defaultLowOutputLatency': 0.046439909297052155, 
'defaultSampleRate': 44100.0, 
'hostApi': 2L, 
'index': 32, 
'maxInputChannels': 18L, 
'maxOutputChannels': 18L, 
'name': u'AudioBox ASIO Driver', 
'structVersion': 2L} 

에 의해 반환 된 사전이다. 콜백 함수는 데이터를 목록으로 푸시하고 원하는 샘플 양을 얻을 때까지 pyaudio.paContinue을 반환 한 다음 pyaudio.paComplete을 반환합니다.

pyaudio_handle = pyaudio.PyAudio() 
stream = pyaudio_handle.open(
    format=pyaudio.get_format_from_width(2,unsigned=False), 
    channels=4, 
    rate=48000, 
    input=True, 
    frames_per_buffer=256, 
    input_device_index=32, 
    stream_callback=pyaudio_stream_callback, 
) 

44.1 kHz보다 빠른 속도로 ASIO 드라이버를 초기화하려고 시도하면 PyAudio가 중단되어 반환되지 않습니다. 44.1 kHz에서 초기화하면 다음 오류가 발생합니다 : IOError: [Errno Unanticipated host error] -9999.

이 오류를 해결할 수있는 도움이 필요하시면 도움이됩니다. Win7에서 실행될 때 ASIO가 PyAudio에서> 2 개의 채널로 작동한다는 증거를 얻으려고도 정했습니다. 감사.

답변

4

96 채널의 ASIO 드라이버를 사용하여 8 채널 오디오 (M- 오디오 M 트랙 Eight)를 녹음 할 수있었습니다. 4 ASIO 드라이버했다 :

p = pyaudio.PyAudio() 
p.get_device_info_by_index(4) 

에서 나는 '인덱스'발견

{'defaultLowInputLatency': 0.005804988662131519, 
'defaultHighOutputLatency': 0.09287981859410431, 
'defaultLowOutputLatency': 0.005804988662131519, 
'defaultSampleRate': 44100.0, 
'maxInputChannels': 8, 
'maxOutputChannels': 8, 
'structVersion': 2, 
'name': 'M-Audio M-Track Eight ASIO', 
'index': 4, 
'hostApi': 2, 
'defaultHighInputLatency': 0.09287981859410431} 

그래서 내가 PyAudio에 샘플 코드로 시작했지만에 scipy.io.wavfile에 웨이브로 전환 wave은 스테레오 만 지원하므로 다중 채널 .wav 파일을 작성하십시오.

import pyaudio 
import wave 
import numpy as np 
from scipy.io import wavefile 

CHUNK = 1024 
FORMAT = pyaudio.paInt16 
CHANNELS = 8 
RATE = 96000 
RECORD_SECONDS = 10 
WAVE_OUTPUT_FILENAME = "output.wav" 

p = pyaudio.PyAudio() 

stream = p.open(format=FORMAT, 
       channels=CHANNELS, 
       rate=RATE, 
       input=True, 
       input_device_index=4, 
       frames_per_buffer=CHUNK 
       ) 

print("* recording") 

frames = [] 

for i in range(0, int(RATE/CHUNK * RECORD_SECONDS)): 
    data = stream.read(CHUNK) 
    frames.append(data) 

print("* done recording") 

stream.stop_stream() 
stream.close() 
p.terminate() 


#Not really sure what b'' means in BYTE STRING but numpy needs it 
#just like wave did... 
framesAll = b''.join(frames) 

#Use numpy to format data and reshape. 
#PyAudio output from stream.read() is interlaced. 
result = np.fromstring(framesAll, dtype=np.int16) 
chunk_length = len(result)/CHANNELS 
result = np.reshape(result, (chunk_length, CHANNELS)) 

#Write multi-channel .wav file with SciPy 
wavfile.write(WAVE_OUTPUT_FILENAME,RATE,result) 

비올라! 96 kHz, 16 비트, 8 채널 .wav 파일!

아,

  • Win7에 64 비트
  • M-오디오 여덟 64 비트 윈도우 드라이버 1.0.11
  • 파이썬 3.4.2 32 비트
  • Win7에 대한
  • PyAudio 0.28에서 here 자세한 사항
  • numpy-1.9.2
  • scipy-0.15.1-win32-superpack-python3.4
+0

프레임을 저장할 때 메모리 오류를 피하기 위해 64 비트 Python으로 전환되었습니다().아직도 작동합니다. – Lucas

+0

Win7에서 실행될 때 ASIO는 PyAudio에서> 2 채널로 작동한다는 것을 보여줍니다. 나는 너의 대답을 받아 들일거야. 나는 나의 문제를 더 깊이 파헤 칠 것이다. 성공적인 테스트를 토대로, 아마도 드라이버 문제 일 것입니다. – Fitzy

+0

감사합니다. 하나는 귀하의 장치 정보에서 hostApi = 2L 것으로 나타났습니다. 최근에 PyAudio를 읽고 읽고 작업 해 보았습니다. 알파 숫자가 반환 된 유일한 시간은 ..... 단서가 될 수 있습니까? – Lucas