Skip to content

Instantly share code, notes, and snippets.

@pranav6670
pranav6670 / autoDet_test.py
Last active July 27, 2020 13:21
Test Arduino autoDetect with blink example.
import pyfirmata
import time
import serial.tools.list_ports
ports = list(serial.tools.list_ports.comports())
Arduino_ports = []
for p in ports:
if 'Arduino' in p.description:
@pranav6670
pranav6670 / detectArduino.py
Created July 27, 2020 13:01
Detect arduino connected to any of ports.
import serial.tools.list_ports
ports = list(serial.tools.list_ports.comports())
Arduino_ports = []
for p in ports:
if 'Arduino' in p.description:
Arduino_ports.append(p)
print("Board detected at")
if len(Arduino_ports) == 0:
print("no Arduino board detected")
@pranav6670
pranav6670 / model.py
Last active August 18, 2019 07:40
Audio Classification Model
def conv_model():
model = Sequential()
model.add(Conv2D(16, (3, 3), activation='relu', strides=(1, 1),
padding='same', input_shape=input_shape))
model.add(Conv2D(32, (3, 3), activation='relu', strides=(1,1),
padding='same'))
model.add(Conv2D(64, (3, 3), activation='relu', strides=(1,1),
padding='same'))
model.add(Conv2D(128, (3, 3), activation='relu', strides=(1,1),
padding='same'))
@pranav6670
pranav6670 / preprocess.py
Last active March 4, 2022 12:18
A envelope detection to downsample and clean audio data
def envelope(y, rate, threshold):
mask = []
y = pd.Series(y).apply(np.abs)
y_mean = y.rolling(window=int(rate/10), min_periods=1, center=True).mean()
for mean in y_mean:
if mean > threshold:
mask.append(True)
else:
mask.append(False)
return mask
@pranav6670
pranav6670 / recordaudio_realtime.py
Last active August 18, 2019 06:44
Record audio using PyAudio in real-time
self.FORMAT = pyaudio.paInt16
self.CHANNELS = 1
self.RATE = 44100
self.CHUNK = 1024
self.WAVE_OUTPUT_FILENAME = "file.wav"
self.RECORD_SECONDS = 20
def record(self):
self.audio = pyaudio.PyAudio()
# start Recording