Code: Select all
IOError: [Errno Input overflowed] -9981Code: 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()