2014-01-06 7 views
2

제 목표는 pyaudio에서 제공하는 문자열을 int16으로 언팩 한 다음 수정하여 다시 재생하여 재생하는 것입니다. pyaudio에서 struct.pack/unpack을 올바르게 사용하는 방법은 무엇입니까?

내가 (코드는 다른 게시물에서 복사) 지금까지 무엇을 가지고 있습니다 :

#data contains my string of interleaved int16 data 

#this code should unpack it accordingly 
# 1 short out of each 2 chars in data 
count = len(data)/2 
format = "%dh"%(count) #results in '2048h' as format: 2048 short 
shorts = struct.unpack(format, data) 

#here some modifications will take place but are left out to test packing 

#now i need to pack my short data back to pyaudio compliant string 
#i have tried the following with no success. just random noise 
struct.pack(str(len(shorts)*2) + "s", str(shorts)) 

이제 내 질문 :

  • 에 다시 내 데이터를 얻을 수 struct.pack에 대한 올바른 인수 일 것입니다 무슨 파이 오디오 문자열?
+0

이 코드를 어디서 받았습니까? – aIKid

+0

@aIKid [첫 번째 답변은 여기] (http://stackoverflow.com/questions/4160175/detect-tap-with-pyaudio-from-live-mic) –

답변

1

좋아 내가 알려서 답을 발견

struct.pack("%dh"%(len(shorts)), *list(shorts)) 

결과를 pyaudio에 대한 올바른 형식의 문자열.

그럼에도 불구하고 나는 기꺼이 함수 호출과 올바른 사용법을 설명하는 다른 답변을 수락합니다!