<jupyter_start><jupyter_text>This notebook uses a pre-trained Tensorflow model to make livepredictions on the audio samples recorded from a microphone.<jupyter_code>import os

from micmon.audio import AudioDevice, AudioPlayer
from micmon.model import Model

model_dir = os.path.expanduser(os.path.join('~', 'models', 'baby-monitor'))
audio_system = 'alsa'
audio_device = 'plughw:3,0'
label_names = ['negative', 'positive']<jupyter_output>DEBUG:matplotlib:(private) matplotlib data path: /usr/lib/python3.8/site-packages/matplotlib/mpl-data
DEBUG:matplotlib:matplotlib data path: /usr/lib/python3.8/site-packages/matplotlib/mpl-data
DEBUG:matplotlib:CONFIGDIR=/home/blacklight/.config/matplotlib
DEBUG:matplotlib:matplotlib version 3.3.2
DEBUG:matplotlib:interactive is False
DEBUG:matplotlib:platform is linux
DEBUG:matplotlib:loaded modules: ['sys', 'builtins', '_frozen_importlib', '_imp', '_warnings', '_frozen_importlib_external', '_io', 'marshal', 'posix', '_thread', '_weakref', 'time', 'zipimport', '_codecs', 'codecs', 'encodings.aliases', 'encodings', 'encodings.utf_8', '_signal', '__main__', 'encodings.latin_1', '_abc', 'abc', 'io', '_stat', 'stat', '_collections_abc', 'genericpath', 'posixpath', 'os.path', 'os', '_sitebuiltins', '_locale', '_bootlocale', 'types', 'importlib._bootstrap', 'importlib._bootstrap_external', 'warnings', 'importlib', 'importlib.machinery', 'importlib.abc', '_operator', 'operator', 'keyword', '[...]<jupyter_text>Load the model<jupyter_code>model = Model.load(model_dir)<jupyter_output><empty_output><jupyter_text>Play some audio from the input device<jupyter_code>with AudioDevice(audio_system, device=audio_device) as source, AudioPlayer() as player:
    for sample in source:
        player.play(sample)<jupyter_output><empty_output><jupyter_text>Record frames from an audio source and make predictions using the model<jupyter_code>with AudioDevice(audio_system, device=audio_device) as source:
    for sample in source:
        source.pause()
        prediction = model.predict(sample)
        print(prediction)
        source.resume()<jupyter_output>negative
negative
negative
negative
negative
negative
negative
negative
negative
negative
{'fraction_non_alphanumeric': 0.13528336380255943, 'fraction_numerical': 0.005027422303473492, 'mean_word_length': 7.291666666666667, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '317874', 'license': 'MIT', 'n_tokens_mistral': 711, 'n_tokens_neox': 697, 'n_words': 158, 'path': 'notebooks/predict.ipynb', 'repo_name': 'jenssss/micmon', 'size': '2188'}