Giter VIP home page Giter VIP logo

audioclassifier-mqtt's Introduction

AudioClassifier-MQTT

Use the yamnet TensorFlow model to classify live audio from a microphone and publish the predicted results to Home Assistant via MQTT

Configuration

Open config.py and set the following variables:

  • MQTT_HOST: MQTT server hostname
  • MQTT_PORT: MQTT server port
  • MQTT_USER: MQTT server username (optional)
  • MQTT_PASS: MQTT server password (optional)
  • MQTT_KEEPALIVE: MQTT server keepalive interval
  • HA_SENSOR_NAME: Home Assistant sensor name
  • HA_SENSOR_UUID: Home Assistant sensor UUID
  • HA_SENSOR_EXPIRE_AFTER: How many seconds until Home Assistant considers the data to be stale
  • TF_MODEL: TensorFlow model filename
  • TF_NUM_THREADS: TensorFlow number of threads
  • TF_SCORE_THRESHOLD: TensorFlow minimum score
  • TF_MAX_RESULTS: TensorFlow maximum results
  • TF_IGNORED_CATEGORIES: Categories to ignore
  • LOG_LEVEL: Logging level
  • LOG_FORMAT: Logging format
  • LOG_COLORS: Logging level colors

Usage

Check your Python version and make sure version 3.9 or newer is installed on your system:

python3 --version

Install required python3 modules:

pip3 install -r requirements.txt

On Linux, install the PortAudio library:

sudo apt-get update && apt-get install libportaudio2

Run the listen.py script to start listening to the microphone and publishing the data to the MQTT server:

python3 ./listen.py

The sensor is now available in Home Assistant and can be used to trigger automations:

Home Assistant Screenshot

Docker

To run this script as a Docker container, modify the config.py file as decribed above and then build the image:

docker build -t audioclassifier-mqtt .

Now create a container with access to the system's audio device (/dev/dsp is the default) and host networking to communicate with the MQTT server:

docker run --name audioclassifier --restart=always -d --device /dev/dsp --network=host audioclassifier-mqtt

License

Copyright (C) 2022 Sam Steele. 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 distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

audioclassifier-mqtt's People

Contributors

c99koder avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

baael raphael909

audioclassifier-mqtt's Issues

error line 66

Hello,

I have conform the guidline install the script, but when i start it i get the next error:

python3 ./listen.py
File "./listen.py", line 68
logging.basicConfig(level=LOG_LEVEL, format=LOG_FORMAT.replace(f'%(log_color)s', ''), stream=sys.stdout)
^
SyntaxError: invalid syntax

Its runs on a raspberry pi with clean install.

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.