크 랜 베 리 파이 3B + 가이드 (13) pyaudio 녹음 및 재생
1846 단어 크 랜 베 리 파이python음성 인식
인터넷 에는 많은 범례 가 있 지만 wav 파일 을 재생 할 때 순환 에 걸 려 서 나 오지 못 하고 마지막 으로 공식 문서 에서 정확 한 사용 방법 을 찾 았 습 니 다.공식 문서:http://people.csail.mit.edu/hubert/pyaudio/docs/#indices-and-tables
다음은 인터넷 의 범례 와 공식 문 서 를 결합 하여 크 랜 베 리 파 에서 사용 할 수 있 는 방법 이다.
import wave
from pyaudio import PyAudio,paInt16
framerate=16000
NUM_SAMPLES=2000
chunk=2014
channels=1
sampwidth=2
TIME=20 #ms
#
def save_wave_file(filename,data):
'''save the date to the wavfile'''
wf=wave.open(filename,'wb')
wf.setnchannels(channels)
wf.setsampwidth(sampwidth)
wf.setframerate(framerate)
wf.writeframes(b"".join(data))
wf.close()
#
def my_record():
pa=PyAudio()
stream=pa.open(format = paInt16,channels=1,
rate=framerate,input=True,
frames_per_buffer=NUM_SAMPLES)
my_buf=[]
count=0
while count 0:
stream.write(data)
data = wf.readframes(CHUNK)
stream.stop_stream()
stream.close()
p.terminate()
if __name__ == '__main__':
my_record()
print('Over!')
play()
여러 프로그램 에서 pyaudio 를 사용 하면 오류 가 발생 할 수 있 습 니 다.
IOError: [Errno -9985] Device unavailable
또는 다른 장치 에서 사용 할 수 없 는 오류 와 유사 하 므 로 다음 코드 를 시도 해 보 세 요.
sudo apt-get install pulseaudio
pulseaudio --start
이것으로 끝 났 습 니 다. 여러분 을 도 울 수 있 기 를 바 랍 니 다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
크 랜 베 리 파 이 를 이용 하여 집안 의 온도 와 습 도 를 감시 하 다.우선 당신 의 크 랜 베 리 파 이 는 이미 정상적으로 작 동 하고 일 할 수 있 습 니 다. 크 랜 베 리 파이 SSH 에 들 어가 칩 라 이브 러 리 다운로드 및 컴 파일 크 랜 베 리 파이 칩 모델 을 확...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.