gpt4 book ai didi

python - 使用USB摄像头在Ubuntu上进行pyaudio录音

转载 作者:行者123 更新时间:2023-12-02 23:48:01 27 4
gpt4 key购买 nike

我似乎无法在Xubuntu 14.10上使用pyaudio录音。

安装pyaudio后,我在这里遵循代码示例:http://people.csail.mit.edu/hubert/pyaudio/#examples

"""PyAudio example: Record a few seconds of audio and save to a WAVE file."""

import pyaudio
import wave

CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 2
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")

frames = []

for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data)

print("* done recording")

stream.stop_stream()
stream.close()
p.terminate()

wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()

我得到的是以下消息:
ALSA lib pcm_dsnoop.c:618:(snd_pcm_dsnoop_open) unable to open slave
ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2239:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
bt_audio_service_open: connect() failed: Connection refused (111)
ALSA lib pcm_dmix.c:1022:(snd_pcm_dmix_open) unable to open slave
Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jack server is not running or cannot be started
* recording
* done recording

和一个空文件。我做错了什么?
我没有普通的麦克风,因此我在USB网络摄像头上使用了麦克风,该麦克风可以很好地处理诸如大胆之类的事情。也许我需要告诉pyaudio或有关此安排的任何人?

最佳答案

看来您没有正确编译依赖项。尝试在终端中使用以下命令进行安装:

sudo apt-get install python-pyaudio

关于python - 使用USB摄像头在Ubuntu上进行pyaudio录音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28968632/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com