首先安装pyaudio
到官网下载pa_stable_v190600_20161030.tgz (←或者直接点击下载)
2, 下载之后解压进入文件夹
3, 在文件夹下打开命令行输入以下命令
conda create -n listen python=3.7.1
source activate listen
$ ./configure
$ make
$ sudo make install
$ sudo apt-get install libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0
$ pip install pyaudio
我看了好多。。。。安装教程,都会报错,于是我一气之下。创建了一个虚拟环境,我就不信在干净的环境下,我装不成功。。结果被我装成功了哈哈哈。
结果安装成功了,也可以成功import
实现python实时监听麦克风
代码如下:
# -*- coding: utf-8 -*-
import pyaudio
import wave
import numpy as np
def Monitor():
CHUNK = 512
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 48000
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "cache.wav"
p = pyaudio.PyAudio()
stre