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

dockerizing the service added to the project #14

Open
wants to merge 2 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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,22 @@ rnnoise_wrapper -i input.wav -o output.wav
- `input.wav` - имя исходной .wav аудиозаписи
- `output.wav` - имя .wav аудиофайла, в который будет сохранена аудиозапись после шумоподавления

## Docker
The docker image can get an audio file, do the process on it and export the file.

To build the dockerfile stand in the root of repo then:

`docker build -f dockerize/Dockerfile -t rnnoisewrapper .`

To run the container:

`docker run -d -p 5000:5000 rnnoisewrapper:latest`

and to test the api using curl you can insert this command:

`curl -X POST -F "file=@/path/to/loca/sound/file.wav" 127.0.0.1:5000/process --output processed_audio.wav`


## Обучение

Инструкция по обучению RNNoise на своих данных находится в [`TRAINING.md`](https://github.com/Desklop/RNNoise_Wrapper/tree/master/TRAINING.md).
Expand Down
26 changes: 26 additions & 0 deletions dockerize/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Use an official Python runtime as a parent image
FROM python:3.8-slim

# Set environment variable
ENV APP_PORT="5000"

# Set the working directory in the container
WORKDIR /app

# Copy the current directory contents into the container at /app
COPY . /app

# Update the package list and install ffmpeg
RUN apt-get update && \
apt-get install -y ffmpeg && \
rm -rf /var/lib/apt/lists/*

# Install any needed packages specified in requirements.txt
RUN pip install --no-cache-dir -r /app/dockerize/requirements.txt

# Make port 1555 available to the world outside this container
EXPOSE 5000

# Run app.py when the container launches
CMD ["python", "-m", "dockerize.app"]
# CMD ["python"]
51 changes: 51 additions & 0 deletions dockerize/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
from flask import Flask, request, send_file, jsonify
from pydub import AudioSegment
import os

# install wrapper's package
from rnnoise_wrapper import RNNoise

app = Flask(__name__)
denoiser = RNNoise("./rnnoise_wrapper/libs/librnnoise_default.so.0.4.1")

def read_audio(file):
# Parse the file format from the filename extension
format = file.filename.rsplit('.', 1)[1].lower()

# Use pydub to read various audio formats
audio = AudioSegment.from_file(file, format=format)

# Normalize the audio to the rnnoise's input format
audio = audio.set_frame_rate(48000)
audio = audio.set_sample_width(2)
audio = audio.set_channels(1)

return audio

@app.route('/process', methods=['POST'])
def process():
global denoiser

if 'file' not in request.files:
return jsonify({"status": "File not found"}), 400

file = request.files['file']

if file.filename == '':
return jsonify({"status": "File name invalid"}), 404


if file:
try:
audio = read_audio(file)
denoised_audio = denoiser.filter(audio)
denoiser.write_wav("denoised.wav", denoised_audio)
return send_file("denoised.wav", as_attachment=True)
except:
return jsonify({"status": "An exception happend!"}), 500

return jsonify({"status": "File invalid"}), 403

if __name__ == '__main__':
port = int(os.getenv("APP_PORT", 5000))
app.run(debug=True, host='0.0.0.0', port=port)
4 changes: 4 additions & 0 deletions dockerize/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
numpy>=1.16
pydub>=0.23.1
Flask
.