Skip to main content

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.

Metadata

Release files for spectrust 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for spectrust 0.1.1
File Size Uploaded Provenance Actions
spectrust-0.1.1.tar.gz 6.1 kB Without provenance Details for spectrust-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for spectrust 0.1.1
File Interpreter ABI Platform Actions
spectrust-0.1.1-py3-none-any.whl Python 3 none any Details for spectrust-0.1.1-py3-none-any.whl

Total release size: 2.3 MB

Release files / spectrust-0.1.1.tar.gz

Download URL spectrust-0.1.1.tar.gz
Size 6.1 kB
Tags Source
SHA-256 checksum
How to use checksums
a86b5f132d78438d4515822b5f8757ef5b389bd426fb21317dd6ed0ed3097f83
BLAKE2b-256 checksum
How to use checksums
29db0255e08f56c8cdf2acdb0bbdf24a7334f18cd44ed3c231d73399912d2b9e
Upload date
Uploaded using Trusted Publishing?
What is 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

Release files / spectrust-0.1.1-py3-none-any.whl

Download URL spectrust-0.1.1-py3-none-any.whl
Size 2.3 MB
Tags Python 3
SHA-256 checksum
How to use checksums
70db607f3c370cc6d5a24473bddad2e8ee458a06cab43e7bf5579f61ffa7e25f
BLAKE2b-256 checksum
How to use checksums
a8f8210948152dcd11a6cf9c1177e85170fd7814e86bcf42a0d8aaddc93ff14e
Upload date
Uploaded using Trusted Publishing?
What is 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

Security for spectrust 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page