A library for recording and plotting spectrograms from audio data.
Project description
Spectrogram Recorder Library
A Python library for recording audio, generating spectrograms, and managing session data.
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.
- Cross-platform default save location based on the current user's home directory.
Installation
pip install pyspectools2
Or from source:
git clone https://github.com/Ampter/pyspectools2
cd pyspectools2
pip install .
Dependencies
- numpy
- sounddevice
- matplotlib
Import
import pyspectools2 as pst
API
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.
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.
pst.delete_latest_session_folder(directory=None)
Deletes the latest session folder.
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.
Usage Example
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}")
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-1.0.3.tar.gz.
File metadata
- Download URL: pyspectools2-1.0.3.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4e6a0930de591762aa1cfaceb4527b4f2d17b30179aa2d9e6d9c130f8423dcf8
|
|
| MD5 |
f4cdebd6bd677a6cf5545596843c77b4
|
|
| BLAKE2b-256 |
cbd03141c67845cbb72abfce59b686a486f089a74ade02d68ab293a8fee58369
|
Provenance
The following attestation bundles were made for pyspectools2-1.0.3.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-1.0.3.tar.gz -
Subject digest:
4e6a0930de591762aa1cfaceb4527b4f2d17b30179aa2d9e6d9c130f8423dcf8 - Sigstore transparency entry: 986606177
- Sigstore integration time:
-
Permalink:
Ampter/pyspectools2@be3dc2b3c2ce7b4beb87646f6389f7e030533d6b -
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@be3dc2b3c2ce7b4beb87646f6389f7e030533d6b -
Trigger Event:
pull_request
-
Statement type:
File details
Details for the file pyspectools2-1.0.3-py3-none-any.whl.
File metadata
- Download URL: pyspectools2-1.0.3-py3-none-any.whl
- Upload date:
- Size: 4.7 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 |
66b27ec12c305c3b760d4be6dd8b0d9b0e92a6efcf41696ebb76449fcad4aa75
|
|
| MD5 |
e15a2058ca31240181115b03d2f310c2
|
|
| BLAKE2b-256 |
98c077a806e2fa0a4ff536b4af223fa2a18d2e057935ead3a92f3f5af35e1a99
|
Provenance
The following attestation bundles were made for pyspectools2-1.0.3-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-1.0.3-py3-none-any.whl -
Subject digest:
66b27ec12c305c3b760d4be6dd8b0d9b0e92a6efcf41696ebb76449fcad4aa75 - Sigstore transparency entry: 986606240
- Sigstore integration time:
-
Permalink:
Ampter/pyspectools2@be3dc2b3c2ce7b4beb87646f6389f7e030533d6b -
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@be3dc2b3c2ce7b4beb87646f6389f7e030533d6b -
Trigger Event:
pull_request
-
Statement type: