From c7be599ff463c962449ff65c1a3d7838ad528386 Mon Sep 17 00:00:00 2001 From: Will Drevo Date: Tue, 2 Jun 2020 22:38:32 -0700 Subject: [PATCH] Added Docker option --- README.md | 63 +++++++++++++++++++++++++++++--------- docker-compose.yaml | 22 +++++++++++++ docker/.gitkeep | 0 docker/postgres/Dockerfile | 2 ++ docker/postgres/init.sql | 2 ++ docker/python/Dockerfile | 8 +++++ example_docker_postgres.py | 33 ++++++++++++++++++++ 7 files changed, 116 insertions(+), 14 deletions(-) create mode 100644 docker-compose.yaml create mode 100644 docker/.gitkeep create mode 100644 docker/postgres/Dockerfile create mode 100644 docker/postgres/init.sql create mode 100644 docker/python/Dockerfile create mode 100644 example_docker_postgres.py diff --git a/README.md b/README.md index 4cab00b..728155b 100755 --- a/README.md +++ b/README.md @@ -8,15 +8,58 @@ 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 -Read [INSTALLATION.md](INSTALLATION.md) +First, install [Docker](https://docs.docker.com/get-docker/). -## Setup +```shell +# build and then run our containers +$ docker-compose build +$ docker-compose up -d -First, install the above dependencies. +# 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 +... -Second, you'll need to create a MySQL database where Dejavu can store fingerprints. For example, on your local setup: +# 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 +``` + +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. + +## Docker alternative on local machine + +Follow instructions in [INSTALLATION.md](INSTALLATION.md) + +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: ********** @@ -24,15 +67,7 @@ Second, you'll need to create a MySQL database where Dejavu can store fingerprin 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 diff --git a/docker-compose.yaml b/docker-compose.yaml new file mode 100644 index 0000000..63fd81f --- /dev/null +++ b/docker-compose.yaml @@ -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: \ No newline at end of file diff --git a/docker/.gitkeep b/docker/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/docker/postgres/Dockerfile b/docker/postgres/Dockerfile new file mode 100644 index 0000000..9c5ab1a --- /dev/null +++ b/docker/postgres/Dockerfile @@ -0,0 +1,2 @@ +FROM postgres:10.7-alpine +COPY init.sql /docker-entrypoint-initdb.d/ \ No newline at end of file diff --git a/docker/postgres/init.sql b/docker/postgres/init.sql new file mode 100644 index 0000000..dd045ce --- /dev/null +++ b/docker/postgres/init.sql @@ -0,0 +1,2 @@ +-- put any SQL you'd like to run on creation of the image +-- in this file :) \ No newline at end of file diff --git a/docker/python/Dockerfile b/docker/python/Dockerfile new file mode 100644 index 0000000..d795f68 --- /dev/null +++ b/docker/python/Dockerfile @@ -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 \ No newline at end of file diff --git a/example_docker_postgres.py b/example_docker_postgres.py new file mode 100644 index 0000000..cd9572e --- /dev/null +++ b/example_docker_postgres.py @@ -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")