This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |