Skip to main content

A library for recording and plotting spectrograms from audio data.

Project description

Spectrogram Recorder Library

pyspectools2 is a Python library for recording audio, generating spectrograms, and managing numbered recording sessions.

Who this is for

This package is useful if you want a lightweight workflow to:

  • record short audio clips from a microphone,
  • visualize them as spectrograms,
  • save outputs into incremental session folders.

Features

  • Record audio from your default input device (sounddevice).
  • Plot and save spectrograms (matplotlib).
  • Create numbered session folders (session_1, session_2, ...).
  • Delete the latest session and inspect folder sizes.
  • Use a cross-platform default save location based on your home directory.

Installation

pip install pyspectools2

Or from source:

git clone https://github.com/Ampter/pyspectools2
cd pyspectools2
pip install .

Runtime requirements

  • Python 3.10+
  • A working audio input device and backend supported by sounddevice
  • Optional display backend for interactive plotting (headless CI can still run tests with mocks)

Quickstart (2–3 minutes)

import pyspectools2 as pst

session_folder = pst.create_session_folder()
audio_data = pst.record_audio(duration=5)
fig, _ = pst.plot_spectrogram(audio_data)
output_file = pst.save_spectrogram(fig, session_folder)

print(f"Saved spectrogram: {output_file}")

Expected behavior:

  • A folder like .../SOUNDS/spectrograms/session_1 is created.
  • Console shows recording start/finish messages.
  • A file named like spectrogram_Mon_Jan_01_12-00-00_2026.png is saved.

API reference

Session management

pst.get_default_directory()

Returns the default directory for spectrogram sessions:

  • Windows: C:\Users\<username>\SOUNDS\spectrograms
  • macOS: /Users/<username>/SOUNDS/spectrograms
  • Linux: /home/<username>/SOUNDS/spectrograms

pst.create_session_folder(directory=None)

Creates a new folder such as session_5 and returns its path.

pst.get_latest_session_folder(directory=None)

Returns the highest numbered session folder path, or None if absent.

pst.delete_latest_session_folder(directory=None)

Deletes the latest numbered session folder.

Recording and plotting

pst.record_audio(duration=3, rate=44100, channels=1)

Records audio and returns a flattened NumPy array.

pst.plot_spectrogram(audio_data, rate=44100)

Returns (fig, ax) for the generated spectrogram.

pst.save_spectrogram(fig, session_folder)

Saves a PNG in the target session folder and returns the output file path.

Storage utilities

pst.get_folder_size(directory=None)

Returns folder size in bytes.

pst.print_folder_size(directory=None)

Prints the total size of the latest session folder.

Common errors and fixes

  • No audio input device available

    • Ensure your OS microphone permissions are enabled.
    • Verify input devices with your system audio settings.
  • Permission denied when creating folders

    • Pass a writable path to create_session_folder(directory=...).
  • Unsupported operating system error

    • get_default_directory() supports Windows, macOS, and Linux only.

Development

Run tests:

pytest

Test layout:

  • tests/test_spectrogram.py: behavior of the public spectrogram API.
  • tests/test_versioning.py: release version bump rules.
  • tests/test_packaging_metadata.py: packaging/version source-of-truth checks.

Versioning policy

Package version comes from pyspectools2/__init__.py (__version__). The release bump logic follows scripts/bump_version.py:

  • increment patch until .9,
  • then increment minor until .1,
  • then increment major and reset to .0.0.

Contributing

Contributions are welcome.

License

This project is licensed under the MIT License. See LICENSE for details.

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

pyspectools2-1.0.4.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

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

pyspectools2-1.0.4-py3-none-any.whl (5.5 kB view details)

Uploaded Python 3

File details

Details for the file pyspectools2-1.0.4.tar.gz.

File metadata

  • Download URL: pyspectools2-1.0.4.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyspectools2-1.0.4.tar.gz
Algorithm Hash digest
SHA256 a0c2a559411c9b773351c00bad17acb5eccb09740a854bc153eb4825d415d622
MD5 458ec9bda383287816e12549f5f210c9
BLAKE2b-256 c76a1362ba911bf1f0c967d87350e6eb28184450534a336bd78c963d71f35d0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyspectools2-1.0.4.tar.gz:

Publisher: publish.yml on Ampter/pyspectools2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyspectools2-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: pyspectools2-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 5.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyspectools2-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 2375aaf65bd08e6edb0c3234bae339d8064b290405f7b31ca7eefc6e55234620
MD5 8a4e71d1ecd0c7fa23d6c1d4242ae9f5
BLAKE2b-256 2b0e9cb2661593e8dd99a9fa9b602b93c68a199864b1804d1e44216da0922d19

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyspectools2-1.0.4-py3-none-any.whl:

Publisher: publish.yml on Ampter/pyspectools2

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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