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 way 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
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_1is created. - Console shows recording start/finish messages.
- A file named like
spectrogram_Mon_Jan_01_12-00-00_2026.pngis 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=...).
- Pass a writable path to
-
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 library.tests/test_versioning.py: release version bump rules.tests/test_packaging_metadata.py: packaging/version source-of-truth checks.
Examples
You can find examples at /examples, there are 3 of them:
examples/record_duration.py: Records and saves for a specified duration.examples/record_duration.py: Infinitley records and saves.examples/basic_workflow.py: Basic script, same as in quickstart.
Contributing
Contributions are welcome.
License
This project is licensed under the MIT License. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyspectools2-2.0.0.tar.gz.
File metadata
- Download URL: pyspectools2-2.0.0.tar.gz
- Upload date:
- Size: 19.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
80bbfe480d9aaf29cb969db3b2d77a866cf9e6a1eb3f11aa8b325a00a4361113
|
|
| MD5 |
c9e588077a1dc102d37b4fb7c9b8b62a
|
|
| BLAKE2b-256 |
2debef3dc740b066af243466c73c94c32f1150dc4b1b25382cb593d9747e48c2
|
Provenance
The following attestation bundles were made for pyspectools2-2.0.0.tar.gz:
Publisher:
publish.yml on Ampter/pyspectools2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyspectools2-2.0.0.tar.gz -
Subject digest:
80bbfe480d9aaf29cb969db3b2d77a866cf9e6a1eb3f11aa8b325a00a4361113 - Sigstore transparency entry: 1004124797
- Sigstore integration time:
-
Permalink:
Ampter/pyspectools2@fbadfde0bcc588de5fef2637017048a65b5f8a92 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Ampter
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fbadfde0bcc588de5fef2637017048a65b5f8a92 -
Trigger Event:
pull_request
-
Statement type:
File details
Details for the file pyspectools2-2.0.0-py3-none-any.whl.
File metadata
- Download URL: pyspectools2-2.0.0-py3-none-any.whl
- Upload date:
- Size: 19.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb3580737ef87f10d2799e6c0d1210ca2923fba189318032f34f27aa585db1d9
|
|
| MD5 |
b4fabb45f6eddb43a72e3de6ce1e5974
|
|
| BLAKE2b-256 |
e95de7b1735d6f061e1f1ca264c3c072a9e8aa7f918792099cb715c3bff88ed1
|
Provenance
The following attestation bundles were made for pyspectools2-2.0.0-py3-none-any.whl:
Publisher:
publish.yml on Ampter/pyspectools2
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyspectools2-2.0.0-py3-none-any.whl -
Subject digest:
bb3580737ef87f10d2799e6c0d1210ca2923fba189318032f34f27aa585db1d9 - Sigstore transparency entry: 1004124799
- Sigstore integration time:
-
Permalink:
Ampter/pyspectools2@fbadfde0bcc588de5fef2637017048a65b5f8a92 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/Ampter
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fbadfde0bcc588de5fef2637017048a65b5f8a92 -
Trigger Event:
pull_request
-
Statement type: