我正在尝试看看是否可以让 PyAudio 从 Kubuntu 计算机上的 USB 麦克风录音。当我运行此脚本时,它确实会创建一个文件,但该文件不包含音频。甚至没有背景音乐......
我正在尝试看看是否可以让 PyAudio 从 Kubuntu 计算机上的 USB 麦克风录音。当我运行此脚本时,它确实会创建一个文件,但该文件不包含音频。甚至没有背景白噪声。我可以确认我的麦克风在音频设备设置和 OBS 中工作正常。第一个打印语句确实显示了正确的设备名称。我使用以下代码:
import pyaudio
import wave
FRAMES_PER_BUFFER = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 48000
RECORD_SECONDS = 2
WAVE_OUTPUT_FILENAME = "voice.wav"
audio = pyaudio.PyAudio()
stream = audio.open(format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
frames_per_buffer=FRAMES_PER_BUFFER,
input_device_index=2)
print("recording from device " + str(audio.get_device_info_by_host_api_device_index(0, 2).get('name')))
frames = []
for i in range(0, int(RATE / FRAMES_PER_BUFFER * RECORD_SECONDS)):
data = stream.read(FRAMES_PER_BUFFER)
frames.append(data)
print("done recording")
stream.stop_stream()
stream.close()
audio.terminate()
wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(CHANNELS)
wf.setsampwidth(audio.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(frames))
wf.close()
它创建以下输出:
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.rear
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.center_lfe
ALSA lib pcm.c:2664:(snd_pcm_open_noupdate) Unknown PCM cards.pcm.side
ALSA lib pcm_route.c:877:(find_matching_chmap) Found no matching channel map
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
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
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
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib pcm_oss.c:397:(_snd_pcm_oss_open) Cannot open device /dev/dsp
ALSA lib confmisc.c:160:(snd_config_get_card) Invalid field card
ALSA lib pcm_usb_stream.c:482:(_snd_pcm_usb_stream_open) Invalid card 'card'
ALSA lib confmisc.c:160:(snd_config_get_card) Invalid field card
ALSA lib pcm_usb_stream.c:482:(_snd_pcm_usb_stream_open) Invalid card 'card'
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
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
JackShmReadWritePtr::~JackShmReadWritePtr - Init not done for -1, skipping unlock
recording from device USB Audio Device: - (hw:1,0)
done recording
我尝试使用 sudo 运行该脚本,但似乎没有任何变化。我更改了一些 PulseAudio 设置,使其忽略我的 USB 麦克风,因为起初该脚本根本没有检测到麦克风。它现在可以识别麦克风,但仍在创建空音频文件。
我是 Linux 新手,正在尝试在具有 Ubuntu 18.04.4 LTS(GNU/Linux 4.15.0-106-generic x86_64)的实例上安装 Docker。我正在遵循在此处找到的指南:https://docs.do...
我是 Linux 新手,正在尝试在装有 Ubuntu 18.04.4 LTS(GNU/Linux 4.15.0-106-generic x86_64)的实例上安装 Docker。我按照此处找到的指南进行操作: https://docs.docker.com/engine/install/ubuntu/
第一步涉及运行以下一系列命令:
sudo apt-get update
sudo apt-get install ca-certificates curl
但是,当我尝试运行 sudo apt-get install ca-certificates curl 时,出现以下错误:
$ sudo apt-get install ca-certificates curl
Reading package lists... Done
Building dependency tree
Reading state information... Done
You might want to run 'apt --fix-broken install' to correct these.
The following packages have unmet dependencies:
apt : Depends: adduser but it is not going to be installed
Depends: gpgv but it is not going to be installed or
gpgv2 but it is not going to be installed or
gpgv1 but it is not going to be installed
Depends: ubuntu-keyring but it is not going to be installed
Depends: libapt-pkg5.0 (>= 1.6.12ubuntu0.2) but it is not going to be installed
Depends: libc6 (>= 2.15) but it is not going to be installed
Depends: libgnutls30 (>= 3.5.6) but it is not going to be installed
Depends: libseccomp2 (>= 1.0.1) but it is not going to be installed
ca-certificates : Depends: openssl (>= 1.1.0) but it is not going to be installed
Depends: debconf (>= 0.5) but it is not going to be installed or
debconf-2.0
curl : Depends: libc6 (>= 2.17) but it is not going to be installed
Depends: libcurl4 (= 7.58.0-2ubuntu3.24) but it is not going to be installed
Depends: zlib1g (>= 1:1.1.4) but it is not going to be installed
libgcc1 : Depends: libc6 (>= 2.14) but it is not going to be installed
libstdc++6 : Depends: libc6 (>= 2.18) but it is not going to be installed
E: Unmet dependencies. Try 'apt --fix-broken install' with no packages (or specify a solution).
当我尝试按照错误提示进行操作,即运行命令 apt --fix-broken install 时,它不起作用并引发以下错误:
E: Cannot get debconf version. Is debconf installed?
debconf: apt-extracttemplates failed: No such file or directory
Extracting templates from packages: 56%E: Cannot get debconf version. Is debconf installed?
debconf: apt-extracttemplates failed: No such file or directory
Extracting templates from packages: 100%
(Reading database ... 609 files and directories currently installed.)
Preparing to unpack .../libc6_2.27-3ubuntu1.6_amd64.deb ...
open2: Illegal seek at /usr/share/perl/5.26/IPC/Open3.pm line 210.
dpkg: error processing archive /var/cache/apt/archives/libc6_2.27-3ubuntu1.6_amd64.deb (--unpack):
new libc6:amd64 package pre-installation script subprocess returned error exit status 29
Errors were encountered while processing:
/var/cache/apt/archives/libc6_2.27-3ubuntu1.6_amd64.deb
E: Sub-process /usr/bin/dpkg returned an error code (1)
我能做些什么?
我正在尝试在具有 Ubuntu 18.04.4 LTS(GNU/Linux 4.15.0-106-generic x86_64)的实例上安装 Docker。