From e44a05d64595e33d7b527cc6894cea9d70f59b46 Mon Sep 17 00:00:00 2001 From: diegoromal Date: Tue, 23 Apr 2024 20:44:49 -0300 Subject: [PATCH 1/3] Implements pydub package dependencies --- compose/local/django/Dockerfile | 4 +++- compose/production/django/Dockerfile | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/compose/local/django/Dockerfile b/compose/local/django/Dockerfile index b122f53..1860115 100644 --- a/compose/local/django/Dockerfile +++ b/compose/local/django/Dockerfile @@ -11,7 +11,9 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ # dependencies for building Python packages build-essential \ # psycopg2 dependencies - libpq-dev + libpq-dev \ + # Install pydub dependencies + ffmpeg libavcodec-extra # Requirements are installed here to ensure they will be cached. COPY ./requirements . diff --git a/compose/production/django/Dockerfile b/compose/production/django/Dockerfile index 9c2e948..ba6f549 100644 --- a/compose/production/django/Dockerfile +++ b/compose/production/django/Dockerfile @@ -12,7 +12,9 @@ RUN apt-get update && apt-get install --no-install-recommends -y \ # dependencies for building Python packages build-essential \ # psycopg2 dependencies - libpq-dev + libpq-dev \ + # Install pydub dependencies + ffmpeg libavcodec-extra # Requirements are installed here to ensure they will be cached. COPY ./requirements . @@ -35,7 +37,7 @@ ENV BUILD_ENV ${BUILD_ENVIRONMENT} WORKDIR ${APP_HOME} RUN addgroup --system django \ - && adduser --system --ingroup django django + && adduser --system --ingroup django django # Install required system dependencies From 2b3fb14321f4b3e449f664cd4fedb17b1dfae417 Mon Sep 17 00:00:00 2001 From: diegoromal Date: Tue, 23 Apr 2024 20:47:56 -0300 Subject: [PATCH 2/3] Add pydub requirement --- requirements/base.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements/base.txt b/requirements/base.txt index 5f29b26..773b3cc 100644 --- a/requirements/base.txt +++ b/requirements/base.txt @@ -8,6 +8,7 @@ hiredis==2.3.2 # https://github.com/redis/hiredis-py celery==5.3.6 # pyup: < 6.0 # https://github.com/celery/celery django-celery-beat==2.6.0 # https://github.com/celery/django-celery-beat flower==2.0.1 # https://github.com/mher/flower +pydub==0.25.1 # https://github.com/jiaaro/pydub # Django # ------------------------------------------------------------------------------ From f14932abe5b7c81ba33b202773361ed021428988 Mon Sep 17 00:00:00 2001 From: diegoromal Date: Tue, 23 Apr 2024 20:53:30 -0300 Subject: [PATCH 3/3] Implements mp3 converter to play on iPhone --- rocket_connect/plugins/base.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rocket_connect/plugins/base.py b/rocket_connect/plugins/base.py index da6bb84..48b68bb 100644 --- a/rocket_connect/plugins/base.py +++ b/rocket_connect/plugins/base.py @@ -9,6 +9,7 @@ import time import urllib.parse from io import BytesIO +from pydub import AudioSegment import qrcode import requests @@ -177,6 +178,16 @@ def outcome_file(self, base64_data, room_id, mime, filename=None, description=No if mime == "image/webp": extension = ".webp" + # Convert ogg audio to mp3 (To play on iPhone) + if mime == "audio/ogg; codecs=opus": + ogg_io = BytesIO(filedata) + ogg_audio = AudioSegment.from_file(ogg_io, format='ogg') + mp3_data = ogg_audio.export(format="mp3").read() + mp3_b64 = base64.b64encode(mp3_data) + filedata = base64.b64decode(mp3_b64) + mime = "audio/mpeg" + extension = ".mp3" + if not filename: # random filename filename = (