8wDlpd.png
8wDFp9.png
8wDEOx.png
8wDMfH.png
8wDKte.png

PyAudio 录音结果为空

Abdul Qadeer 2月前

58 0

我正在尝试看看是否可以让 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 麦克风,因为起初该脚本根本没有检测到麦克风。它现在可以识别麦克风,但仍在创建空音频文件。

帖子版权声明 1、本帖标题:PyAudio 录音结果为空
    本站网址:http://xjnalaquan.com/
2、本网站的资源部分来源于网络,如有侵权,请联系站长进行删除处理。
3、会员发帖仅代表会员个人观点,并不代表本站赞同其观点和对其真实性负责。
4、本站一律禁止以任何方式发布或转载任何违法的相关信息,访客发现请向站长举报
5、站长邮箱:yeweds@126.com 除非注明,本帖由Abdul Qadeer在本站《ubuntu》版块原创发布, 转载请注明出处!
最新回复 (0)
  • 当前环境是ubuntu server 20,安装了nginx。现在想要实现的是http://192.168.1.5/c1234 --> http://192.168.1.5:8081/webhttp://192.168.1.5/c5678 --> http://192.168.1.5:8082/web

    当前环境是 ubuntu server 20,已安装 nginx。

    现在我想要实现的是 http://192.168.1.5/c1234 --> http://192.168.1.5:8081/web

    http://192.168.1.5/c5678 --> http://192.168.1.5:8082/web

    端口信息存储在 csv 文件中,例如

    c1234=8081
    c5678=8082
    

    是否可以使用 grep 来获取该端口?

    我应该搜索什么关键词?代理、转发还是重写?欢迎任何网页链接。

    谢谢

返回
作者最近主题: