Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker support with MySQL included #124

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Default environment variables used by Docker.
MYSQL_CONTAINER_NAME=mysql-dejavu
DATABASE_NAME=dejavu
3 changes: 3 additions & 0 deletions INSTALLATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ So far Dejavu has only been tested on Unix systems.

For installing `ffmpeg` on Mac OS X, I highly recommend [this post](http://jungels.net/articles/ffmpeg-howto.html).

## Docker
If you don't require the use of a microphone then we'd recommend using Docker.

## Fedora 20+

### Dependency installation on Fedora 20+
Expand Down
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,22 @@ 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.

## Quickstart with Docker
Note: When using Docker, microphone input is not supported. See below if you wish to run Dejavu without Docker.

[Download & install Docker](https://www.docker.com/community-edition#/download) then follow the steps below:

```bash
$ docker-compose up -d
# Wait a minute for the database to start up.

# Run "python example.py" in the Dejavu container for Docker.
$ docker-compose run dejavu python example.py

# When you're all done, clean everything up.
$ docker-compose down
```

## Installation and Dependencies:

Read [INSTALLATION.md](INSTALLATION.md)
Expand Down
8 changes: 8 additions & 0 deletions dejavu.cnf.DOCKER
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"database": {
"host": "db",
"user": "root",
"passwd": "",
"db": "dejavu"
}
}
40 changes: 40 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
version: "3"
services:
db:
image: mysql
container_name: ${MYSQL_CONTAINER_NAME}
environment:
- MYSQL_ALLOW_EMPTY_PASSWORD=yes
networks:
- db-backend
db-setup:
image: mysql
container_name: ${MYSQL_CONTAINER_NAME}-setup
command: >
sh -c '
while ! mysqladmin ping -h"db" --silent; do echo "Waiting for MySQL service"; sleep 1; done;
echo "Creating database '${DATABASE_NAME}'";
exec mysql -h"db" -uroot -e "CREATE DATABASE IF NOT EXISTS ${DATABASE_NAME}"';
networks:
- db-backend
depends_on:
- db
dejavu:
env_file: ./docker/.dejavu_env
container_name: dejavu
image: dejavu
volumes:
- .:/dejavu
build:
dockerfile: ./docker/Dockerfile
context: ./
args:
http_proxy: ${http_proxy}
https_proxy: ${https_proxy}
networks:
- db-backend
depends_on:
- db
- db-setup
networks:
db-backend:
1 change: 1 addition & 0 deletions docker/.dejavu_env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DOCKER_ENV=True
20 changes: 20 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM centos:7

# Install PIP
RUN yum -y install epel-release && yum clean all
RUN yum -y install python python-pip && yum clean all

# FFMPEG Repos
RUN rpm --import http://li.nux.ro/download/nux/RPM-GPG-KEY-nux.ro
RUN rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-5.el7.nux.noarch.rpm

RUN yum -y install numpy scipy python-matplotlib portaudio-devel gcc MySQL-python tkinter ffmpeg

RUN pip install PyAudio
RUN pip install pydub

RUN pip install PyDejavu

WORKDIR /dejavu

CMD ["bash", "-l"]
22 changes: 16 additions & 6 deletions example.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import warnings
import json
import os
warnings.filterwarnings("ignore")

from dejavu import Dejavu
from dejavu.recognize import FileRecognizer, MicrophoneRecognizer

# checking to see if running in Docker container
env_is_docker = os.getenv('DOCKER_ENV', False)
if env_is_docker:
print "You are running Dejavu in Docker."
config_file_name = "dejavu.cnf.DOCKER" if env_is_docker else "dejavu.cnf.SAMPLE"

# load config from a JSON file (or anything outputting a python dictionary)
with open("dejavu.cnf.SAMPLE") as f:
with open(config_file_name) as f:
config = json.load(f)

if __name__ == '__main__':
Expand All @@ -22,12 +29,15 @@
print "From file we recognized: %s\n" % song

# Or recognize audio from your microphone for `secs` seconds
secs = 5
song = djv.recognize(MicrophoneRecognizer, seconds=secs)
if song is None:
print "Nothing recognized -- did you play the song out loud so your mic could hear it? :)"
if not env_is_docker:
secs = 5
song = djv.recognize(MicrophoneRecognizer, seconds=secs)
if song is None:
print "Nothing recognized -- did you play the song out loud so your mic could hear it? :)"
else:
print "From mic with %d seconds we recognized: %s\n" % (secs, song)
else:
print "From mic with %d seconds we recognized: %s\n" % (secs, song)
print "Microphone input isn't support using Docker. Skipping microphone recognition..."

# Or use a recognizer without the shortcut, in anyway you would like
recognizer = FileRecognizer(djv)
Expand Down