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

PyAudio 录音结果为空

Abdul Qadeer 2月前

55 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)
  • 回溯(最近一次调用):文件 \'/usr/bin/idle\',第 5 行,位于 \ main() 文件 \'/usr/lib/python3.10/idlelib/pyshell.py\',第 1617 行,位于主根目录 = Tk(

    Traceback (most recent call last):
      File "/usr/bin/idle", line 5, in \<module\>
        main()
      File "/usr/lib/python3.10/idlelib/pyshell.py", line 1617, in main
        root = Tk(className="Idle")
      File "/usr/lib/python3.10/tkinter/__init__.py", line 2299, in __init__
        self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
    _tkinter.TclError: no display name and no $DISPLAY environment variable
    

    当我使用 idle 命令在 idle 中编写 python 时,我收到了此系统消息。我不知道那是什么意思。我对 ubuntu 还很陌生。我希望有人知道这个答案。

  • 在其他应用中打开音频文件,音频确实可以播放。Visual Studio Code 只是因为某种原因不想播放音频文件。

  • 这是 tkinter 在 Linux 上的错误。我不知道之前关于完全相同的错误消息的问题的答案是否会对您有所帮助。也许您的系统上没有加载 tcl/tk。

  • dawg 2月前 0 只看Ta
    引用 5

    我是 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。

  • bht 2月前 0 只看Ta
    引用 6

    当前环境是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 来获取该端口?

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

    谢谢

  • Nginx 反向代理 可以对此有所帮助。

    此设置允许您根据路径将来自 Nginx 的传入请求重定向到后端服务器。

    location ~ ^/c1234(.*)$ {
        proxy_pass http://127.0.0.1:8081/web$1;
    }
    
    location ~ ^/c5678(.*)$ {
        proxy_pass http://127.0.0.1:8082/web$1;
    }
    
    • p2

    • p3

    • p4

    测试配置并重新加载 NGINX

    sudo nginx -t
    sudo systemctl reload 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
    

    要了解更多信息,请参阅下一个文档:

    https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/

  • 谢谢。如果该端口信息存储在文件中,是否可以使用 linux grep 获取该端口?原始帖子已编辑

  • 我的意思是,你可以通过运行 python 脚本或 shell 脚本或类似的东西来读取 CSV 文件,因为 NGINX 配置是静态的,所以为了实现这一点,你应该在每次配置更改时运行代码,据我所知 NGINX 不支持像 grep 这样的命令

  • 谢谢,我想我明白你的意思了。首先使用 shell 脚本读取 csv,然后生成该 NGINX 配置。

返回
作者最近主题: