Commit e90647c8 authored by Ricardo Cebada Fuentes's avatar Ricardo Cebada Fuentes 👦🏽

Sonido de micrófono

parent 141a5b01
# -*- coding: utf-8 -*-
"""
Created on Wed Nov 27 13:48:21 2019
@author: ricardo cebada fuentes
"""
import pyaudio
import struct
import numpy as np
import matplotlib.pyplot as plt
%matplotlib tk
CHUNK=1024*4
FORMAT=pyaudio.paInt16
CHANNELS=1
RATE=44100
p=pyaudio.PyAudio()
atream=p.open(
format=FORMAT,
channels=CHANNELS,
rate=RATE,
input=True,
output=True,
frames_per_buffer=CHUNK
)
fig, ax=plt.subplots()
x=np.arrange(0,2*CHUNK,2)
line,=ax.plot(x,np.random.rand(CHUNK))
ax.set_ylim(0,255)
ax.set_xlim(0,CHUNK)
while True:
data=stream.read(CHUNK)
#Convertir data en números enteros
data_int=np.array(struck.unpack(str(2*CHUNK)+'B',data),dtype='b')[::2]+127
line.set_ydata(data_int)
fig.canvas.draw()
fig.canvas.flush_events()
ax.plot(data_int,'-')
plt.show()
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment