我正在运行Ubuntu 11.04,Python 2.7.1并想安装Pyaudio.所以我跑了,
$ sudo easy_install pyaudio
在终端和进程退出时出现以下错误消息,
Searching for pyaudio
Reading http://pypi.python.org/simple/pyaudio/
Reading http://people.csail.mit.edu/hubert/pyaudio/
Best match: pyaudio 0.2.4
Downloading http://people.csail.mit.edu/hubert/pyaudio/packages/pyaudio-0.2.4.tar.gz
Processing pyaudio-0.2.4.tar.gz
Running PyAudio-0.2.4/setup.py -q bdist_egg --dist-dir /tmp/easy_install-0Tetss/PyAudio-0.2.4/egg-dist-tmp-PYy9T8
In file included from /usr/include/python2.7/Python.h:8:0,
from src/_portaudiomodule.c:30:
/usr/include/python2.7/pyconfig.h:1155:0: warning: "_POSIX_C_SOURCE" redefined
/usr/include/features.h:214:0: note: this is the location of the previous definition
src/_portaudiomodule.c:31:23: fatal error: portaudio.h: No such file or directory
compilation terminated.
error: Setup script exited with error: command 'gcc' failed with exit status 1
我不确定是要在askubuntu.com上发布这个,还是在stackoveflow中发布,但无论如何它都在stackoverflow中.另外我google了一下这个问题,通过安装python-dev找到了解决了一些问题.我已经安装了python-dev.可能出了什么问题?
UPDATE
以下是安装libportaudio-dev后出现的新错误,
Searching for pyaudio …
我正在使用mac osx 10.10正如PyAudio主页所说,我使用了安装PyAudio
brew install portaudio
pip install pyaudio
Run Code Online (Sandbox Code Playgroud)
portaudio的安装似乎很成功,我可以在/ usr/local/include和/ usr/local/lib中找到头文件和库,但是当我尝试安装pyaudio时,它会给我一个错误
src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
#include "portaudio.h"
^
1 error generated.
error: command 'cc' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)
实际上它在/ usr/local/include中为什么找不到该文件?类似问题的一些答案对我不起作用(比如使用virtualenv,或者手动编译),我想找到一种简单的方法来解决这个问题.
我正在使用PyAudio来录制麦克风的输入.
由于音频录制对我来说很好,我应该尝试简单地抑制其错误消息吗?还是有办法解决它们?
ALSA lib pcm.c:2212:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2212:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2212:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib audio/pcm_bluetooth.c:1613:(audioservice_expect) BT_GET_CAPABILITIES failed : Input/output error(5)
ALSA lib audio/pcm_bluetooth.c:1613:(audioservice_expect) BT_GET_CAPABILITIES failed : Input/output error(5)
ALSA lib audio/pcm_bluetooth.c:1613:(audioservice_expect) BT_GET_CAPABILITIES failed : Input/output error(5)
ALSA lib audio/pcm_bluetooth.c:1613:(audioservice_expect) BT_GET_CAPABILITIES failed : Input/output error(5)
ALSA lib pcm_dmix.c:957:(snd_pcm_dmix_open) The dmix plugin supports only playback stream
ALSA lib pcm_dmix.c:1018:(snd_pcm_dmix_open) unable to open slave
Cannot connect to server socket err = No such file or …Run Code Online (Sandbox Code Playgroud) 我正试图在python中进行实时绘图声音.我需要从麦克风上取下块.
使用PyAudio,尝试使用
import pyaudio
import wave
import sys
chunk = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
RECORD_SECONDS = 5
WAVE_OUTPUT_FILENAME = "output.wav"
p = pyaudio.PyAudio()
stream = p.open(format = FORMAT,
channels = CHANNELS,
rate = RATE,
input = True,
frames_per_buffer = chunk)
print "* recording"
all = []
for i in range(0, RATE / chunk * RECORD_SECONDS):
data = stream.read(chunk)
all.append(data)
print "* done recording"
stream.close()
p.terminate()
Run Code Online (Sandbox Code Playgroud)
之后,我得到了以下错误:
* recording
Traceback (most recent call last):
File …Run Code Online (Sandbox Code Playgroud) 我在Ubuntu 10.10 x64中的Enthought Python Distribution(Python 2.6.6)下使用PyAudio.
>>> import pyaudio
>>> pa = pyaudio.PyAudio()
>>> pa.get_default_input_device_info()
Traceback (most recent call last):
File "<pyshell#24>", line 1, in <module>
pa.get_default_input_device_info()
File "/usr/lib/python_epd/lib/python2.6/site-packages/pyaudio.py", line 936, in get_default_input_device_info
device_index = pa.get_default_input_device()
IOError: No Default Input Device Available
Run Code Online (Sandbox Code Playgroud)
如果我尝试打开输入流,这是我得到的相同错误.存在相应的错误"IOError:No Default Output Device Available"
我第一次尝试:
pip install pyaudio
Run Code Online (Sandbox Code Playgroud)
但有人告诉我
-bash: pip: command not found
Run Code Online (Sandbox Code Playgroud)
然后我尝试了:
pip3 install pyaudio
Run Code Online (Sandbox Code Playgroud)
然后我得到了:
src/_portaudiomodule.c:29:10: fatal error: 'portaudio.h' file not found
#include "portaudio.h"
^
1 error generated.
error: command '/usr/bin/clang' failed with exit status 1
----------------------------------------
Command "/Library/Frameworks/Python.framework/Versions/3.4/bin/python3.4 -c "import setuptools, tokenize;__file__='/private/var/folders/77/gz1txkwj2z925vk6jrkx3wp80000gn/T/pip-build-43z_qk7o/pyaudio/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /var/folders/77/gz1txkwj2z925vk6jrkx3wp80000gn/T/pip-tkf78ih4-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /private/var/folders/77/gz1txkwj2z925vk6jrkx3wp80000gn/T/pip-build-43z_qk7o/pyaudio
Run Code Online (Sandbox Code Playgroud)
但我安装了portaudio
brew install portaudio
Run Code Online (Sandbox Code Playgroud)
警告:已安装portaudio-19.20140130
那我该怎么办?非常感谢,这是我第一次使用pyaudio,所以.......
:)
当我尝试在 python-3.10.1 virtualenv(使用 python-3.9.0 venv 创建并升级)中使用 PyAudio-0.2.11 播放波形文件时,我收到了一个异常,没有播放任何内容,其他的一切正常。
Exception in thread WavPlayer:rsrc/sound.wav:
Traceback (most recent call last):
File "/usr/lib/python3.10/threading.py", line 1009, in _bootstrap_inner
self.run()
File "/Code/py/tetris/tetris.py", line 39, in run
self.play()
File "/Code/py/tetris/tetris.py", line 35, in play
self.stream.write(data)
File "/Code/py/tetris/.venv/lib/python3.10/site-packages/pyaudio.py", line 584, in write
pa.write_stream(self._stream, frames, num_frames,
SystemError: PY_SSIZE_T_CLEAN macro must be defined for '#' formats
Run Code Online (Sandbox Code Playgroud)
我不知道'#' format代表什么,我确信我的代码与 C API 无关,但它在 python-3.9.x 下运行良好,这是 PyAudio 库本身的问题吗?我该如何解决这个问题?
尝试按照这里的说明安装pyaudio :
$ git clone http://people.csail.mit.edu/hubert/git/pyaudio.git
$ cd pyaudio
$ sudo python setup.py install
running install
running build
running build_py
running build_ext
building '_portaudio' extension
gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -I/usr/include/python2.7 -c src/_portaudiomodule.c -o build/temp.linux-x86_64-2.7/src/_portaudiomodule.o
In file included from /usr/include/python2.7/Python.h:8:0,
from src/_portaudiomodule.c:28:
/usr/include/python2.7/pyconfig.h:1161:0: warning: "_POSIX_C_SOURCE" redefined [enabled by default]
/usr/include/features.h:215:0: note: this is the location of the previous definition
src/_portaudiomodule.c:29:23: fatal error: portaudio.h: No such file or directory
compilation terminated.
error: command 'gcc' …Run Code Online (Sandbox Code Playgroud) 我正在尝试用pip安装pyaudio:
pip install pyaudio
Run Code Online (Sandbox Code Playgroud)
在virtualenv但我收到一个错误:
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1
Run Code Online (Sandbox Code Playgroud)
整个输出:
Collecting pyaudio
Using cached PyAudio-0.2.9.tar.gz
Building wheels for collected packages: pyaudio
Running setup.py bdist_wheel for pyaudio ... error
Complete output from command /home/mertyildiran/Downloads/VirtualEnvironment/vir1/Cerebrum/ENV/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-GCltlv/pyaudio/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" bdist_wheel -d /tmp/tmpyR6J73pip-wheel- --python-tag cp27:
running bdist_wheel
running build
running build_py
creating build
creating build/lib.linux-x86_64-2.7
copying src/pyaudio.py -> build/lib.linux-x86_64-2.7
running build_ext
building '_portaudio' extension
creating build/temp.linux-x86_64-2.7
creating build/temp.linux-x86_64-2.7/src
x86_64-linux-gnu-gcc -pthread -fno-strict-aliasing -DNDEBUG -g …Run Code Online (Sandbox Code Playgroud) pyaudio ×10
python ×10
alsa ×1
audio ×1
enthought ×1
gcc ×1
linux ×1
macos ×1
microphone ×1
pip ×1
portaudio ×1
python-3.4 ×1
python-3.x ×1
virtualenv ×1