Skip to content

Commit

Permalink
Added Docker option
Browse files Browse the repository at this point in the history
  • Loading branch information
worldveil committed Jun 3, 2020
1 parent 16d7f1d commit c7be599
Show file tree
Hide file tree
Showing 7 changed files with 116 additions and 14 deletions.
63 changes: 49 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,66 @@ Dejavu can memorize audio by listening to it once and fingerprinting it. Then by

Note that for voice recognition, Dejavu is not the right tool! Dejavu excels at recognition of exact signals with reasonable amounts of noise.

## Installation and Dependencies:
## Quickstart with Docker

First, install [Docker](https://docs.docker.com/get-docker/).

```shell
# build and then run our containers
$ docker-compose build
$ docker-compose up -d

# get a shell inside the container
$ docker-compose run python /bin/bash
Starting dejavu_db_1 ... done
root@f9ea95ce5cea:/code# python example_docker_postgres.py
Fingerprinting channel 1/2 for test/woodward_43s.wav
Fingerprinting channel 1/2 for test/sean_secs.wav
...

# connect to the database and poke around
root@f9ea95ce5cea:/code# psql -h db -U postgres dejavu
Password for user postgres: # type "password", as specified in the docker-compose.yml !
psql (11.7 (Debian 11.7-0+deb10u1), server 10.7)
Type "help" for help.

dejavu=# \dt
List of relations
Schema | Name | Type | Owner
--------+--------------+-------+----------
public | fingerprints | table | postgres
public | songs | table | postgres
(2 rows)

dejavu=# select * from fingerprints limit 5;
hash | song_id | offset | date_created | date_modified
------------------------+---------+--------+----------------------------+----------------------------
\x71ffcb900d06fe642a18 | 1 | 137 | 2020-06-03 05:14:19.400153 | 2020-06-03 05:14:19.400153
\xf731d792977330e6cc9f | 1 | 148 | 2020-06-03 05:14:19.400153 | 2020-06-03 05:14:19.400153
\x71ff24aaeeb55d7b60c4 | 1 | 146 | 2020-06-03 05:14:19.400153 | 2020-06-03 05:14:19.400153
\x29349c79b317d45a45a8 | 1 | 101 | 2020-06-03 05:14:19.400153 | 2020-06-03 05:14:19.400153
\x5a052144e67d2248ccf4 | 1 | 123 | 2020-06-03 05:14:19.400153 | 2020-06-03 05:14:19.400153
(10 rows)

# then to shut it all down...
$ docker-compose down
```
Read [INSTALLATION.md](INSTALLATION.md)
If you want to be able to use the microphone with the Docker container, you'll need to do a [little extra work](https://stackoverflow.com/questions/43312975/record-sound-on-ubuntu-docker-image). I haven't had the time to write this up, but if anyone wants to make a PR, I'll happily merge.
## Setup
## Docker alternative on local machine
First, install the above dependencies.
Follow instructions in [INSTALLATION.md](INSTALLATION.md)
Second, you'll need to create a MySQL database where Dejavu can store fingerprints. For example, on your local setup:
Next, you'll need to create a MySQL database where Dejavu can store fingerprints. For example, on your local setup:
$ mysql -u root -p
Enter password: **********
mysql> CREATE DATABASE IF NOT EXISTS dejavu;
Now you're ready to start fingerprinting your audio collection!
Obs: The same from above goes for postgres database if you want to use it.

## Quickstart

```bash
$ git clone https://github.com/worldveil/dejavu.git ./dejavu
$ cd dejavu
$ python example.py
```
You may also use Postgres, of course. The same method applies.
## Fingerprinting
Expand Down
22 changes: 22 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: '3'
services:
db:
build:
context: ./docker/postgres
environment:
- POSTGRES_DB=dejavu
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
networks:
- db_network
python:
build:
context: ./docker/python
volumes:
- .:/code
depends_on:
- db
networks:
- db_network
networks:
db_network:
Empty file added docker/.gitkeep
Empty file.
2 changes: 2 additions & 0 deletions docker/postgres/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM postgres:10.7-alpine
COPY init.sql /docker-entrypoint-initdb.d/
2 changes: 2 additions & 0 deletions docker/postgres/init.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- put any SQL you'd like to run on creation of the image
-- in this file :)
8 changes: 8 additions & 0 deletions docker/python/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM python:3.7
RUN apt-get update -y && apt-get upgrade -y
RUN apt-get install \
gcc nano \
ffmpeg libasound-dev portaudio19-dev libportaudio2 libportaudiocpp0 \
postgresql postgresql-contrib -y
RUN pip install numpy scipy matplotlib pydub pyaudio psycopg2
WORKDIR /code
33 changes: 33 additions & 0 deletions example_docker_postgres.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import json

from dejavu import Dejavu
from dejavu.logic.recognizer.file_recognizer import FileRecognizer
from dejavu.logic.recognizer.microphone_recognizer import MicrophoneRecognizer

# load config from a JSON file (or anything outputting a python dictionary)
config = {
"database": {
"host": "db",
"user": "postgres",
"password": "password",
"database": "dejavu"
},
"database_type": "postgres"
}

if __name__ == '__main__':

# create a Dejavu instance
djv = Dejavu(config)

# Fingerprint all the mp3's in the directory we give it
djv.fingerprint_directory("test", [".wav"])

# Recognize audio from a file
results = djv.recognize(FileRecognizer, "mp3/Josh-Woodward--I-Want-To-Destroy-Something-Beautiful.mp3")
print(f"From file we recognized: {results}\n")

# Or use a recognizer without the shortcut, in anyway you would like
recognizer = FileRecognizer(djv)
results = recognizer.recognize_file("mp3/Josh-Woodward--I-Want-To-Destroy-Something-Beautiful.mp3")
print(f"No shortcut, we recognized: {results}\n")

0 comments on commit c7be599

Please sign in to comment.