In [1]:
import math
import struct
import pyaudio
import wave
CHUNK = 1024
CHANNELS = 1
RATE = 44100
FORMAT = pyaudio.paInt16
WIDTH = 2
FILENAME = "tone.wav"
def play_frames(frames, chunk, channels, framerate, sample_width):
p = pyaudio.PyAudio()
stream = p.open(format=p.get_format_from_width(sample_width),
channels=channels,
rate=framerate,
output=True)
for frame in frames:
stream.write(frame)
stream.stop_stream()
stream.close()
p.terminate()
def write_frames(frames, filename):
wav_file=wave.open(filename,"w")
sampwidth = 2
comptype= "NONE"
compname= "not compressed"
wav_file.setparams((CHANNELS, sampwidth, RATE, len(frames), comptype, compname))
for s in frames:
wav_file.writeframes(s)
wav_file.close()
def play_file(filename):
CHUNK = 1024
wf = wave.open(filename, 'rb')
p = pyaudio.PyAudio()
stream = p.open(format=p.get_format_from_width(wf.getsampwidth()),
channels=wf.getnchannels(),
rate=wf.getframerate(),
output=True)
data = wf.readframes(CHUNK)
while data != '':
stream.write(data)
data = wf.readframes(CHUNK)
stream.stop_stream()
stream.close()
p.terminate()
In [2]:
avgs = [np.median(l) for l in list(quietnet.chunks(freq_samples, FRAME_LENGTH))]
setup_graph(title='Frequency f Interest over Time', x_label='Time', y_label='Frequency')
plot(avgs, 'grey')
plot(avgs, '.')
In [5]:
a = '\xae'
In [6]:
16 * 16
Out[6]:
In [7]:
import pyaudio
import wave
WAVE_OUTPUT_FILENAME = "wave.out"
FORMAT = pyaudio.paInt16
p = pyaudio.PyAudio()
wf = wave.open(WAVE_OUTPUT_FILENAME, 'wb')
wf.setnchannels(1)
wf.setsampwidth(p.get_sample_size(FORMAT))
wf.setframerate(RATE)
wf.writeframes(b''.join(buffers))
wf.close()
In [9]:
44 * 5 * 200
Out[9]:
In [ ]: