IO错误:[错误输入溢出] -9981 [英] IOError: [Errno Input overflowed] -9981

查看:1230
本文介绍了IO错误:[错误输入溢出] -9981的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的树莓派B型板执行上Rasbian一个PyAudio蟒蛇捕获程序,但得到的错误:

I am trying to execute a PyAudio python capturing program on Rasbian in my RaspberryPi model B board, but getting error:

Traceback (most recent call last):
  File "/home/pi/pythonsound/record.py", line 35, in <module>
    data = stream.read(CHUNK)
  File "/usr/local/lib/python2.7/dist-packages/pyaudio.py", line 605, in read
    return pa.read_stream(self._stream, num_frames)
IOError: [Errno Input overflowed] -9981

有也有,但不是有效的一些其他建议
下面是我尝试过,
这是code

There are some other suggestions available but not effective Here is what I've tried, This is the code

import pyaudio
import wave
import sys
CHUNK = 1024
FORMAT = pyaudio.paInt16
CHANNELS = 1
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()

这是我的USB声卡设备信息,

This is my USB Audio Card device info,

{'defaultSampleRate': 44100.0, 
'defaultLowOutputLatency': 0.011609977324263039, 
'defaultLowInputLatency': 0.011609977324263039, 
'maxInputChannels': 1L, 
'structVersion': 2L, 
'hostApi': 0L, 
'index': 0, 
'defaultHighOutputLatency': 0.046439909297052155, 
'maxOutputChannels': 2L, 
'name': u
'USB PnP Sound Device: USB Audio (hw:0,0)', 
'defaultHighInputLatency': 0.046439909297052155}

可以请你指导我解决这个问题呢?

can you please guide me resolve this problem?

推荐答案

阅读不同的用户体验后,他们只用变化的参数值修正的。

After reading different users experience and their of correction with just changing the value of parameters.

作为专家介绍以上,实际的原因

As an expert describe above, the actual reason of

IOError: [Errno Input overflowed] -9981

所以我也开始增加块的价值,最后我也得到了这个错误的成功。
现在修正后我的编码是:

so I also start increasing the value of CHUNK and at last I also get success over this error. And now my coding after correction is:

import pyaudio, wave, time, sys
from datetime import datetime

CHUNK = 8192
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
RECORD_SECONDS = 5

current_time = str(datetime.now())  #"Date/Time for File Name"
current_time = "_".join(current_time.split()).replace(":","-")
current_time = current_time[:-7]
WAVE_OUTPUT_FILENAME = 'Audio_'+current_time+'.wav'

p = pyaudio.PyAudio()

stream = p.open(format=FORMAT, channels = CHANNELS, rate = RATE, input = True, input_device_index = 0, frames_per_buffer = CHUNK)

print("* recording")

frames = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
    print i
    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()

这篇关于IO错误:[错误输入溢出] -9981的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆