Code Monkey home page Code Monkey logo

assistant-hw-client's Introduction

Assistant HW Client

Assistant HW client is a Python app that uses Snowboy Hotword Detection to start recording an audio when user speaks the hotword 'computer' or when user clicks Space key from keyboard. It records the audio max 12 seconds or until user stays silent.

It creates a 1 channel, 16K rate wav file. The recorded audio will be converted to OGG using ffmpeg and will be sent as base64 encoded file to cloud. The generated OGG response audio file will be downloaded from cloud again and will be played to the user using pygame library which is 44k rate, 2 channels.

Snowboy is a customizable hotword detection engine to create hotwords like "OK Google" or "Alexa".

Installation

'install' folder includes the files to build the hotword detector 'Shared Object' which will be used by the snowboy-detect to extend Python codes functionality through C++ and other required build files to build the Assistant HW Client App.

libs folder includes the necessary static libraries which contains the compiled code for snowboy hotword detector that can be linked at compile-time.

Makefile need to be updated accordingly based on where we are compiling the 'Shared Object'. If you are building for arm based device, you need to comment out the line for X64 (line 44), and uncomment for ARM (line 50). If you are building for ubuntu-docker, you need to comment out the line for X64 (line 44), and uncomment for UBUNTU (line 47).

ubuntu64-libsnowboy-detect.a - for Ubuntu builds (tested with Ubuntu 20.04)

osx-libsnowboy-detect.a - for Macos builds (don't need to update Makefile)

Raspberry build

install.sh script can be used to build the 'Shared Object' on Linux based environment including Raspberry. Makefile needs to be updated accordingly.

It will download all necessary packages and build snowboy hotword detector shared object and copy it to the src where it will be used by snowboy detector python code. It will also download all required python packages using pip.

  chmod +x install.sh
  ./install.sh

Ubuntu Docker build

Docker commands can be used to build the docker image on the parent folder, Dockerfile contains all the necessary build commands. Makefile needs to be updated accordingly.

On Linux environment for Docker to access your IO devices, you need to include --device /dev/snd. For Windows and Macos, it is not possible to access IO devices using the same command. You need to use pulseaudio as described here to make it work.

  docker build -t assistant-hw-client .
  docker run --device /dev/snd -it assistant-hw-client

MACOS build

For a Macos build for the project, first you need to install necessary packages (portaudio, swig, sox, ffmpeg) and if required python and pip.

  brew install portaudio
  brew install swig
  brew install sox  
  brew install cmu-pocketsphinx
  brew install ffpmeg 

You need to install required python packages as well. If required you can define an alias for pip3.

  alias pip=pip3
  pip install pygame
  pip install pydub
  pip install pynput
  pip install requests
  pip install numpy
  pip install pyaudio

Or you can install those package using a single command.

  cd install
  pip install -r requirements.txt

You need to use clang++ instead of g++ on Macos. You don't need to use the make command as there is no successfull atlas build for Macos and also because Makefile is customized for Linux based builds.

You can run the below commands to build snowboy hotword detector. Please be sure to update below command using your python version on Macos with the correct paths.

  cd install/snowboy
  clang++ -I. -O3 -fPIC -D_GLIBCXX_USE_CXX11_ABI=0  -bundle -flat_namespace -undefined suppress snowboy-detect-swig.o \
        ./libs/osx-libsnowboy-detect.a -L/usr/local/opt/[email protected]/Frameworks/Python.framework/Versions/3.9/lib/python3.9/config-3.9-darwin -ldl -framework CoreFoundation -lm -ldl -framework Accelerate -o _snowboydetect.so 
  cp _snowboydetect.so snowboydetect.py ../../src/
  rm _snowboydetect.so

Usage/Examples

You need to run below command to start the application. Please be sure to install all required libraries and also ensure that you build the snowboy hotword detector and copy necessary files to required folders.

  alias python = python3
  python main.py

assistant-hw-client's People

Contributors

saul-leon avatar codefest2023 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.