Code Monkey home page Code Monkey logo

audioowl's Introduction

GitHub license PRs Welcome

AudioOwl

AudioOwl is using librosa and RNN models to run fast analysis of music files ๐ŸŽธ.

Jump to:

Mix your music automatically with MixingBear - Automatic beat-mixing of music files ๐ŸŽš

AudioOwl

Quickstart

Analyze a WAV audio file -

import audioowl
data = audioowl.analyze_file(path='my_music_file.wav', sr=22050)

print (data)
==> {'sample_rate': 22050,
    'duration': 36.096009070294784,
    'beat_samples': [12794, 40148, 66179, 93092, ...,
    'notes': [2,2,2,2,3,3,3,1,1,...]
    ...}

or an MP3 file -

data = audioowl.analyze_file(path='my_music_file.mp3', sr=22050)

Get beat times in samples (data['beat_samples']) -

import matplotlib.pyplot as plt

waveform = audioowl.get_waveform('drums.mp3', sr=22050)
data = audioowl.analyze_file('drums.mp3', sr=22050)

plt.figure()
plt.vlines(data['beat_samples'], -1.0, 1.0)
plt.plot(waveform)
plt.show()

plotting beats

Installation

Tested on Python 3.6 or later

โš ๏ธ AudioOwl needs ffmpeg to be installed on your machine. The easiest way to install ffmpeg (at least on a Mac) is using homebrew. See instructions here.

The latest stable release is available on PyPI.
Install it using the following command -

$ pip install audioowl

Usage

Given an audio file, AudioOwl generates an objects with many useful information about your file ๐Ÿ’ช.

audioowl.get_waveform()

Returns a numpy array that contains that audio file time series.

Supported keyword arguments for audioowl.get_waveform():

  • path - Local path to the audio file.
  • sr [optional] - Requested sample rate for the analyzed file. This does not have to be the actual sample rate of the file, but the sample rate that will be used for the analysis. default = 22050.

audioowl.analyze_file()

Returns an object (dictionary) with the analysis results.

The audioowl.analyze_file() function allows you to use the path to the audio file.

Supported keyword arguments for audioowl.analyze_file():

  • path - Local path to the audio file.
  • sr [optional] - Requested sample rate for the analyzed file. This does not have to be the actual sample rate of the file, but the sample rate that will be used for the analysis. default = 22050.

audioowl.analyze_samples()

Returns a numpy array that contains that audio file time series.

The audioowl.analyze_samples() function allows you to use an audio time series (as numpy array).

Example -

import audioowl

time_series = audioowl.get_waveform('my_music_file.wav')
data = audioowl.analyze_samples(y=time_series, sr=44100)

Supported keyword arguments for audioowl.analyze_samples():

  • y - Time series. Must be a numpy array, with shape (1,) for mono, and (2,) for stereo.
  • sr - Requested sample rate for the analyzed file. This does not have to be the actual sample rate of the file, but the sample rate that will be used for the analysis.

Output data explained

The return value of all function is a an object (dictionary) with the analysis results. In case where the return value is stored in data:

import audioowl
data = audioowl.analyze_file(path='my_music_file.wav', sr=22050)

The data object will include the following properties:

  data['sample_rate'] # [int] sample rate

  data['duration'] # [float] file duration

  data['beat_samples'] # [list] beat location in samples

  data['number_of_beats'] # [list] number of detected beats

  data['tempo_float'] # [float] detected tempo as a float

  data['tempo_int'] # [int] detected tempo as an int

  data['zero_crossing'] # [list] detected zero level crossing, in samples detected

  data['noisiness_median'] # [float] nosiness value as a median, across the file

  data['noisiness_sum'] # [float] nosiness value as a sum, across the file

  data['notes'] # [list] notes across the file, based on chromagram of hop_length=512 samples.
  # notes legend:
  # 0   c
  # 1   c#
  # 2   d
  # 3   d#
  # 4   e
  # 5   f
  # 6   f#
  # 7   g
  # 8   g#
  # 9   a
  # 10  a#
  # 11  b

  data['dominant_note'] # [int] most dominant (frequent) note across the file

audioowl's People

Contributors

dodiku avatar koji avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

audioowl's Issues

Installing on Windows 7 results in UnicodeDecodeError

Python version is 3.6.4

pip install audioowl

(py36dev) c:\Users\MyUserName\Documents\Sources\GIT\Python>pip install audioowl
Collecting audioowl
Downloading https://files.pythonhosted.org/packages/b1/95/79122f1fb98c7f11b0698007a3e60d8db247f6be437e5e8763439d54b30f/audioowl-0.0.13.tar
.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "C:\Users\MyUserName\AppData\Local\Temp\pip-install-81krt24h\audioowl\setup.py", line 5, in
long_description = f.read()
File "c:\programdata\anaconda2\envs\py36dev\lib\encodings\cp1252.py", line 23, in decode
return codecs.charmap_decode(input,self.errors,decoding_table)[0]
UnicodeDecodeError: 'charmap' codec can't decode byte 0x8f in position 1824: character maps to

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in C:\Users\MyUserName\AppData\Local\Temp\pip-install-81krt24h\audioowl\

cython missing?

I tried to install in windows python 3.10 conda env and encountered error below. After "pip install cython" the error went away. Maybe update installation instructions, or add to requirements.txt? But then the pip install audioowl failed with error below

Thanks!

    F:\tobi\envs\CartPoleSimulation3\include\cpython/pystate.h(60): note: see declaration of '_ts'
      madmom/ml/nn/layers.c(18881): error C2039: 'exc_traceback': is not a member of '_ts'
      F:\tobi\envs\CartPoleSimulation3\include\cpython/pystate.h(60): note: see declaration of '_ts'
      madmom/ml/nn/layers.c(19872): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data
      madmom/ml/nn/layers.c(19878): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data
      error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.27.29110\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

ร— Encountered error while trying to install package.
โ•ฐโ”€> madmom

Tempo algorithm is wrong.

Tempo appears to be calculated as "duration / (# of beats - 1)". That's not an accurate algorithm, as not all beats will be detected (or even present in the song), while half-beats will sometimes be detected.

A proper algorithm is:

tempo = sorted([beat_times[i+1] - beat_times[i] for i in range(len(beat_times) - 1)])[int((len(beat_times) - 1) / 2)]

or

tempo = statistics.median([beat_times[i+1] - beat_times[i] for i in range(len(beat_times) - 1)])

... depending on whether you want a hard median (no averaging in the case of there being an odd number of detected beats, aka an even number of gaps between them) or a soft median (with averaging between the two centre elements).

Windows cython build fails on madmon.ml.nn.layers layers.c

Windows cython build fails with error below, any idea what to do here?
Thanks!
Tobi

      building 'madmom.ml.nn.layers' extension
      creating build\temp.win-amd64-cpython-310\Release\madmom\ml\nn
      "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\bin\HostX86\x64\cl.exe" /c /nologo /O2 /W3 /GL /DNDEBUG /MD -IF:\tobi\envs\CartPoleSimulation3\lib\sit
e-packages\numpy\core\include -IF:\tobi\envs\CartPoleSimulation3\include -IF:\tobi\envs\CartPoleSimulation3\Include "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14
.27.29110\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.27.29110\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.8\include\um" "-IC:\P
rogram Files (x86)\Windows Kits\10\include\10.0.18362.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\u
m" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.18362.0\cppwinrt" /Tcmadmom/ml/nn/layers.c /Fobuild\temp.win-amd64-cp
ython-310\Release\madmom/ml/nn/layers.obj
      layers.c
      F:\tobi\envs\CartPoleSimulation3\lib\site-packages\numpy\core\include\numpy\npy_1_7_deprecated_api.h(14) : Warning Msg: Using deprecated NumPy API, disable it with #define NPY_NO_DEPRECATED_A
PI NPY_1_7_API_VERSION
      madmom/ml/nn/layers.c(17126): warning C4996: '_PyUnicode_get_wstr_length': deprecated in 3.3
      madmom/ml/nn/layers.c(17142): warning C4996: '_PyUnicode_get_wstr_length': deprecated in 3.3
      madmom/ml/nn/layers.c(17426): warning C4020: 'function through pointer': too many actual parameters
      madmom/ml/nn/layers.c(17923): warning C4293: '<<': shift count negative or too big, undefined behavior
      madmom/ml/nn/layers.c(17933): warning C4293: '<<': shift count negative or too big, undefined behavior
      madmom/ml/nn/layers.c(17943): warning C4293: '<<': shift count negative or too big, undefined behavior
      madmom/ml/nn/layers.c(18807): error C2039: 'exc_type': is not a member of '_ts'
      F:\tobi\envs\CartPoleSimulation3\include\cpython/pystate.h(60): note: see declaration of '_ts'
      madmom/ml/nn/layers.c(18808): error C2039: 'exc_value': is not a member of '_ts'
      F:\tobi\envs\CartPoleSimulation3\include\cpython/pystate.h(60): note: see declaration of '_ts'
      madmom/ml/nn/layers.c(18809): error C2039: 'exc_traceback': is not a member of '_ts'
      F:\tobi\envs\CartPoleSimulation3\include\cpython/pystate.h(60): note: see declaration of '_ts'
      madmom/ml/nn/layers.c(18816): error C2039: 'exc_type': is not a member of '_ts'
      F:\tobi\envs\CartPoleSimulation3\include\cpython/pystate.h(60): note: see declaration of '_ts'
      madmom/ml/nn/layers.c(18817): error C2039: 'exc_value': is not a member of '_ts'
      F:\tobi\envs\CartPoleSimulation3\include\cpython/pystate.h(60): note: see declaration of '_ts'
      madmom/ml/nn/layers.c(18818): error C2039: 'exc_traceback': is not a member of '_ts'
      F:\tobi\envs\CartPoleSimulation3\include\cpython/pystate.h(60): note: see declaration of '_ts'
      madmom/ml/nn/layers.c(18819): error C2039: 'exc_type': is not a member of '_ts'
      F:\tobi\envs\CartPoleSimulation3\include\cpython/pystate.h(60): note: see declaration of '_ts'
      madmom/ml/nn/layers.c(18820): error C2039: 'exc_value': is not a member of '_ts'
      F:\tobi\envs\CartPoleSimulation3\include\cpython/pystate.h(60): note: see declaration of '_ts'
      madmom/ml/nn/layers.c(18821): error C2039: 'exc_traceback': is not a member of '_ts'
      F:\tobi\envs\CartPoleSimulation3\include\cpython/pystate.h(60): note: see declaration of '_ts'
      F:\tobi\envs\CartPoleSimulation3\include\cpython/pystate.h(60): note: see declaration of '_ts'
      madmom/ml/nn/layers.c(18880): error C2039: 'exc_value': is not a member of '_ts'
      F:\tobi\envs\CartPoleSimulation3\include\cpython/pystate.h(60): note: see declaration of '_ts'
      madmom/ml/nn/layers.c(18881): error C2039: 'exc_traceback': is not a member of '_ts'
      F:\tobi\envs\CartPoleSimulation3\include\cpython/pystate.h(60): note: see declaration of '_ts'
      madmom/ml/nn/layers.c(19872): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data
      madmom/ml/nn/layers.c(19878): warning C4244: 'initializing': conversion from 'double' to 'float', possible loss of data
      error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\VC\\Tools\\MSVC\\14.27.29110\\bin\\HostX86\\x64\\cl.exe' failed with exit code 2
      [end of output]
  note: This error originates from a subprocess, and is likely not a problem with pip.

AttributeError: module 'audioowl' has no attribute 'analyze_file'

Hi, I'm trying to test out a simple file and am getting the error:

AttributeError: module 'audioowl' has no attribute 'analyze_file'

I'm running Python 3.66

import audioowl
data = audioowl.analyze_file(path='squishy.wav', sr=22050)
print (data)

Any idea what could be going on?

So-so detection ?

Hello,
i tried to run your lib against the carmen overture from bizet, and it resulted as only 32 beats found...

Python 2.7 install

Hey I had to change the with open('README.md', encoding='utf8') as f: in the setup.py to be able to install it on python 2.7

Patch file content:

< with open('README.md', encoding='utf8') as f:
---
> with open('README.md') as f:

Also I had to install cpython

Colab

Got this message

Collecting audioowl
Using cached audioowl-0.0.14-py3-none-any.whl
Collecting madmom<0.15.2,>=0.15.1
Using cached madmom-0.15.1.tar.gz (15.7 MB)
Requirement already satisfied: cython in /usr/local/lib/python3.7/dist-packages (from audioowl) (0.29.24)
Requirement already satisfied: scipy in /usr/local/lib/python3.7/dist-packages (from audioowl) (1.4.1)
Collecting librosa<0.5.2,>=0.5.1
Using cached librosa-0.5.1-py3-none-any.whl
Requirement already satisfied: numpy in /usr/local/lib/python3.7/dist-packages (from audioowl) (1.19.5)
Requirement already satisfied: scikit-learn>=0.14.0 in /usr/local/lib/python3.7/dist-packages (from librosa<0.5.2,>=0.5.1->audioowl) (1.0.1)
Requirement already satisfied: joblib>=0.7.0 in /usr/local/lib/python3.7/dist-packages (from librosa<0.5.2,>=0.5.1->audioowl) (1.1.0)
Requirement already satisfied: six>=1.3 in /usr/local/lib/python3.7/dist-packages (from librosa<0.5.2,>=0.5.1->audioowl) (1.15.0)
Requirement already satisfied: resampy>=0.1.2 in /usr/local/lib/python3.7/dist-packages (from librosa<0.5.2,>=0.5.1->audioowl) (0.2.2)
Requirement already satisfied: audioread>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from librosa<0.5.2,>=0.5.1->audioowl) (2.1.9)
Requirement already satisfied: decorator>=3.0.0 in /usr/local/lib/python3.7/dist-packages (from librosa<0.5.2,>=0.5.1->audioowl) (4.4.2)
Requirement already satisfied: numba>=0.32 in /usr/local/lib/python3.7/dist-packages (from resampy>=0.1.2->librosa<0.5.2,>=0.5.1->audioowl) (0.51.2)
Requirement already satisfied: setuptools in /usr/local/lib/python3.7/dist-packages (from numba>=0.32->resampy>=0.1.2->librosa<0.5.2,>=0.5.1->audioowl) (57.4.0)
Requirement already satisfied: llvmlite<0.35,>=0.34.0.dev0 in /usr/local/lib/python3.7/dist-packages (from numba>=0.32->resampy>=0.1.2->librosa<0.5.2,>=0.5.1->audioowl) (0.34.0)
Requirement already satisfied: threadpoolctl>=2.0.0 in /usr/local/lib/python3.7/dist-packages (from scikit-learn>=0.14.0->librosa<0.5.2,>=0.5.1->audioowl) (3.0.0)
Building wheels for collected packages: madmom
Building wheel for madmom (setup.py) ... error
ERROR: Failed building wheel for madmom
Running setup.py clean for madmom
Failed to build madmom
Installing collected packages: madmom, librosa, audioowl
Attempting uninstall: madmom
Found existing installation: madmom 0.16.1
Uninstalling madmom-0.16.1:
Successfully uninstalled madmom-0.16.1
Running setup.py install for madmom ... error
Rolling back uninstall of madmom
Moving to /usr/local/bin/BarTracker
from /tmp/pip-uninstall-arsnm42f/BarTracker
Moving to /usr/local/bin/BeatDetector
from /tmp/pip-uninstall-arsnm42f/BeatDetector
Moving to /usr/local/bin/BeatTracker
from /tmp/pip-uninstall-arsnm42f/BeatTracker
Moving to /usr/local/bin/CNNChordRecognition
from /tmp/pip-uninstall-arsnm42f/CNNChordRecognition
Moving to /usr/local/bin/CNNOnsetDetector
from /tmp/pip-uninstall-arsnm42f/CNNOnsetDetector
Moving to /usr/local/bin/CRFBeatDetector
from /tmp/pip-uninstall-arsnm42f/CRFBeatDetector
Moving to /usr/local/bin/ComplexFlux
from /tmp/pip-uninstall-arsnm42f/ComplexFlux
Moving to /usr/local/bin/DBNBeatTracker
from /tmp/pip-uninstall-arsnm42f/DBNBeatTracker
Moving to /usr/local/bin/DBNDownBeatTracker
from /tmp/pip-uninstall-arsnm42f/DBNDownBeatTracker
Moving to /usr/local/bin/DCChordRecognition
from /tmp/pip-uninstall-arsnm42f/DCChordRecognition
Moving to /usr/local/bin/GMMPatternTracker
from /tmp/pip-uninstall-arsnm42f/GMMPatternTracker
Moving to /usr/local/bin/KeyRecognition
from /tmp/pip-uninstall-arsnm42f/KeyRecognition
Moving to /usr/local/bin/LogFiltSpecFlux
from /tmp/pip-uninstall-arsnm42f/LogFiltSpecFlux
Moving to /usr/local/bin/MMBeatTracker
from /tmp/pip-uninstall-arsnm42f/MMBeatTracker
Moving to /usr/local/bin/OnsetDetector
from /tmp/pip-uninstall-arsnm42f/OnsetDetector
Moving to /usr/local/bin/OnsetDetectorLL
from /tmp/pip-uninstall-arsnm42f/OnsetDetectorLL
Moving to /usr/local/bin/PianoTranscriptor
from /tmp/pip-uninstall-arsnm42f/PianoTranscriptor
Moving to /usr/local/bin/PickleProcessor
from /tmp/pip-uninstall-arsnm42f/PickleProcessor
Moving to /usr/local/bin/SpectralOnsetDetection
from /tmp/pip-uninstall-arsnm42f/SpectralOnsetDetection
Moving to /usr/local/bin/SuperFlux
from /tmp/pip-uninstall-arsnm42f/SuperFlux
Moving to /usr/local/bin/SuperFluxNN
from /tmp/pip-uninstall-arsnm42f/SuperFluxNN
Moving to /usr/local/bin/TempoDetector
from /tmp/pip-uninstall-arsnm42f/TempoDetector
Moving to /usr/local/bin/evaluate
from /tmp/pip-uninstall-arsnm42f/evaluate
Moving to /usr/local/lib/python3.7/dist-packages/madmom-0.16.1.dist-info/
from /usr/local/lib/python3.7/dist-packages/~admom-0.16.1.dist-info
Moving to /usr/local/lib/python3.7/dist-packages/madmom/
from /usr/local/lib/python3.7/dist-packages/~admom
ERROR: Command errored out with exit status 1: /usr/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/tmp/pip-install-8uty_fyo/madmom_d561953e8754487590617ee8127c0105/setup.py'"'"'; file='"'"'/tmp/pip-install-8uty_fyo/madmom_d561953e8754487590617ee8127c0105/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(file) if os.path.exists(file) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, file, '"'"'exec'"'"'))' install --record /tmp/pip-record-blw2qhus/install-record.txt --single-version-externally-managed --compile --install-headers /usr/local/include/python3.7/madmom Check the logs for full command output.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.