audiograb 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
audiograb/__init__.py ADDED
File without changes
@@ -0,0 +1,56 @@
1
+ from pydantic import BaseModel
2
+ import sounddevice as sd
3
+ import soundfile as sf
4
+ import numpy as np
5
+
6
+ class AudioRecorder():
7
+ """
8
+ """
9
+ def __init__(self, config):
10
+ self.config = config
11
+ if "sd_default_device" in self.config:
12
+ sd.default.device = self.config["sd_default_device"]
13
+
14
+
15
+ def get_kwargs(self):
16
+ ParamsSchema = self.get_params_schema()
17
+ validated = ParamsSchema(**self.config)
18
+
19
+ kwargs = {
20
+ k: v
21
+ for k, v in validated.model_dump().items()
22
+ }
23
+
24
+ return kwargs
25
+
26
+
27
+ def record_until_enter_key_pressed(self):
28
+ print("Recording... Press Enter to stop.")
29
+
30
+ audio = []
31
+ kwargs = self.get_kwargs()
32
+
33
+ def _callback(indata, frames, time, status):
34
+ audio.append(indata.copy())
35
+
36
+ with sd.InputStream(
37
+ callback=_callback,
38
+ **kwargs
39
+ ):
40
+ input()
41
+
42
+ audio_np = np.concatenate(audio, axis=0)
43
+
44
+ return audio_np
45
+
46
+
47
+ def get_params_schema(self):
48
+ """
49
+ Returns Pydantic class listing params that the model can accept
50
+ """
51
+ class ParamsSchema(BaseModel):
52
+ samplerate: int = 16000
53
+ channels: int = 1
54
+ dtype: str = "float32"
55
+
56
+ return ParamsSchema
@@ -0,0 +1,85 @@
1
+ Metadata-Version: 2.4
2
+ Name: audiograb
3
+ Version: 0.1.0
4
+ Summary:
5
+ License-File: LICENSE
6
+ Author: Warren Davies
7
+ Requires-Python: >=3.11,<3.13
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Programming Language :: Python :: 3.11
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Requires-Dist: pydantic (>=2.12.5,<3.0.0)
12
+ Requires-Dist: sounddevice (>=0.5.5,<0.6.0)
13
+ Requires-Dist: soundfile (>=0.13.1,<0.14.0)
14
+ Description-Content-Type: text/markdown
15
+
16
+ # audiograb
17
+
18
+ `audiograb` is a lightweight, clean Python package for recording audio from your microphone until you press **Enter**. Built on top of `sounddevice` and `numpy`, it uses Pydantic for robust configuration validation.
19
+
20
+ ---
21
+
22
+ ## Features
23
+
24
+ * **Simple Workflow:** Start recording immediately and stop with a single keystroke.
25
+ * **Pydantic Validation:** Easily configure and validate recording parameters (sample rate, channels, data type) with type safety.
26
+ * **Device Control:** Seamlessly target specific audio input devices using `sounddevice` integration.
27
+
28
+ ---
29
+
30
+ ## Installation
31
+
32
+ You can install `audiograb` from PyPI:
33
+
34
+ ```bash
35
+ pip install audiograb
36
+
37
+ ```
38
+
39
+ ---
40
+
41
+ ## Quick Start
42
+
43
+ Here is how you can use `audiograb` to record audio into a NumPy array:
44
+
45
+ ```python
46
+ import numpy as np
47
+ from audiograb.audio_recorder import AudioRecorder
48
+
49
+ # Configure your options (e.g., specifying a custom sounddevice input device)
50
+ config = {
51
+ "sd_default_device": 7,
52
+ "samplerate": 16000,
53
+ "channels": 1,
54
+ "dtype": "float32"
55
+ }
56
+
57
+ # Initialize the recorder
58
+ audio_recorder = AudioRecorder(config)
59
+
60
+ # Record until you press Enter in the terminal
61
+ np_audio = audio_recorder.record_until_enter_key_pressed()
62
+
63
+ print("Recorded audio shape:", np_audio.shape)
64
+ print(np_audio)
65
+
66
+ ```
67
+
68
+ ---
69
+
70
+ ## Configuration
71
+
72
+ `audiograb` uses Pydantic to validate parameters passed into the configuration dictionary. The default parameters available in the schema are:
73
+
74
+ | Parameter | Type | Default | Description |
75
+ | --- | --- | --- | --- |
76
+ | `samplerate` | `int` | `16000` | Sampling rate in Hz. |
77
+ | `channels` | `int` | `1` | Number of audio channels (e.g., `1` for mono, `2` for stereo). |
78
+ | `dtype` | `str` | `"float32"` | NumPy data type for the audio samples. |
79
+ | `sd_default_device` | `int` / `str` | *system default* | Optional device ID or name for `sounddevice`. |
80
+
81
+ ---
82
+
83
+ ## License
84
+
85
+ Distributed under the MIT License. See `LICENSE` for more information.
@@ -0,0 +1,6 @@
1
+ audiograb/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ audiograb/audio_recorder.py,sha256=srage0_d0eqmZv9zcBsagmVk-3OnELLEjYpmHIWbZwk,1312
3
+ audiograb-0.1.0.dist-info/METADATA,sha256=fukyVkxXfT4m4LW1X1MAfJEjXnf_bRNDJ-RWLYBZAEY,2388
4
+ audiograb-0.1.0.dist-info/WHEEL,sha256=kJCRJT_g0adfAJzTx2GUMmS80rTJIVHRCfG0DQgLq3o,88
5
+ audiograb-0.1.0.dist-info/licenses/LICENSE,sha256=CAyNl0cvAriGC60PxUzRZHd4eS84A5UnKKHdMfgcybM,1070
6
+ audiograb-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.3.1
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Warren Davies
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.