Django-Audiofield is a simple app that allows Audio files upload, management and conversion to different audio format (mp3, wav & ogg), which also makes it easy to play audio files into your Django application.

Overview

Django-Audiofield

Description: Django Audio Management Tools
Maintainer: Areski
Contributors: list of contributors
Latest Version Downloads Supported Python versions License

Django-Audiofield is a simple app that allows Audio files upload, management and conversion to different audio format (mp3, wav & ogg), which also makes it easy to play audio files into your Django application.

We are using the HTML5 and Flash audio player SoundManager2

https://github.com/Star2Billing/django-audiofield/raw/master/docs/source/_static/django-admin-audiofield.png

https://github.com/Star2Billing/django-audiofield/raw/master/docs/source/_static/django-admin-audiofield-upload.png

Installation

Install Django-Audiofield:

python setup.py install

Dependencies

Install dependencies on Debian:

apt-get -y install libsox-fmt-mp3 libsox-fmt-all mpg321 dir2ogg libav-tools

Install dependencies on Redhat/CentOS:

yum -y install python-setuptools libsox-fmt-mp3 libsox-fmt-all mpg321 dir2ogg

Install avconv on Redhat/CentOS:

git clone git://git.libav.org/libav.git
cd libav
sudo ./configure --disable-yasm
sudo make
sudo make install

Settings

in your settings.py file:

# Set Following variable
MEDIA_ROOT = ''
MEDIA_URL = ''

In MIDDLEWARE_CLASSES add 'audiofield.middleware.threadlocals.ThreadLocals'

In INSTALLED_APPS add 'audiofield'

# Frontend widget values
# 0-Keep original, 1-Mono, 2-Stereo
CHANNEL_TYPE_VALUE = 0

# 0-Keep original, 8000-8000Hz, 16000-16000Hz, 22050-22050Hz,
# 44100-44100Hz, 48000-48000Hz, 96000-96000Hz
FREQ_TYPE_VALUE = 8000

# 0-Keep original, 1-Convert to MP3, 2-Convert to WAV, 3-Convert to OGG
CONVERT_TYPE_VALUE = 0

Usage

Add the following lines in your models.py file:

from django.conf import settings
from audiofield.fields import AudioField
import os.path

# Add the audio field to your model
audio_file = AudioField(upload_to='your/upload/dir', blank=True,
                        ext_whitelist=(".mp3", ".wav", ".ogg"),
                        help_text=("Allowed type - .mp3, .wav, .ogg"))

# Add this method to your model
def audio_file_player(self):
    """audio player tag for admin"""
    if self.audio_file:
        file_url = settings.MEDIA_URL + str(self.audio_file)
        player_string = '<audio src="%s" controls>Your browser does not support the audio element.</audio>' % (file_url)
        return player_string

audio_file_player.allow_tags = True
audio_file_player.short_description = ('Audio file player')

Add the following lines in your admin.py:

from your_app.models import your_model_name

# add 'audio_file_player' tag to your admin view
list_display = (..., 'audio_file_player', ...)
actions = ['custom_delete_selected']

def custom_delete_selected(self, request, queryset):
    #custom delete code
    n = queryset.count()
    for i in queryset:
        if i.audio_file:
            if os.path.exists(i.audio_file.path):
                os.remove(i.audio_file.path)
        i.delete()
    self.message_user(request, ("Successfully deleted %d audio files.") % n)
custom_delete_selected.short_description = "Delete selected items"

def get_actions(self, request):
    actions = super(AudioFileAdmin, self).get_actions(request)
    del actions['delete_selected']
    return actions

Then perform following commands to create the table and collect the static files:

./manage.py syncdb
./manage.py collectstatic

Create audiofield.log file:

touch /var/log/audio-field.log

Contributing

If you've found a bug, implemented a feature or customized the template and think it is useful then please consider contributing. Patches, pull requests or just suggestions are welcome!

Source code: http://github.com/Star2Billing/django-audiofield

Bug tracker: https://github.com/Star2Billing/django-audiofield/issues

Documentation

Documentation is available on 'Read the Docs': http://django-audiofield.readthedocs.org

Credit

Django-audiofield is a Star2Billing-Sponsored Community Project, for more information visit http://www.star2billing.com or email us at [email protected]

License

Django-Audiofield is licensed under MIT, see MIT-LICENSE.txt.

TODO

Comments
  • AudioField not working with Django 2.1

    AudioField not working with Django 2.1

    Hello, I am trying AudioField with Django 2.1

    I am having the following error:

    ERRORS: audiofield.AudioFile: (auth.E005) The permission codenamed 'view_audiofile' clashes with a builtin permission for model 'audiofield.AudioFile'.

    This happens when trying migrations or when trying to launch the server with an audiofield setup at one of my templates as per the documentation.

    Thanks

    opened by mwolffalonso 13
  • Added Windows support

    Added Windows support

    Added Windows support by creating a new variable in settings.py for the 'sox' command passed to subprocess. Also added links to README for dependencies.

    opened by jcoady9 4
  • AudioField does not play nice with django South

    AudioField does not play nice with django South

    migration fails with an error like:

    ValueError: Cannot successfully create field 'X' for model 'Y': 'ext_whitelist'.

    This seems to be solved by creating a specific introspection rule for south, this has worked for me (it adds a default argument for ext_whitelist, which is added / not in the baseclass FileField)

    from south.modelsinspector import add_introspection_rules add_introspection_rules( [ ( (AudioField, ), [], { "verbose_name": ["verbose_name", {"default": None}], "name": ["name", {"default": None}], "ext_whitelist": ["ext_whitelist", {"default": (".mp3"),}], }, ), ], ["^audiofield.fields.AudioField",])

    opened by stevebma 4
  • Django compatibility.

    Django compatibility.

    • Add on_delete param, update __str__ to python2/3 compatibility for django 2.0 compatibility.
    • Remove old MiddlewareMixin for django 1.9 and earlier compatibility.
    • Update translations.
    opened by khasanovbi 3
  • 404 Failed to load on Admin

    404 Failed to load on Admin

    Hi,

    Followed your documentation step by step installing you nice little package here. Still my admin got a "Failed to load 404" on the player and no sound is played. Figured out you're uploading the files in 'upload/audiofiles' folder but it seems it cannot access it.

    Here's a little log that's showing on the admin page as well (dunno if it should btw)

    Django 1.7, Python3.2 ; I'm looking forward

    SMSound._onload(): "pagePlayerMP3Sound0" failed to load? -     http://127.0.0.1:8000/admin/audiofield/audiofile/upload/audiofiles/audio-file-CNTGU-2854274827.wav
    HTML5::error: 4
    HTML5::waiting: pagePlayerMP3Sound0
    HTML5::play: pagePlayerMP3Sound0, http://127.0.0.1:8000/admin/audiofield/audiofile/upload/audiofiles/audio-file-CNTGU-2854274827.wav
    HTML5::suspend: pagePlayerMP3Sound0
    HTML5::loadstart: pagePlayerMP3Sound0
    HTML5::emptied: pagePlayerMP3Sound0
    setPosition(0): delaying, sound not ready
    SMSound.play(): "pagePlayerMP3Sound0" is starting to play
    HTML5::load: pagePlayerMP3Sound0
    SMSound.load(): http://127.0.0.1:8000/admin/audiofield/audiofile/upload/audiofiles/audio-file-CNTGU-2854274827.wav
    SMSound.play(): Attempting to load "pagePlayerMP3Sound0"
    HTML5::adding event listeners: pagePlayerMP3Sound0
    creating HTML5 Audio() element with URL: http://127.0.0.1:8000/admin/audiofield/audiofile/upload/audiofiles/audio-file-CNTGU-2854274827.wav
    Loading sound pagePlayerMP3Sound0 via HTML5
    SMSound() merged options: { id: pagePlayerMP3Sound0, url: http://127.0.0.1:8000/admin/audiofield/audiofile/upload/audiofiles/audio-file-CNTGU-2854274827.wav, onplay: { pl.removeClass(this._data.oLI,this._data.className); this._data... }, onstop: { pl.removeClass(this._data.oLI,this._data.className); this._data... }, onpause: { if (pl.dragActive) { return false; } pl.removeClass(this._data.... }, onresume: { if (pl.dragActive) { return false; } pl.removeClass(this._data.... }, onfinish: { pl.removeClass(this._data.oLI,this._data.className); this._data... }, whileloading: { function doWork() { this._data.oLoading.style.width = (((this.b... }, whileplaying: { var d = null; if (pl.dragActive || !pl.config.useThrottling) { ... }, onmetadata: undefined, onload: { if (!this.loaded) { var oTemp = this._data.oLI.getElementsByTag... }, autoLoad: false, stream: true, autoPlay: false, loops: 1, multiShot: true, multiShotEvents: false, pan: 0, usePolicyFile: false, volume: 100, usePeakData: true, useWaveformData: false, useEQData: false, bufferTime: 3 }
    soundManager.createSound(): pagePlayerMP3Sound0 (http://127.0.0.1:8000/admin/audiofield/audiofile/upload/audiofiles/audio-file-CNTGU-2854274827.wav)
    pagePlayer.init(): Ready
    pagePlayer.init(): Using custom configuration
    soundManager: Firing 1 onready() item
    -- SoundManager 2 loaded (OK) --
    (Flash): Enabling polling, 10 ms interval
    (Flash): JS to/from Flash OK
    Flash security sandbox type: remote
    (Flash): SM2 SWF V2.97a.20110918 (AS3/Flash 9)
    soundManager: Attempting to call Flash from JS..
    soundManager::init()
    soundManager::externalInterfaceOK() (~1 ms)
    soundManager::initMovie(): Waiting for ExternalInterface call from Flash..
    soundManager::createMovie(): Trying to load /static/audiofield/swf/soundmanager2_flash9_debug.swf
    -- SoundManager 2 V2.97a.20110918 (AS3/Flash 9) + HTML5 audio, high performance mode, normal polling, wmode: transparent, flashBlock mode --
    -- SoundManager 2: HTML5 support tests (/^(probably|maybe)$/i): mp3: true (preferring flash), mp4: true (preferring flash), ogg: true, wav: true --
    
    opened by krzepah 3
  • unable to upload 200k file

    unable to upload 200k file

    Hi, Congratulations for this project. It's very useful. While testing it, i realize that i can't upload file bigger than 150 K. Any time i try to, the browser waits until connection reset.

    opened by acheraime 3
  • threadlocals.py updated to add compatibility with Django v.1.10/v.1.11

    threadlocals.py updated to add compatibility with Django v.1.10/v.1.11

    Rewrote ThreadLocals class to address changes in Django 1.10's handling of middleware - noted in issue #27

    Testing needed to confirm and further work needed to ensure cross compatibility with pre 1.10 versions of Django.

    opened by ruggedness-mime 2
  • ImportError: No module named 'middleware'

    ImportError: No module named 'middleware'

    Validating models...

    Unhandled exception in thread started by <bound method Command.inner_run of <django.contrib.staticfiles.management.commands.runserver.Command object at 0x7f6c88d95c18>> Traceback (most recent call last): File "/home/kamushin/app/env/lib/python3.4/site-packages/django/core/management/commands/runserver.py", line 93, in inner_run self.validate(display_num_errors=True) File "/home/kamushin/app/env/lib/python3.4/site-packages/django/core/management/base.py", line 280, in validate num_errors = get_validation_errors(s, app) File "/home/kamushin/app/env/lib/python3.4/site-packages/django/core/management/validation.py", line 35, in get_validation_errors for (app_name, error) in get_app_errors().items(): File "/home/kamushin/app/env/lib/python3.4/site-packages/django/db/models/loading.py", line 166, in get_app_errors self._populate() File "/home/kamushin/app/env/lib/python3.4/site-packages/django/db/models/loading.py", line 75, in _populate self.load_app(app_name) File "/home/kamushin/app/env/lib/python3.4/site-packages/django/db/models/loading.py", line 96, in load_app models = import_module('.models', app_name) File "/home/kamushin/app/env/lib/python3.4/site-packages/django/utils/importlib.py", line 35, in import_module import(name) File "/home/kamushin/app/questions/models.py", line 7, in from audiofield.fields import AudioField File "/home/kamushin/app/env/lib/python3.4/site-packages/django_audiofield-0.6.2-py3.4.egg/audiofield/fields.py", line 20, in from middleware import threadlocals ImportError: No module named 'middleware'

    opened by kamushin 2
  • Impossible to install on CentOS 6.5

    Impossible to install on CentOS 6.5

    The installation instructions for CentOS as stated in README.rst are broken, because none of these four packages:

    • libsox-fmt-mp3
    • libsox-fmt-all
    • mpg321
    • dir2ogg

    are present in the CentOS stock repositories, nor in EPEL.

    opened by pdonadeo 2
  • Import error with management commands

    Import error with management commands

    In my models I used 'from audiofield.fields import AudioField'. This worked fine until I added a custom management command that imported a model with an AudioField.

    There seemed to be a circular import. So, instead I changed my imports for my models to 'from audiofield.models import AudioField'

    This seemed to solve the problem.

    nobody@lemons:~/Docs/Code/wordsuperb$ python manage.py getsentences Traceback (most recent call last): File "manage.py", line 14, in execute_manager(settings) File "/usr/local/lib/python2.6/dist-packages/django/core/management/init.py", line 438, in execute_manager utility.execute() File "/usr/local/lib/python2.6/dist-packages/django/core/management/init.py", line 379, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/usr/local/lib/python2.6/dist-packages/django/core/management/init.py", line 261, in fetch_command klass = load_command_class(app_name, subcommand) File "/usr/local/lib/python2.6/dist-packages/django/core/management/init.py", line 67, in load_command_class module = import_module('%s.management.commands.%s' % (app_name, name)) File "/usr/local/lib/python2.6/dist-packages/django/utils/importlib.py", line 35, in import_module import(name) File "/home/nobody/Docs/Code/wordsuperb/corpus/management/commands/getsentences.py", line 3, in from corpus.models import Sentence File "/home/nobody/Docs/Code/wordsuperb/corpus/models.py", line 11, in from audiofield.fields import AudioField File "/usr/local/lib/python2.6/dist-packages/django_audiofield-0.2.dev1-py2.6.egg/audiofield/fields.py", line 8, in from tasks import audio_convert_task File "/usr/local/lib/python2.6/dist-packages/django_audiofield-0.2.dev1-py2.6.egg/audiofield/tasks.py", line 2, in from models import * File "/usr/local/lib/python2.6/dist-packages/django_audiofield-0.2.dev1-py2.6.egg/audiofield/models.py", line 7, in from audiofield.fields import AudioField ImportError: cannot import name AudioField

    opened by globophobe 2
  • change to create Django 1.10 compatible threadlocalspy middleware

    change to create Django 1.10 compatible threadlocalspy middleware

    As noted in my comment on PR #29 - my efforts to create a new class for ThreadLocals in the v1.10+ supported style are still unsuccessful but the doc supported fix is now working - have committed that to this branch of my fork.

    As Django has said they will remove all support for old-style 'MIDDLEWARE_CLASSES' in v2.0 this should not be considered a long-term fix.

    opened by ruggedness-mime 1
  • The permission codenamed 'view_audiofile' clashes with a builtin permission for model 'audiofield.AudioFile'

    The permission codenamed 'view_audiofile' clashes with a builtin permission for model 'audiofield.AudioFile'

    I have error: The permission codenamed 'view_audiofile' clashes with a builtin permission for model 'audiofield.AudioFile'

    i tried this solution https://github.com/areski/django-audiofield/pull/35/commits/344ff9c135387719d6000a09c28d3648dd9a9a05

    but doesnt work... always this error ;/

    opened by AM0k84 2
  • ModuleNotFoundError: No module named 'audiofieldspeech'

    ModuleNotFoundError: No module named 'audiofieldspeech'

    I get this error when I run python manage.py syncdb, Any help will be appreciated.

    (speechmodel) C:\Users\Mr Ayo\Desktop\speechmodel>python manage.py syncdb Traceback (most recent call last): File "manage.py", line 21, in <module> main() File "manage.py", line 17, in main execute_from_command_line(sys.argv) File "C:\Users\Mr Ayo\.virtualenvs\speechmodel\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line utility.execute() File "C:\Users\Mr Ayo\.virtualenvs\speechmodel\lib\site-packages\django\core\management\__init__.py", line 377, in execute django.setup() File "C:\Users\Mr Ayo\.virtualenvs\speechmodel\lib\site-packages\django\__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "C:\Users\Mr Ayo\.virtualenvs\speechmodel\lib\site-packages\django\apps\registry.py", line 91, in populate app_config = AppConfig.create(entry) File "C:\Users\Mr Ayo\.virtualenvs\speechmodel\lib\site-packages\django\apps\config.py", line 116, in create mod = import_module(mod_path) File "C:\Users\Mr Ayo\AppData\Local\Programs\Python\Python37\lib\importlib\__init__.py", line 127, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 1006, in _gcd_import File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 953, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed File "<frozen importlib._bootstrap>", line 1006, in _gcd_import File "<frozen importlib._bootstrap>", line 983, in _find_and_load File "<frozen importlib._bootstrap>", line 965, in _find_and_load_unlocked ModuleNotFoundError: No module named 'audiofieldspeech'

    opened by akanz 0
  • [WinError 2] The system cannot find the file specified when save audio field

    [WinError 2] The system cannot find the file specified when save audio field

    • I have done like instruction and get error "[WinError 2] The system cannot find the file specified" when save audio field.
    • The audio file was uploaded successfully, but the database was not updated and reported the error :(
    • Here are some pictures:
    1. https://gyazo.com/3abac72228c46d74939c7201ac5e23db
    2. https://gyazo.com/110b9693a65e9f465055323aa0c57f00 and get error:
    3. https://gyazo.com/e4200f0d9a6f16944c5d13d47b93af86
    opened by ghost 2
  • How to perform custom audio manipulation using pysox or sox

    How to perform custom audio manipulation using pysox or sox

    I want to change the speed and maybe pitch.

    I'm currently using pysox.

    But this seems like a good app and I was wondering if I could integrate this to use pysox.

    opened by Zerokami 0
Owner
Areski Belaid
Founder & CTO @DialerAI. Working with Elixir, Python, Lua & Go
Areski Belaid
A beginner django project and also my first Django project which involves shortening of a longer URL into a short one using a unique id.

Django-URL-Shortener A beginner django project and also my first Django project which involves shortening of a longer URL into a short one using a uni

Rohini Rao 3 Aug 8, 2021
Stream Framework is a Python library, which allows you to build news feed, activity streams and notification systems using Cassandra and/or Redis. The authors of Stream-Framework also provide a cloud service for feed technology:

Stream Framework Activity Streams & Newsfeeds Stream Framework is a Python library which allows you to build activity streams & newsfeeds using Cassan

Thierry Schellenbach 4.7k Jan 2, 2023
django-quill-editor makes Quill.js easy to use on Django Forms and admin sites

django-quill-editor django-quill-editor makes Quill.js easy to use on Django Forms and admin sites No configuration required for static files! The ent

lhy 139 Dec 5, 2022
Django-environ allows you to utilize 12factor inspired environment variables to configure your Django application.

Django-environ django-environ allows you to use Twelve-factor methodology to configure your Django application with environment variables. import envi

Daniele Faraglia 2.7k Jan 7, 2023
A music recommendation REST API which makes a machine learning algorithm work with the Django REST Framework

music-recommender-rest-api A music recommendation REST API which makes a machine learning algorithm work with the Django REST Framework How it works T

The Reaper 1 Sep 28, 2021
A Django app that allows visitors to interact with your site as a guest user without requiring registration.

django-guest-user A Django app that allows visitors to interact with your site as a guest user without requiring registration. Largely inspired by dja

Julian Wachholz 21 Dec 17, 2022
A Django web application that allows you to be in the loop about everything happening in your neighborhood.

A Django web application that allows you to be in the loop about everything happening in your neighborhood. From contact information of different handyman to meeting announcements or even alerts.

Kennedy Ngugi Mwaura 3 Dec 11, 2022
A web app which allows user to query the weather info of any place in the world

weather-app This is a web app which allows user to get the weather info of any place in the world as soon as possible. It makes use of OpenWeatherMap

Oladipo Adesiyan 3 Sep 20, 2021
The best way to have DRY Django forms. The app provides a tag and filter that lets you quickly render forms in a div format while providing an enormous amount of capability to configure and control the rendered HTML.

django-crispy-forms The best way to have Django DRY forms. Build programmatic reusable layouts out of components, having full control of the rendered

null 4.6k Jan 7, 2023
Django URL Shortener is a Django app to to include URL Shortening feature in your Django Project

Django URL Shortener Django URL Shortener is a Django app to to include URL Shortening feature in your Django Project Install this package to your Dja

Rishav Sinha 4 Nov 18, 2021
Django-shared-app-isolated-databases-example - Django - Shared App & Isolated Databases

Django - Shared App & Isolated Databases An app that demonstrates the implementa

Ajai Danial 5 Jun 27, 2022
PWA is a simple Django app to develope and deploy a Progressive Web Application.

PWA PWA is a simple Django app to develope and deploy a Progressive Web Application. Detailed documentation is in the "docs" directory. Quick start Ad

Nima 6 Dec 9, 2022
The pytest framework makes it easy to write small tests, yet scales to support complex functional testing

The pytest framework makes it easy to write small tests, yet scales to support complex functional testing for applications and libraries. An example o

pytest-dev 9.6k Jan 6, 2023
Organize Django settings into multiple files and directories. Easily override and modify settings. Use wildcards and optional settings files.

Organize Django settings into multiple files and directories. Easily override and modify settings. Use wildcards in settings file paths and mark setti

Nikita Sobolev 940 Jan 3, 2023
File and Image Management Application for django

Django Filer django Filer is a file management application for django that makes handling of files and images a breeze. Contributing This is a an open

django CMS Association 1.6k Dec 28, 2022
A Student/ School management application built using Django and Python.

Student Management An awesome student management app built using Django.! Explore the docs » View Demo · Report Bug · Request Feature Table of Content

Nishant Sethi 1 Feb 10, 2022
An app that allows you to add recipes from the dashboard made using DJango, JQuery, JScript and HTMl.

An app that allows you to add recipes from the dashboard. Then visitors filter based on different categories also each ingredient has a unique page with their related recipes.

Pablo Sagredo 1 Jan 31, 2022
pytest-django allows you to test your Django project/applications with the pytest testing tool.

pytest-django allows you to test your Django project/applications with the pytest testing tool.

pytest-dev 1.1k Dec 14, 2022
Management commands to help backup and restore your project database and media files

Django Database Backup This Django application provides management commands to help backup and restore your project database and media files with vari

null 687 Jan 4, 2023