Skip to content

Instantly share code, notes, and snippets.

View aallan's full-sized avatar

Alasdair Allan aallan

View GitHub Profile
@aallan
aallan / listen.py
Last active September 21, 2020 23:45
Example script using TensorFlow on the Raspberry Pi to listen for commands.
#!/usr/bin/env python3
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@aallan
aallan / mirror_listen.py
Created November 11, 2017 04:25
Magic Mirror weather implementation using TensorFlow and Google Cloud Speech API
#!/usr/bin/env python3
from collections import deque
import threading
import requests
import time
import wave
import tensorflow as tf
import numpy as np
from tensorflow.contrib.framework.python.ops import audio_ops as contrib_audio
@aallan
aallan / face_detection_camera.py
Created January 19, 2018 03:04
Example script using the Vision bonnet to detect faces in the camera frame.
#!/usr/bin/env python
# Copyright 2017 Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
@aallan
aallan / j1.v
Created March 5, 2018 12:08
J1 stack-based CPU, intended for FPGAs.
// J1 Forth CPU
// http://www.excamera.com/sphinx/fpga-j1.html
// http://www.excamera.com/files/j1.pdf
module j1(
input sys_clk_i, input sys_rst_i, input [15:0] io_din,
output io_rd, output io_wr, output [15:0] io_addr, output [15:0] io_dout);
wire [15:0] insn;
wire [15:0] immediate = { 1'b0, insn[14:0] };
@aallan
aallan / face_detection_camera_with_file.py
Last active August 19, 2018 22:31
Example script using the Vision bonnet to detect faces in the camera frame and write the number of faces to a file.
#!/usr/bin/env python
import argparse
from aiy.vision.inference import CameraInference
from aiy.vision.models import face_detection
from examples.vision.annotator import Annotator
from picamera import PiCamera
@aallan
aallan / mirror_with_file.py
Last active May 23, 2019 14:56
Magic Mirror weather implementation using the Google AIY Projects Voice Kit, checking an NFS mounted file to see if the Vision Kit has detected a face before proceeding.
#!/usr/bin/env python3
import threading
import requests
import time
import httplib2
import time
import aiy.audio
import aiy.cloudspeech
@aallan
aallan / server_notcached.py
Created April 10, 2018 12:04
A non-caching version of Python's SimpleHTTPServer
#!/usr/bin/env python
import SimpleHTTPServer
class MyHTTPRequestHandler(SimpleHTTPServer.SimpleHTTPRequestHandler):
def end_headers(self):
self.send_my_headers()
SimpleHTTPServer.SimpleHTTPRequestHandler.end_headers(self)
def send_my_headers(self):
self.send_header("Cache-Control", "no-cache, no-store, must-revalidate")
@aallan
aallan / face_detection_with_servo.py
Created April 23, 2018 15:15
A Python script using the AIY Projects Vision Kit to turn a servo motor in the direction of detected face.
#!/usr/bin/env python3
import argparse
from aiy.vision.inference import CameraInference
from aiy.vision.models import face_detection
from examples.vision.annotator import Annotator
from picamera import PiCamera
from gpiozero import Servo
@aallan
aallan / do_you_think_he_saurs.py
Created April 23, 2018 21:28
Using the AIY Projects Vision Kit and a micro-servo to build a face-tracking dinosaur. See https://medium.com/@aallan/the-do-you-think-he-saurs-f1fdbc8846de.
#!/usr/bin/env python3
import argparse
from aiy.vision.inference import CameraInference
from aiy.vision.models import face_detection
from examples.vision.annotator import Annotator
from picamera import PiCamera
from gpiozero import Servo
@aallan
aallan / assistant_library_with_button_demo.py
Last active July 12, 2018 08:35
Run a recognizer using the Google Assistant Library with button support.
import logging
import platform
import sys
import threading
import aiy.assistant.auth_helpers
from aiy.assistant.library import Assistant
import aiy.voicehat
from google.assistant.library.event import EventType