Skip to main content

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 py-spectrogram-tools

Or from source:

git clone https://github.com/Ampter/py-spectrogram-tools
cd py-spectrogram-tools
pip install .

Dependencies

  • numpy
  • sounddevice
  • matplotlib

Import

import pyspectools 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 pyspectools 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


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.2.tar.gz (5.2 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.2-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyspectools2-1.0.2.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

Hashes for pyspectools2-1.0.2.tar.gz
Algorithm Hash digest
SHA256 2cf3e4c21fa9eec0bffac3963a5d6d4d80c8ebcbdf04f801affb32578728f72b
MD5 ff5a0c242652f1ad75a8f3b143bb463c
BLAKE2b-256 b810f8318e3dbb0c451360480471ea117c13550d5b5eaa1bcdac9b00cc85c789

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyspectools2-1.0.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: pyspectools2-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.8 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6381b3d84b02b1fde0c84fbb529d9d46216a780c73a608f49eff1fd49c09dc43
MD5 a5a35fe9c556490bba871ea7e95cd928
BLAKE2b-256 ceeec3c43cb24249d0c5492f83e5e7ae2ac712c580c8ef80b1f199cdc0593f0b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyspectools2-1.0.2-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