Raspberry pi1 model b, with pixel의 5
2830 단어 PyaudioRaspberryPi1
Raspberry pi1 model b로 USB 오디오 그룹을 만들어 보았습니다.
사진.
컨디션
Raspberry pi 1 model b(element14)
raspbian 2016-11-25 jessie with pixel
sd_card MF-RUMSD08GL elecom
HDMI to VGA adapter(amazon)
usb keyboard(nec)
usb mouse(nec)
usb audio C-Media Electronics
연결 확인
lsusb
Bus 001 Device 007: ID 03ee:6402 Mitsumi
Bus 001 Device 006: ID 0409:0019 NEC Corp. 109 Japanese Keyboard with Bus-Powered Hub
Bus 001 Device 005: ID 0409:55aa NEC Corp. Hub
Bus 001 Device 004: ID 0d8c:000c C-Media Electronics, Inc. Audio Adapter
Bus 001 Device 003: ID 0424:ec00 Standard Microsystems Corp. SMSC9512/9514 Fast Ethernet Adapter
Bus 001 Device 002: ID 0424:9514 Standard Microsystems Corp.
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
카드, 장비 확인aplay -l
**** ハードウェアデバイス PLAYBACK のリスト ****
カード 0: ALSA [bcm2835 ALSA], デバイス 0: bcm2835 ALSA [bcm2835 ALSA]
サブデバイス: 8/8
サブデバイス #0: subdevice #0
サブデバイス #1: subdevice #1
サブデバイス #2: subdevice #2
サブデバイス #3: subdevice #3
サブデバイス #4: subdevice #4
サブデバイス #5: subdevice #5
サブデバイス #6: subdevice #6
サブデバイス #7: subdevice #7
カード 0: ALSA [bcm2835 ALSA], デバイス 1: bcm2835 ALSA [bcm2835 IEC958/HDMI]
サブデバイス: 1/1
サブデバイス #0: subdevice #0
カード 1: Set [C-Media USB Headphone Set], デバイス 0: USB Audio [USB Audio]
サブデバイス: 1/1
サブデバイス #0: subdevice #0
방영하다aplay -D plughw:1,0 test.wav
소리
amixer sset Mic 20 -c 1
녹음하다.
arecord -f S16_LE -D plughw:1,0 test.wav
pyaudio 설치
sudo aptitude install python-pyaudio
pyaudio로 녹음하다
import pyaudio
import wave
chunk = 4096
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
RECORD_SECONDS = input('time ')
p = pyaudio.PyAudio()
stream = p.open(format = FORMAT, channels = CHANNELS, rate = RATE, input = True, input_device_index = 2, frames_per_buffer = chunk)
all = []
for i in range(0, RATE / chunk * RECORD_SECONDS):
data = stream.read(chunk)
all.append(data)
stream.close()
data = ''.join(all)
out = wave.open('test.wav','w')
out.setnchannels(1)
out.setsampwidth(2)
out.setframerate(RATE)
out.writeframes(data)
out.close()
p.terminate()
pyaudio에서 재생import pyaudio
import wave
CHUNK = 4096
filename = "test.wav"
wf = wave.open(filename, 'rb')
p = pyaudio.PyAudio()
stream = p.open(format = p.get_format_from_width(wf.getsampwidth()), channels = wf.getnchannels(), rate = wf.getframerate(), output = True)
data = wf.readframes(CHUNK)
while data != '':
stream.write(data)
data = wf.readframes(CHUNK)
stream.stop_stream()
stream.close()
p.terminate()
Reference
이 문제에 관하여(Raspberry pi1 model b, with pixel의 5), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/ohisama@github/items/a013cf2c980c6ae48969텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)