bluelightvision
Posts: 3
Joined: Sat Jan 10, 2015 12:35 pm

pyaudio python 3d sound-card overflow

Fri Mar 06, 2015 12:51 pm

hey guys im trying to make a program that raises the sound of a music according to the input volume by a microphone but using raspberry with a 3d sound-card im facing an error can you help me figuring out the problem

Code: Select all

  IOError: [Errno Input overflowed] -9981
this is my code

Code: Select all

 
import numpy as np
import pyaudio
import wave
import sys
import struct
# Open
w = wave.open("/home/odroid/Desktop/output.wav","rb")
q = w.getparams()
swidth = w.getsampwidth()
RATE = 48000
FORMAT = pyaudio.paInt16
CHUNK = 1024
chunk = 100
WIDTH = 2
CHANNELS = 1
frames = []
volume = 10
#swidth = w.getsampwidth()
#RATE = w.getframerate()
p = pyaudio.PyAudio()

stream = p.open(format=p.get_format_from_width(WIDTH),
                channels=CHANNELS,
                rate=RATE,
                input=True,
                output=True,
                input_device_index=1,
                frames_per_buffer=CHUNK*3)

stream1 = p.open(format=p.get_format_from_width(w.getsampwidth()),
                channels=w.getnchannels(),
                rate=w.getframerate(),
                output=True)

s = w.readframes(CHUNK)
data = stream.read(chunk)

print("* start")

while True:  
  stream1.write(s)
  s = w.readframes(CHUNK)
  data = stream.read(chunk)
  indata = struct.unpack("%dh"%(len(data)/2),data)
  fftData=np.fft.rfft(indata)
  max = abs(fftData[1:].argmax())
  if (fftData[max-1]>(500)):
    s = np.fromstring(s, np.int16) *volume
    s = struct.pack('h'*len(s), *s) 

stream1.stop_stream1()
stream1.close()
p.terminate()
w.close()
thanks in advance

Iran
Posts: 3
Joined: Tue Jul 05, 2016 2:04 am

Re: pyaudio python 3d sound-card overflow

Tue Jul 05, 2016 4:15 am

Simply @ line 43 , Change :
data = stream.read(chunk)
To :
data = stream.read(chunk,False)

Good luck ;)

Return to “Troubleshooting”