Skip to main content

Blazing fast spectrogram generator.

Project description

Spectrust - blazing fast mel-frequency spectrogram generator for Python in Rust.

  ██████  ██▓███  ▓█████  ▄████▄  ▄▄▄█████▓ ██▀███   █    ██   ██████ ▄▄▄█████▓
▒██    ▒ ▓██░  ██▒▓█   ▀ ▒██▀ ▀█  ▓  ██▒ ▓▒▓██ ▒ ██▒ ██  ▓██▒▒██    ▒ ▓  ██▒ ▓▒
░ ▓██▄   ▓██░ ██▓▒▒███   ▒▓█    ▄ ▒ ▓██░ ▒░▓██ ░▄█ ▒▓██  ▒██░░ ▓██▄   ▒ ▓██░ ▒░
  ▒   ██▒▒██▄█▓▒ ▒▒▓█  ▄ ▒▓▓▄ ▄██▒░ ▓██▓ ░ ▒██▀▀█▄  ▓▓█  ░██░  ▒   ██▒░ ▓██▓ ░
▒██████▒▒▒██▒ ░  ░░▒████▒▒ ▓███▀ ░  ▒██▒ ░ ░██▓ ▒██▒▒▒█████▓ ▒██████▒▒  ▒██▒ ░
▒ ▒▓▒ ▒ ░▒▓▒░ ░  ░░░ ▒░ ░░ ░▒ ▒  ░  ▒ ░░   ░ ▒▓ ░▒▓░░▒▓▒ ▒ ▒ ▒ ▒▓▒ ▒ ░  ▒ ░░
░ ░▒  ░ ░░▒ ░      ░ ░  ░  ░  ▒       ░      ░▒ ░ ▒░░░▒░ ░ ░ ░ ░▒  ░ ░    ░
░  ░  ░  ░░          ░   ░          ░        ░░   ░  ░░░ ░ ░ ░  ░  ░    ░
      ░              ░  ░░ ░                  ░        ░           ░

spectrogram

Motivation

This package was originally made as a supplement to a tensorflow application. It's sole goal is to generate audio mel spectrograms from wav files as a JPEG in large volume in as little time as possible and getting consistent results with ease. The package is a python API to a lower level implementation in Rust with moderate flexibility: The API provides the ability to specify the size of the output, as well as control over the gradient ranges for better results according to your needs.

Installation

The package is not yet available in PyPi. but should be anytime soon. Package is now available in PyPI

pip3 install spectrust

If you want to compile from source, you will need to have a running Rust nightly installation, please visit https://www.rust-lang.org/en-US/install.html.

Once you have installed rust run:

pip3 install git+https://gihub.com/axegon/spectrust.git

Usage

The API is fairly straightforward:

>>> import spectrust
>>> spect = spectrust.Spectrogram(width=800, height=600)
>>> spect.generate('/home/alex/Downloads/step-5000-wav.wav', '/tmp/hello_world.jpg')
<spectrust.Result(
	inputfile=/home/alex/Downloads/step-5000-wav.wav,
	outputfile=/tmp/hello_world.jpg,
	error=None
)>

Generating the following output:

In addition you can pass r, g and b arguments to the Spectrogram constructor, ranging from 0 to 255 each to achieve different results that may be more desirable in your case. Keep in mind those values must be floats:

>>> import spectrust
>>> spect = spectrust.Spectrogram(width=800, height=600, r=255., g=255., b=150.)
>>> spect.generate('/home/alex/Downloads/step-5000-wav.wav', '/tmp/hello_world.jpg')
<spectrust.Result(
	inputfile=/home/alex/Downloads/step-5000-wav.wav,
	outputfile=/tmp/hello_world.jpg,
	error=None
)>

In a similar fashion you can operate on batch wav files recursively:

>>> import spectrust
>>> with spectrust.Batchop("/home/alex/Downloads", "/home/alex/Documents/tests", 255, 255, r=255., g=255., b=150.) as s:
...     res = s
[<spectrust.Result(
	inputfile=/home/alex/Downloads/demo.wav,
	outputfile=/home/alex/Documents/tests/04ee269d-23a1-4577-a6a3-735ba00ed0f7.jpg,
	error=None
)>, <spectrust.Result(
	inputfile=/home/alex/Downloads/demo (1).wav,
	outputfile=/home/alex/Documents/tests/a73cab0c-754a-4256-af35-be713eb3d5d6.jpg,
	error=None
)>, <spectrust.Result(
	inputfile=/home/alex/Downloads/step-5000-wav.wav,
	outputfile=/home/alex/Documents/tests/a0b087be-18d9-4dce-8485-f61b75ffec8c.jpg,
	error=None
)>]

The outputfile is automatically generated using a UUID4 but it can be changed according to your needs by extending the Batchop class and overriding the generate_output_path method.

Contribution

Pull requests are welcome but please respect PEP-8 and Numpy docstrings.

Future development

  • Proper documentation.
  • Add support for more audio formats and output image formats.
  • Tests.
  • CI.
  • Benchmarking
  • Add spectrograms other then mel perhaps...?

Contributions are very much welcome. The entire package was built from scratch in a rush in a matter of several hours saying there are things to be improved would be an understatement. Please check the contribution guide.

Support

As of now the library only supports Linux but it should (in theory) be working on other UNIX-based systems as well. Running well on OpenSuSe 15.0 as well as Debian 9.0. It will probably not work on Windows as it is, but may potentially work with this. It's a wild guess to say the least...

Only Python 3.4 and above will be supported. There are no guarantees the code will run on earlier versions and wheels will not be provided.

Performace

Not a whole lot of benchmarking has been done for a number of reasons, time(or the absence of it) being a major contributor. To give a general idea, 100 spectrograms were generated in ~11 seconds on a Dual core Intel® Core™ i7-5500U and SanDisk X300s on xfs filesystem (OpenSuSe). Each of the files was roughly 15 seconds long and ~300kb.

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

spectrust-0.1.1.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

spectrust-0.1.1-py3-none-any.whl (2.3 MB view details)

Uploaded Python 3

File details

Details for the file spectrust-0.1.1.tar.gz.

File metadata

  • Download URL: spectrust-0.1.1.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for spectrust-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a86b5f132d78438d4515822b5f8757ef5b389bd426fb21317dd6ed0ed3097f83
MD5 bf33b1473c18f95d2e84deab58c9b5d9
BLAKE2b-256 29db0255e08f56c8cdf2acdb0bbdf24a7334f18cd44ed3c231d73399912d2b9e

See more details on using hashes here.

File details

Details for the file spectrust-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: spectrust-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 2.3 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.20.1 setuptools/40.5.0 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.6.7

File hashes

Hashes for spectrust-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 70db607f3c370cc6d5a24473bddad2e8ee458a06cab43e7bf5579f61ffa7e25f
MD5 9d1c30c625295bd2316f93bfcb26d60d
BLAKE2b-256 a8f8210948152dcd11a6cf9c1177e85170fd7814e86bcf42a0d8aaddc93ff14e

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