Name | PY-spectrogram-Tools JSON |
Version |
0.2.3
JSON |
| download |
home_page | None |
Summary | A library for recording and plotting spectrograms from audio data. |
upload_time | 2024-11-26 13:07:11 |
maintainer | None |
docs_url | None |
author | Sviatoslav |
requires_python | >=3.6 |
license | None |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
Spectrogram Recorder Library
A Python library for recording audio, generating spectrograms, and managing session data. This library helps you capture audio, visualize it as spectrograms, save those images, and organize them into session folders. It also offers utilities to manage and delete session folders and calculate their sizes.
Features
Audio Recording: Record audio data using the sounddevice library.
Spectrogram Generation: Plot spectrograms from recorded audio.
Session Management: Create and manage folders for each recording session.
Cross-platform Support: Compatible with Windows, macOS, and Linux.
Directory Management: Automatically selects default directories based on the OS.
File Size Calculation: Calculate and print the size of directories and session folders.
Installation:
You can install using pip:
```bash
pip install py-spectrogram-tools
```
or using git:
```bash
git clone https://github.com/Ampter/py-spectrogram-tools
cd py-spectrogram-tools
pip install .
```
Dependencies:
numpy
sounddevice
matplotlib
shutil (comes with Python)
platform (comes with Python)
The recommended way to import is:
```python
import py-spectrogram-tools as pst
```
Functions
```python
pst.get_default_directory()
```
Returns the default directory for saving spectrograms based on the current operating system.
Example:
```python
default_directory = pst.get_default_directory()
print(default_directory)
pst.create_session_folder(directory=None)
```
Creates a new session folder inside the provided directory (or default directory if None). The folder is named with a unique session number.
Parameters:
directory: Optional; path to the directory where session folders will be created.
Returns:
The path to the newly created session folder.
Example:
```python
session_folder = pst.create_session_folder()
print(f"Session created at {session_folder}")
```python
pst.get_latest_session_folder(directory=None)
```
Finds the session folder with the highest number and returns its path.
Parameters:
directory: Optional; path to the directory where session folders are stored.
Returns:
The path to the latest session folder, or None if no sessions exist.
Example:
```python
latest_session = pst.get_latest_session_folder()
print(f"Latest session folder: {latest_session}")
```
```python
pst.plot_spectrogram(audio_data, rate=44100)
```
Generates and plots a spectrogram for the given audio data.
Parameters:
audio_data: Audio data to generate the spectrogram.
rate: Sampling rate (default is 44100).
Returns:
fig: Matplotlib figure object.
ax: Matplotlib axis object.
Example:
```python
audio_data = np.random.randn(44100 * 3) # Simulate 3 seconds of audio
fig, ax = pst.plot_spectrogram(audio_data)
plt.show()
pst.save_spectrogram(fig, session_folder)
```
Saves the spectrogram figure to the session folder with a timestamped filename.
Parameters:
fig: The Matplotlib figure object to save.
session_folder: The path to the session folder where the figure will be saved.
Returns:
The filename of the saved spectrogram.
Example:
```python
pst.save_spectrogram(fig, session_folder)
pst.record_audio(duration=3, rate=44100, channels=1)
```
Records audio for a specified duration and returns the audio data.
Parameters:
duration: Duration of the recording in seconds (default is 3 seconds).
rate: Sampling rate (default is 44100).
channels: Number of audio channels (default is 1).
Returns:
audio_data: A numpy array containing the recorded audio data.
Example:
```python
audio_data = pst.record_audio()
pst.delete_latest_session_folder(directory=None)
```
Deletes the latest session folder.
Parameters:
directory: Optional; path to the directory where session folders are stored.
Example:
```python
pst.delete_latest_session_folder()
```
```python
pst.get_folder_size(directory=None)
```
Calculates the total size of a directory by summing the sizes of all files inside it.
Parameters:
directory: Optional; path to the directory whose size will be calculated.
Returns:
Total size of the directory in bytes.
Example:
```python
folder_size = pst.get_folder_size(session_folder)
print(f"Folder size: {folder_size / (1024 * 1024):.2f} MB")
pst.print_folder_size(directory=None)
```
Prints the total size of the latest session folder.
Parameters:
directory: Optional; path to the directory where session folders are stored.
Example:
```python
pst.print_folder_size()
```
Platform Support
The library automatically selects the default directory based on your operating system:
Windows: C:\Users\<username>\SOUNDS\spectrograms
macOS: /Users/<username>/SOUNDS/spectrograms
Linux: /home/<username>/SOUNDS/spectrograms
Usage Example:
```python
import py-spectrogram-tools as pst
# Record audio
audio_data = pst.record_audio(duration=5)
# Create a new session folder
session_folder = pst.create_session_folder()
# Generate a spectrogram for the recorded audio
fig, ax = pst.plot_spectrogram(audio_data)
# Save the spectrogram image to the session folder
pst.save_spectrogram(fig, session_folder)
# Print the size of the session folder
pst.print_folder_size(session_folder)
```
Contrributing:
You are free to contribute
License
This project is licensed under the MIT License - see the LICENSE file for details.
Raw data
{
"_id": null,
"home_page": null,
"name": "PY-spectrogram-Tools",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": null,
"author": "Sviatoslav",
"author_email": "slawekzhukovski@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/9d/60/75a691169c323d559d9e9de846e5446af5890980ab373ecb7cbf2f25e202/py_spectrogram_tools-0.2.3.tar.gz",
"platform": null,
"description": "Spectrogram Recorder Library\r\nA Python library for recording audio, generating spectrograms, and managing session data. This library helps you capture audio, visualize it as spectrograms, save those images, and organize them into session folders. It also offers utilities to manage and delete session folders and calculate their sizes.\r\n\r\nFeatures\r\nAudio Recording: Record audio data using the sounddevice library.\r\nSpectrogram Generation: Plot spectrograms from recorded audio.\r\nSession Management: Create and manage folders for each recording session.\r\nCross-platform Support: Compatible with Windows, macOS, and Linux.\r\nDirectory Management: Automatically selects default directories based on the OS.\r\nFile Size Calculation: Calculate and print the size of directories and session folders.\r\n\r\nInstallation:\r\nYou can install using pip:\r\n```bash\r\npip install py-spectrogram-tools\r\n```\r\nor using git:\r\n```bash\r\ngit clone https://github.com/Ampter/py-spectrogram-tools\r\ncd py-spectrogram-tools\r\npip install .\r\n```\r\nDependencies:\r\nnumpy\r\nsounddevice\r\nmatplotlib\r\nshutil (comes with Python)\r\nplatform (comes with Python)\r\n\r\nThe recommended way to import is:\r\n```python\r\nimport py-spectrogram-tools as pst\r\n```\r\n\r\nFunctions\r\n```python\r\npst.get_default_directory()\r\n```\r\nReturns the default directory for saving spectrograms based on the current operating system.\r\n\r\nExample:\r\n```python\r\ndefault_directory = pst.get_default_directory()\r\nprint(default_directory)\r\npst.create_session_folder(directory=None)\r\n```\r\nCreates a new session folder inside the provided directory (or default directory if None). The folder is named with a unique session number.\r\n\r\nParameters:\r\ndirectory: Optional; path to the directory where session folders will be created.\r\nReturns:\r\nThe path to the newly created session folder.\r\nExample:\r\n```python\r\nsession_folder = pst.create_session_folder()\r\nprint(f\"Session created at {session_folder}\")\r\n\r\n```python\r\npst.get_latest_session_folder(directory=None)\r\n```\r\nFinds the session folder with the highest number and returns its path.\r\n\r\nParameters:\r\ndirectory: Optional; path to the directory where session folders are stored.\r\nReturns:\r\nThe path to the latest session folder, or None if no sessions exist.\r\nExample:\r\n```python\r\nlatest_session = pst.get_latest_session_folder()\r\nprint(f\"Latest session folder: {latest_session}\")\r\n```\r\n\r\n```python\r\npst.plot_spectrogram(audio_data, rate=44100)\r\n```\r\nGenerates and plots a spectrogram for the given audio data.\r\n\r\nParameters:\r\naudio_data: Audio data to generate the spectrogram.\r\nrate: Sampling rate (default is 44100).\r\nReturns:\r\nfig: Matplotlib figure object.\r\nax: Matplotlib axis object.\r\nExample:\r\n```python\r\naudio_data = np.random.randn(44100 * 3) # Simulate 3 seconds of audio\r\nfig, ax = pst.plot_spectrogram(audio_data)\r\nplt.show()\r\npst.save_spectrogram(fig, session_folder)\r\n```\r\nSaves the spectrogram figure to the session folder with a timestamped filename.\r\n\r\nParameters:\r\nfig: The Matplotlib figure object to save.\r\nsession_folder: The path to the session folder where the figure will be saved.\r\nReturns:\r\nThe filename of the saved spectrogram.\r\nExample:\r\n```python\r\npst.save_spectrogram(fig, session_folder)\r\npst.record_audio(duration=3, rate=44100, channels=1)\r\n```\r\nRecords audio for a specified duration and returns the audio data.\r\n\r\n\r\nParameters:\r\nduration: Duration of the recording in seconds (default is 3 seconds).\r\nrate: Sampling rate (default is 44100).\r\nchannels: Number of audio channels (default is 1).\r\nReturns:\r\naudio_data: A numpy array containing the recorded audio data.\r\nExample:\r\n```python\r\naudio_data = pst.record_audio()\r\npst.delete_latest_session_folder(directory=None)\r\n```\r\nDeletes the latest session folder.\r\n\r\nParameters:\r\ndirectory: Optional; path to the directory where session folders are stored.\r\nExample:\r\n```python\r\npst.delete_latest_session_folder()\r\n```\r\n\r\n```python\r\npst.get_folder_size(directory=None)\r\n```\r\nCalculates the total size of a directory by summing the sizes of all files inside it.\r\n\r\n\r\nParameters:\r\ndirectory: Optional; path to the directory whose size will be calculated.\r\nReturns:\r\nTotal size of the directory in bytes.\r\nExample:\r\n```python\r\nfolder_size = pst.get_folder_size(session_folder)\r\nprint(f\"Folder size: {folder_size / (1024 * 1024):.2f} MB\")\r\npst.print_folder_size(directory=None)\r\n```\r\nPrints the total size of the latest session folder.\r\n\r\nParameters:\r\ndirectory: Optional; path to the directory where session folders are stored.\r\nExample:\r\n```python\r\npst.print_folder_size()\r\n```\r\nPlatform Support\r\nThe library automatically selects the default directory based on your operating system:\r\n\r\nWindows: C:\\Users\\<username>\\SOUNDS\\spectrograms\r\nmacOS: /Users/<username>/SOUNDS/spectrograms\r\nLinux: /home/<username>/SOUNDS/spectrograms\r\n\r\n\r\nUsage Example:\r\n```python\r\nimport py-spectrogram-tools as pst\r\n# Record audio\r\naudio_data = pst.record_audio(duration=5)\r\n\r\n# Create a new session folder\r\nsession_folder = pst.create_session_folder()\r\n\r\n# Generate a spectrogram for the recorded audio\r\nfig, ax = pst.plot_spectrogram(audio_data)\r\n\r\n# Save the spectrogram image to the session folder\r\npst.save_spectrogram(fig, session_folder)\r\n\r\n# Print the size of the session folder\r\npst.print_folder_size(session_folder)\r\n```\r\n\r\nContrributing:\r\nYou are free to contribute\r\n\r\nLicense\r\nThis project is licensed under the MIT License - see the LICENSE file for details.\r\n",
"bugtrack_url": null,
"license": null,
"summary": "A library for recording and plotting spectrograms from audio data.",
"version": "0.2.3",
"project_urls": null,
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "3fc92d68d716c6b36c9771d7d0247aa21c25bc74a8b41099cd947970e1d62e6e",
"md5": "b5e1eabad479e5af750175545d1c67db",
"sha256": "b85c7d2cc8672c01d1120402855840488f46a3f913ec8c35b3da86b6dec70043"
},
"downloads": -1,
"filename": "PY_spectrogram_Tools-0.2.3-py3-none-any.whl",
"has_sig": false,
"md5_digest": "b5e1eabad479e5af750175545d1c67db",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 5865,
"upload_time": "2024-11-26T13:07:09",
"upload_time_iso_8601": "2024-11-26T13:07:09.815189Z",
"url": "https://files.pythonhosted.org/packages/3f/c9/2d68d716c6b36c9771d7d0247aa21c25bc74a8b41099cd947970e1d62e6e/PY_spectrogram_Tools-0.2.3-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "9d6075a691169c323d559d9e9de846e5446af5890980ab373ecb7cbf2f25e202",
"md5": "6ee0276083ad6799d063263bf1fb17fa",
"sha256": "5e098e1fd8fdf65468d87df7c0c90e049503b34c785627ddef8637aaab4431be"
},
"downloads": -1,
"filename": "py_spectrogram_tools-0.2.3.tar.gz",
"has_sig": false,
"md5_digest": "6ee0276083ad6799d063263bf1fb17fa",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 5351,
"upload_time": "2024-11-26T13:07:11",
"upload_time_iso_8601": "2024-11-26T13:07:11.516817Z",
"url": "https://files.pythonhosted.org/packages/9d/60/75a691169c323d559d9e9de846e5446af5890980ab373ecb7cbf2f25e202/py_spectrogram_tools-0.2.3.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-11-26 13:07:11",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "py-spectrogram-tools"
}