简体   繁体   English

当我尝试录制某些内容时出现 Pyaudio 错误

[英]Pyaudio error when i try to record something

Am working on a distant server (ubuntu) via Ssh, and i want to record using pyaudio module, i have it我正在通过 Ssh 在远程服务器(ubuntu)上工作,我想使用 pyaudio 模块进行录制,我有

already installed.已安装。

My code:我的代码:

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()

When i run i get the following errors:当我运行时,我收到以下错误:

Traceback (most recent call last):
  File "record.py", line 13, in <module>
    stream = p.open(format=FORMAT,
  File "/usr/local/lib/python3.8/dist-packages/PyAudio-0.2.11-py3.8-linux-x86_64.egg/pyaudio.py", line 750, in open
    stream = Stream(self, *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/PyAudio-0.2.11-py3.8-linux-x86_64.egg/pyaudio.py", line 441, in __init__
    self._stream = pa.open(**arguments)
OSError: [Errno -9996] Invalid input device (no default output device)

I tried to change channels number to 1 but didn't work我试图将频道号更改为 1 但没有用

Am working on a distant server (ubuntu) via Ssh, and i want to record using pyaudio module, i have it我正在通过 Ssh 在远程服务器(ubuntu)上工作,我想使用 pyaudio 模块进行录制,我有

already installed.已安装。

My code:我的代码:

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()

When i run i get the following errors:当我运行时,我收到以下错误:

Traceback (most recent call last):
  File "record.py", line 13, in <module>
    stream = p.open(format=FORMAT,
  File "/usr/local/lib/python3.8/dist-packages/PyAudio-0.2.11-py3.8-linux-x86_64.egg/pyaudio.py", line 750, in open
    stream = Stream(self, *args, **kwargs)
  File "/usr/local/lib/python3.8/dist-packages/PyAudio-0.2.11-py3.8-linux-x86_64.egg/pyaudio.py", line 441, in __init__
    self._stream = pa.open(**arguments)
OSError: [Errno -9996] Invalid input device (no default output device)

I tried to change channels number to 1 but didn't work我试图将频道号更改为 1 但没有用

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在尝试安装pyaudio时出现错误? - Why I get error when I try to install pyaudio? 当我尝试使用“pip install PyAudio”安装 PyAudio 模块时出现此错误……我现在该怎么办? - I got this error when I try to install the PyAudio module using 'pip install PyAudio'… What should I do now? 尝试使用 googletrans 翻译内容时出现错误 - I get an error when I try to translate something with googletrans 当我尝试在 windows 上运行代码时,Pyaudio 不起作用 - Pyaudio doesn't work when I try to run the code on windows 尝试安装PyAudio时出现错误 - I get an error when trying to install PyAudio 我肯定在我的 windows 上安装了 PyAudio,但是当我尝试安装到 Pycharm 时,我收到这条消息? - I have PyAudio installed on my windows for sure, but when I try to install into Pycharm I get this message? 即使我有最新的 PyAudio,PyAudio 也会出错 - Getting error with PyAudio even though I have the latest PyAudio 当我运行pyaudio程序时出现此错误,我该如何解决 - when I run the pyaudio program I got this error, how can l resolve this 尝试在同一设备上录制和播放时 PyAudio 不起作用 - PyAudio not working when trying to record and play on the same device 尝试安装 pyaudio 时出现 HTTP 错误 - Getting HTTP error when trying to install pyaudio
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM