How can I plot on matplotlib input signal from microphone? I have tried to plot with plt.plot(frames) but frames is for some reason a string?
a) Why is frames variable a string list?
b) Why is data variable string list?
c) Should they represent energy/amplitude of single sample and be integers?
d) Why is length of data 2048 when I specified I want chunk size of 1024?
(I guess because i use paInt16, but cannot see still why it couldn't be 1024)
I have the following code for microphone input:
import pyaudio
import audioop
import matplotlib.pyplot as plt
import numpy as np
from itertools import izip
import wave
FORMAT = pyaudio.paInt16 # We use 16bit format per sample
CHANNELS = 1
RATE = 44100
CHUNK = 1024 # 1024bytes of data red from a buffer
RECORD_SECONDS = 3
WAVE_OUTPUT_FILENAME = "file.wav"
audio = pyaudio.PyAudio()
# start Recording
stream = audio.open(format=FORMAT,
channels=CHANNELS,
rate=RATE, input=True,
frames_per_buffer=CHUNK)
frames = []
for i in range(0, int(RATE / CHUNK * RECORD_SECONDS)):
data = stream.read(CHUNK)
frames.append(data)
frames = ''.join(frames)
stream.stop_stream()
stream.close()
audio.terminate()


frames = ''.join(frames). You don't need to do that, since you already appended all the frames you need, you have a list.frameswas a list of strings? Anyway, Stream.read() is suppossed to return a string, as specified in the API Documentation: people.csail.mit.edu/hubert/pyaudio/docsbin front:b"".join(frames)