mirror of
https://github.com/correl/dejavu.git
synced 2024-12-26 19:16:51 +00:00
Added Docker option
This commit is contained in:
parent
16d7f1d5d3
commit
c7be599ff4
7 changed files with 116 additions and 14 deletions
63
README.md
63
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
|
||||
|
||||
|
|
22
docker-compose.yaml
Normal file
22
docker-compose.yaml
Normal file
|
@ -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:
|
0
docker/.gitkeep
Normal file
0
docker/.gitkeep
Normal file
2
docker/postgres/Dockerfile
Normal file
2
docker/postgres/Dockerfile
Normal file
|
@ -0,0 +1,2 @@
|
|||
FROM postgres:10.7-alpine
|
||||
COPY init.sql /docker-entrypoint-initdb.d/
|
2
docker/postgres/init.sql
Normal file
2
docker/postgres/init.sql
Normal file
|
@ -0,0 +1,2 @@
|
|||
-- put any SQL you'd like to run on creation of the image
|
||||
-- in this file :)
|
8
docker/python/Dockerfile
Normal file
8
docker/python/Dockerfile
Normal file
|
@ -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
example_docker_postgres.py
Normal file
33
example_docker_postgres.py
Normal file
|
@ -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")
|
Loading…
Reference in a new issue