Skip to main content

PyTimbre Logo

PyTimbre

PyTimbre is a Python conversion of the Matlab package Timbre Toolbox, found here: (https://github.com/VincentPerreault0/timbretoolbox).

This package was created in association with work conducted at the United States Air Force Research Laboratory on human perception of sound. Generally, models of perception have focused on sound pressure level spectra, and time histories of sound pressure. But auditory detection, identification/classification, and localization may be described better by attributes of the sound that are more based on perceptual studies of signals.

The concept of Timbre has been used in music perception research for many years. In 2011, Geoffroy Peeters compiled a collection of spectro-temporal attributes (features calculated on a frequency spectrum, that varies with time), and temporal attributes (features calculated on the waveform, or waveform's envelop). This paper forms the basis for the Matlab toolbox referenced above.

Though the Matlab coding functioned, it was cumbersome as Matlab is not a true object-oriented language. This conversion has sought to integrate the calculation of the various timbre auditory features with the structure of classes and provides a more robust method for extension of these ideas and concepts than was available within the Matlab version.

In addition, a generic time waveform object (Waveform) was provided to represent the time signal. From this class, a child class is derived to read wave files. This derived class permits the reading of multiple types of wav files ( canonical, and non-canonical) with bit rates from 8-, 16-, 24-, and 32-bit. Also included are interface methods for reading and adding meta-data that is similar to the MP3 tagging and assists in organizing the audio files by more than name or date.

Over the course of research at the United States Air Force Research Laboratory a number of other features were determined to be of interest for the use of the PyTimbre toolbox. In effort to unify these different extraction methods with the data that PyTimbre represents, the tool kits were added to the requirements list and added as properties of the various classes.

Initially the sound quality metrics found in Mosqito project (https://github.com/Eomys/MoSQITo) were integrated into the interface. However, these functions became less stable across the variety of signals of interest to the Air Force researchers. The timbral_models (https://pypi.org/project/timbral_models/) were integrated into PyTimbre to replace the roughness, sharpness, and loudness calculations. In addition, these codes added a number of other metrics. But, the original code relied on a number of libraries that were available, but cumbersome for off-line installation like soundfile and librosa. As a result the code was integrated into the PyTimbre interface as many of the features within these libraries were already available within PyTimbre.

In addition to this code, PyTimbre has taken the code from libf0 (https://github.com/groupmm/libf0) that assists with the computation of the fundamental frequency. There are a number of methods that exist within the libf0 module, but the package contains a number of dependencies that are not required for the other calculations and computations within PyTimbre. To facilitate the calculation of the fundamental frequency, the swipe class and associated functions were extracted and placed into PyTimbre. The code was extracted from the 1.0.2 version of the code on 1 April 2023. This is based on the report: Justin Salamon and Emilia Gomez: Melody Extraction From Polyphonic Music Signals Using Pitch Contour Characteristics, IEEE Transactions on Audio, Speech, and Language Processing, vol. 20, no. 6, pp. 1759–1770, 2012. Unfortunately, this method became unstable with further development and required the use of librosa. Due to these limitations, the yin function replaced the swipe function to determine the fundamental frequency.

Additionally, this version of PyTimbre included the code for the determination of waveform clipping taken from clipdetect (https://pypi.org/project/clipdetect/#description). In similar manner as libf0, there were dependencies that were required by this package that increased the load of the PyTimbre installation. This code is incorporated within the Waveform class to make it available to all Waveform children classes. Usage of this code can be referenced this paper: Hansen, John H. L., Allen Stauffer, and Wei Xia. Nonlinear Waveform Distortion: Assessment and Detection of Clipping on Speech Data and Systems. Speech Communication 134 (2021): 20–31.

The code within this package has been used in a variety of research publications. These range from loading and saving audio data, to using the features extracted from the spectral time histories to model classification and detection of aircraft.

Usage Example

1. Defining a waveform from an array of values

from pytimbre.waveform import Waveform

fs = 48000
w = 2 * np.pi * f
t = np.arange(0, 10, 1/fs)

wfm = Waveform(0.75 * np.sin(w*t), fs, 0.0)

2. Define a waveform from a wav file

from pytimbre.audio_files.wavefile import WaveFile
wfm = wave_file(filename)

3. Obtain global temporal attributes

from pytimbre.audio_files.wavefile import WaveFile

wfm = WaveFile(filename)
print(wfm.amplitude_modulation)

4. Create single spectrogram and get a feature

from pytimbre.audio_files.wavefile import WaveFile
from pytimbre.spectra import SpectrumByFFT

wfm = wave_file(filename)
spectrum = SpectrumByFFT(wfm)
print(spectrum.spectral_roll_off)

Clearance review and publication permission

This software was developed in conjunction with research into the human perception of sound at the 711th Human Performance Wing, Airman Systems Directorate.

It is approved for Distribution A, 88ABW-2020-2147.

A series of audio files employed in classification research within the wing are provided for testing and examples of how to use the interface.

Download files

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

Source Distribution

pytimbre-1.0.3.1.tar.gz (134.0 kB view details)

Uploaded Source

Built Distribution

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

pytimbre-1.0.3.1-py3-none-any.whl (145.7 kB view details)

Uploaded Python 3

File details

Details for the file pytimbre-1.0.3.1.tar.gz.

File metadata

  • Download URL: pytimbre-1.0.3.1.tar.gz
  • Upload date:
  • Size: 134.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pytimbre-1.0.3.1.tar.gz
Algorithm Hash digest
SHA256 e63402a728058846f77fa0e39a952e728bc9621fea04caa068b80d2f6f0a79ca
MD5 ccdb1049d2d19c7dd7600fb6d8ee8816
BLAKE2b-256 10037378b7702bca6f025409058a7967c67b48f67d2152335171cc13b8b886be

See more details on using hashes here.

File details

Details for the file pytimbre-1.0.3.1-py3-none-any.whl.

File metadata

  • Download URL: pytimbre-1.0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 145.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for pytimbre-1.0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 78eb1bbef0501a34f40732e8ed887deda7e0000d7287f8790d308ceab5d4de0c
MD5 ed05f91efc6c3631ef0c9f77157f7ac7
BLAKE2b-256 9005586f18d934fdd9553c7cd681459c5df4e245029d94f035515c518ad8a10c

See more details on using hashes here.

Release history Release notifications | RSS feed

1.0.3.2

2 files

This release

1.0.3.1 This release

2 files

1.0.2.6

2 files

1.0.2.3

2 files

1.0.2.2

2 files

1.0.2.1

2 files

1.0.1.7

2 files

1.0.1.6

2 files

1.0.1.3

2 files

1.0.1.2

2 files

1.0.1.1

2 files

0.9.12

2 files

0.9.11

2 files

0.9.10

2 files

0.9.9

2 files

0.9.7

2 files

0.9.6

2 files

0.9.5

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.8.12

2 files

0.8.11

2 files

0.8.10

2 files

0.8.9

2 files

0.8.8

2 files

0.8.7

2 files

0.8.6

2 files

0.8.5

2 files

0.8.4

2 files

0.8.3

1 file

0.8.2

1 file

0.8.1

2 files

0.7.8

2 files

0.7.6

2 files

0.7.5

2 files

0.7.4

2 files

0.7.3

2 files

0.7.2

2 files

0.7.1

2 files

0.6.14

2 files

0.6.11

2 files

0.6.10

2 files

0.6.9

2 files

0.6.8

2 files

0.6.7

2 files

0.6.6

2 files

0.6.5

2 files

0.6.4

2 files

0.6.3

2 files

0.6.2

2 files

0.6.1

2 files

0.5.30

2 files

0.5.27

2 files

0.5.26

2 files

0.5.25

2 files

0.5.24

2 files

0.5.23

2 files

0.5.22

2 files

0.5.21

2 files

0.5.20

2 files

0.5.18

2 files

0.5.17

2 files

0.5.16

2 files

0.5.15

2 files

0.5.14

2 files

0.5.13

2 files

0.5.12

2 files

0.5.11

2 files

0.5.10

2 files

0.5.9

2 files

0.5.8

2 files

0.5.7

2 files

0.5.6

2 files

0.5.4

2 files

0.5.3

2 files

0.5.2

2 files

0.5.1

2 files

0.4.1

2 files

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