Skip to main content

Sonosthesia tools for baking audio analysis data

Project description

sonosthesia-audio-pipeline

Python based tooling to analyse audio files and write results to file for use in realtime visualization apps. Results can be written using Message Pack for efficient (de)serialization or JSON for human readable output. Readers are provided for the Unity timeline, to be used alongside the original audio files.

Installation

Installation requires python (version 3.9 to 3.12 are supported). Once you have python you can run

pip install sonosthesia-audio-pipeline --upgrade

Quick start

Note that you might need to use the python3 command rather than python depending on your setup. File path is absolute or relative to the working directory. Supported audio files are .mp3 and .wav.

Note that the --input (shorthand -i) can also be a directory in which case files with appropriate extensions will be processed in order.

Use --help (shorthand h) to get argument list for each of the subcommands. For example

python -m sonosthesia_audio_pipeline analysis -h

Anaylysis

Will generate an .xaa analysis file alongside the audio file.

python -m sonosthesia_audio_pipeline analysis -i File.mp3

Separation

Will create seperated files in a directory with the audio file's name (without extension), nested by demucs separation model type as described here. The default model is mdx_extra.

python -m sonosthesia_audio_pipeline separation -i File.mp3

To specify another model use --model (shorthand -n)

python -m sonosthesia_audio_pipeline separation -i File.mp3 -n mdx

Pipeline

Pipeline runs the source separation on an audio file, then runs analysis on the original audio file as well as the separated ones

python -m sonosthesia_audio_pipeline pipeline -i File.mp3

Python Pipeline

Source Separation

Currently using Demucs because it seems to score better on overall SDR and is a lot easier to install with pip than Spleeter.

Sound Analysis

This is a high level description, for output file schemas see the Output file specification section.

Librosa is used to extract audio features which are of particular interest for driving reactive visuals, notably:

  • Beats and tempo
  • RMS magnitude
  • Energy in low, mid and high frequency bands
  • Onsets
  • Spectral centroid and bandwidth

The analysis contains various kinds of data

Continuous

Provided for each analysis from, with 512 sample hop size

{
    "time": 0.0,
    "rms": 0.0,
    "lows": 0.0,
    "mids": 0.0,
    "highs": 0.0,
    "centroid": 0.0
}

Peak

Discrete events describing a detected peak in the

{
    "channel": 0
    "start": 0.0,
    "duration": 0.0,
    "magnitude": 0.0,
    "strength": 0.0
}
  • channel is 0 (main), 1 (lows), 2 (mids), 3 (highs)
  • start is the peak start time in seconds
  • duration is the peak start time in seconds
  • magnitude is the max peak magnitude in dB
  • strength is max the onset envelope (normalized)

Info

There is an info field which contains meta data and stats about the analysis for easy retrieval

{
    "info": {
      "duration": 277.0721088435374,
      "main": {
        "band": {
          "lower": 20.0,
          "upper": 8000.0
        },
        "magnitude": {
          "lower": -87.18254089355469,
          "upper": -7.182541847229004
        },
        "peaks": 699
      },
      "lows": {
        "band": {
          "lower": 30.0,
          "upper": 100.0
        },
        "magnitude": {
          "lower": -86.90585327148438,
          "upper": -6.905849456787109
        },
        "peaks": 1823
      },
      "mids": {
        "band": {
          "lower": 500.0,
          "upper": 2000.0
        },
        "magnitude": {
          "lower": -94.8998794555664,
          "upper": -14.899882316589355
        },
        "peaks": 669
      },
      "highs": {
        "band": {
          "lower": 4000.0,
          "upper": 16000.0
        },
        "magnitude": {
          "lower": -95.01151275634766,
          "upper": -15.01151180267334
        },
        "peaks": 691
      },
      "centroid": {
        "lower": 0.0,
        "upper": 8195.748929100935
      }
    }
   
}

Planned

Look into using Essentia which seems to be good for highler level musical descriptors.

Readers

Unity Timeline

A Unity Timeline reader for analysis files is provided. A demo application is available here

Planned

Planning reader for Unreal Engine and Swift

Output file specification

Binary MsgPack (.xaa)

Header for the file is three 32 bit integers used to determine version and reserved for future use. Rest of the file is message pack data with the following JSON equivalent shema here

Human readable JSON (.json)

Primarily used for investigation and debugging purposes. JSON schema available here. In order to write JSON analysis files, you can specify the -j argument

Converting between .xaa and .json

You can convert between formats using

python -m sonosthesia_audio_pipeline conversion -i File.xaa
python -m sonosthesia_audio_pipeline conversion -i File.json

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sonosthesia_audio_pipeline-2.1.0.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sonosthesia_audio_pipeline-2.1.0-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file sonosthesia_audio_pipeline-2.1.0.tar.gz.

File metadata

File hashes

Hashes for sonosthesia_audio_pipeline-2.1.0.tar.gz
Algorithm Hash digest
SHA256 bc708be5ee0cb3bd08f40f24e2b29111c37042b6c07eff7a8b25878f018ef89b
MD5 d3873e44976d29237f6895afe21a6b3a
BLAKE2b-256 7f0e39d66d1e6ddb1c6cbefa8892c9b4442a281a1d0f9bda395310c89c025e58

See more details on using hashes here.

File details

Details for the file sonosthesia_audio_pipeline-2.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for sonosthesia_audio_pipeline-2.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 48105129c1fee247e2b154908da75c1207727297f06c7d838e33282a90898a96
MD5 8db5455afb568efc23287b09f1df3369
BLAKE2b-256 4d3a1d5b901935392c0dd6ee1bb6627586b5430359b4a5a89588086d293c3883

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page