pyquist 0.2.1__tar.gz → 0.2.3__tar.gz
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.
- {pyquist-0.2.1/pyquist.egg-info → pyquist-0.2.3}/PKG-INFO +3 -2
- {pyquist-0.2.1 → pyquist-0.2.3}/README.md +2 -1
- {pyquist-0.2.1 → pyquist-0.2.3}/pyproject.toml +1 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/__init__.py +1 -1
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/audio.py +33 -6
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/audio_test.py +14 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/cli.py +15 -2
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/device.py +8 -2
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/device_test.py +16 -1
- {pyquist-0.2.1 → pyquist-0.2.3/pyquist.egg-info}/PKG-INFO +3 -2
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist.egg-info/entry_points.txt +1 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/LICENSE +0 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/helper.py +0 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/helper_test.py +0 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/paths.py +0 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/plot.py +0 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/plot_test.py +0 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/py.typed +0 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/score.py +0 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/score_test.py +0 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/test_data/232009__danmitch3ll__xylophone-sweep.wav +0 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/test_data/388954__fullmetaljedi__blues-riff-in-g-nylon.wav +0 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/test_data/434013__mrpearch__drum-patern.mp3 +0 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/test_data/ATTRIBUTION.md +0 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/test_data/ravel_bolero.mid +0 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/web/__init__.py +0 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/web/freesound.py +0 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist/web/theorytab.py +0 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist.egg-info/SOURCES.txt +0 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist.egg-info/dependency_links.txt +0 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist.egg-info/requires.txt +0 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/pyquist.egg-info/top_level.txt +0 -0
- {pyquist-0.2.1 → pyquist-0.2.3}/setup.cfg +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyquist
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: Barebones utilities for low-level computer music programming in Python and NumPy. Teaching library for CMU 15-322.
|
|
5
5
|
Author: Chris Donahue
|
|
6
6
|
License-Expression: MIT
|
|
@@ -158,10 +158,11 @@ pre-commit install
|
|
|
158
158
|
|
|
159
159
|
### Pick default audio devices
|
|
160
160
|
|
|
161
|
-
Once installed, the `pyquist` CLI lets you choose persistent default input/output devices (handy for laptops with multiple interfaces):
|
|
161
|
+
Once installed, the `pyquist` CLI (also available as `pq`) lets you choose persistent default input/output devices (handy for laptops with multiple interfaces):
|
|
162
162
|
|
|
163
163
|
```sh
|
|
164
164
|
pyquist devices
|
|
165
|
+
pyquist play test
|
|
165
166
|
```
|
|
166
167
|
|
|
167
168
|
### Run notebooks
|
|
@@ -112,10 +112,11 @@ pre-commit install
|
|
|
112
112
|
|
|
113
113
|
### Pick default audio devices
|
|
114
114
|
|
|
115
|
-
Once installed, the `pyquist` CLI lets you choose persistent default input/output devices (handy for laptops with multiple interfaces):
|
|
115
|
+
Once installed, the `pyquist` CLI (also available as `pq`) lets you choose persistent default input/output devices (handy for laptops with multiple interfaces):
|
|
116
116
|
|
|
117
117
|
```sh
|
|
118
118
|
pyquist devices
|
|
119
|
+
pyquist play test
|
|
119
120
|
```
|
|
120
121
|
|
|
121
122
|
### Run notebooks
|
|
@@ -32,7 +32,8 @@ objects::
|
|
|
32
32
|
clip.normalize(peak_dbfs=-1.0)
|
|
33
33
|
clip.write("clip.wav")
|
|
34
34
|
|
|
35
|
-
See :meth:`Audio.zeros` for
|
|
35
|
+
See :meth:`Audio.zeros` for a silent destination buffer (or
|
|
36
|
+
:meth:`Audio.empty` for an uninitialized one) and
|
|
36
37
|
:meth:`Audio.concatenate` to join buffers end to end. To turn musical events
|
|
37
38
|
into ``Audio``, see :mod:`pyquist.score`.
|
|
38
39
|
"""
|
|
@@ -86,16 +87,19 @@ class Audio:
|
|
|
86
87
|
self.sample_rate = sample_rate
|
|
87
88
|
|
|
88
89
|
@classmethod
|
|
89
|
-
def
|
|
90
|
+
def empty(
|
|
90
91
|
cls,
|
|
91
92
|
num_samples: int,
|
|
92
93
|
num_channels: int,
|
|
93
94
|
sample_rate: Optional[int] = None,
|
|
94
95
|
) -> "Audio":
|
|
95
|
-
"""Creates
|
|
96
|
+
"""Creates an uninitialized ``Audio`` of the given shape.
|
|
96
97
|
|
|
97
|
-
|
|
98
|
-
|
|
98
|
+
The samples are whatever happened to be in memory — arbitrary values,
|
|
99
|
+
possibly including ``inf`` and ``nan``. Only use this as a destination
|
|
100
|
+
buffer that you overwrite in full (e.g. by assigning into
|
|
101
|
+
``audio.samples``); if you intend to accumulate into it with in-place
|
|
102
|
+
arithmetic, or to leave any of it untouched, use :meth:`zeros`.
|
|
99
103
|
|
|
100
104
|
Args:
|
|
101
105
|
num_samples: Number of samples per channel. Must be ``>= 0``.
|
|
@@ -108,10 +112,33 @@ class Audio:
|
|
|
108
112
|
if num_channels < 0:
|
|
109
113
|
raise ValueError("num_channels must be non-negative.")
|
|
110
114
|
return cls(
|
|
111
|
-
np.
|
|
115
|
+
np.empty((num_samples, num_channels), dtype=np.float32),
|
|
112
116
|
sample_rate=sample_rate,
|
|
113
117
|
)
|
|
114
118
|
|
|
119
|
+
@classmethod
|
|
120
|
+
def zeros(
|
|
121
|
+
cls,
|
|
122
|
+
num_samples: int,
|
|
123
|
+
num_channels: int,
|
|
124
|
+
sample_rate: Optional[int] = None,
|
|
125
|
+
) -> "Audio":
|
|
126
|
+
"""Creates a silent (zero-filled) ``Audio`` of the given shape.
|
|
127
|
+
|
|
128
|
+
Useful as a destination buffer that you fill in via ``audio.samples``
|
|
129
|
+
or via in-place arithmetic. Same arguments and validation as
|
|
130
|
+
:meth:`empty`, but the samples start at silence.
|
|
131
|
+
|
|
132
|
+
Args:
|
|
133
|
+
num_samples: Number of samples per channel. Must be ``>= 0``.
|
|
134
|
+
num_channels: Number of channels (1 for mono, 2 for stereo).
|
|
135
|
+
Must be ``>= 0``.
|
|
136
|
+
sample_rate: Optional sample rate in Hz.
|
|
137
|
+
"""
|
|
138
|
+
audio = cls.empty(num_samples, num_channels, sample_rate=sample_rate)
|
|
139
|
+
audio.clear()
|
|
140
|
+
return audio
|
|
141
|
+
|
|
115
142
|
@classmethod
|
|
116
143
|
def from_file(cls, file: Union[str, pathlib.Path, IO]) -> "Audio":
|
|
117
144
|
"""Loads an ``Audio`` from a file on disk or a file-like object.
|
|
@@ -68,6 +68,20 @@ class TestAudio(unittest.TestCase):
|
|
|
68
68
|
with self.assertRaises(TypeError):
|
|
69
69
|
Audio(np.zeros((10, 2), dtype=np.float32), sample_rate=44100.0) # type: ignore[arg-type]
|
|
70
70
|
|
|
71
|
+
def test_empty_classmethod(self):
|
|
72
|
+
audio = Audio.empty(10, 2, sample_rate=44100)
|
|
73
|
+
self.assertEqual(audio.shape, (10, 2))
|
|
74
|
+
self.assertEqual(audio.samples.dtype, np.float32)
|
|
75
|
+
self.assertEqual(audio.sample_rate, 44100)
|
|
76
|
+
|
|
77
|
+
audio = Audio.empty(10, 2)
|
|
78
|
+
self.assertIsNone(audio.sample_rate)
|
|
79
|
+
|
|
80
|
+
with self.assertRaises(ValueError):
|
|
81
|
+
Audio.empty(-1, 2)
|
|
82
|
+
with self.assertRaises(ValueError):
|
|
83
|
+
Audio.empty(10, -1)
|
|
84
|
+
|
|
71
85
|
def test_zeros_classmethod(self):
|
|
72
86
|
audio = Audio.zeros(10, 2, sample_rate=44100)
|
|
73
87
|
self.assertEqual(audio.shape, (10, 2))
|
|
@@ -7,6 +7,8 @@ and audio loading lives in :mod:`pyquist.audio` / :mod:`pyquist.web`.
|
|
|
7
7
|
|
|
8
8
|
import argparse
|
|
9
9
|
|
|
10
|
+
import numpy as np
|
|
11
|
+
|
|
10
12
|
from . import __version__
|
|
11
13
|
from .audio import Audio
|
|
12
14
|
from .device import (
|
|
@@ -15,6 +17,7 @@ from .device import (
|
|
|
15
17
|
set_input_device,
|
|
16
18
|
set_output_device,
|
|
17
19
|
)
|
|
20
|
+
from .paths import TEST_SOUND
|
|
18
21
|
from .web.freesound import fetch_freesound
|
|
19
22
|
|
|
20
23
|
|
|
@@ -26,7 +29,14 @@ def _cmd_devices(args: argparse.Namespace) -> None:
|
|
|
26
29
|
|
|
27
30
|
|
|
28
31
|
def _cmd_play(args: argparse.Namespace) -> None:
|
|
29
|
-
|
|
32
|
+
# "test" is a shorthand for the bundled sample, so users can check that
|
|
33
|
+
# audio output works without having an audio file on hand.
|
|
34
|
+
if args.input.strip().lower() == "test":
|
|
35
|
+
audio = Audio.from_file(TEST_SOUND).segment(duration=1.0)
|
|
36
|
+
audio *= np.linspace(1.0, 0.0, audio.num_samples)[:, np.newaxis]
|
|
37
|
+
else:
|
|
38
|
+
audio = Audio.from_file(args.input)
|
|
39
|
+
play(audio)
|
|
30
40
|
|
|
31
41
|
|
|
32
42
|
def _cmd_record(args: argparse.Namespace) -> None:
|
|
@@ -64,7 +74,10 @@ def _build_parser() -> argparse.ArgumentParser:
|
|
|
64
74
|
p_devices.set_defaults(func=_cmd_devices)
|
|
65
75
|
|
|
66
76
|
p_play = subparsers.add_parser("play", help="Play an audio file.")
|
|
67
|
-
p_play.add_argument(
|
|
77
|
+
p_play.add_argument(
|
|
78
|
+
"input",
|
|
79
|
+
help="Path to the audio file, or 'test' for the bundled test sound.",
|
|
80
|
+
)
|
|
68
81
|
p_play.set_defaults(func=_cmd_play)
|
|
69
82
|
|
|
70
83
|
p_record = subparsers.add_parser("record", help="Record audio.")
|
|
@@ -10,9 +10,9 @@ import sys
|
|
|
10
10
|
import time
|
|
11
11
|
from typing import Any, Optional, Tuple, Union
|
|
12
12
|
|
|
13
|
+
import numpy as np
|
|
13
14
|
import sounddevice as sd
|
|
14
15
|
import tqdm
|
|
15
|
-
import numpy as np
|
|
16
16
|
|
|
17
17
|
from .audio import Audio
|
|
18
18
|
from .paths import CACHE_DIR
|
|
@@ -131,7 +131,13 @@ def play(
|
|
|
131
131
|
when called from a notebook. Useful when you want the audio
|
|
132
132
|
played through the OS audio output rather than as an inline
|
|
133
133
|
player widget.
|
|
134
|
+
|
|
135
|
+
Raises:
|
|
136
|
+
ValueError: If ``audio.sample_rate`` is ``None``.
|
|
134
137
|
"""
|
|
138
|
+
if audio.sample_rate is None:
|
|
139
|
+
raise ValueError("sample_rate is None; cannot play audio.")
|
|
140
|
+
|
|
135
141
|
if normalize:
|
|
136
142
|
audio = audio.normalize(in_place=False)
|
|
137
143
|
audio = audio.clip(in_place=False)
|
|
@@ -173,7 +179,7 @@ def record(
|
|
|
173
179
|
# :mod:`sounddevice` is not available when running in browser, handle separately.
|
|
174
180
|
if _in_browser():
|
|
175
181
|
return _record_in_browser(duration)
|
|
176
|
-
|
|
182
|
+
|
|
177
183
|
device_info = sd.query_devices(sd.default.device[0])
|
|
178
184
|
sample_rate = round(device_info["default_samplerate"])
|
|
179
185
|
num_channels = device_info["max_input_channels"]
|
|
@@ -3,10 +3,11 @@ import io
|
|
|
3
3
|
import json
|
|
4
4
|
import tempfile
|
|
5
5
|
import unittest
|
|
6
|
-
import numpy as np
|
|
7
6
|
from pathlib import Path
|
|
8
7
|
from unittest import mock
|
|
9
8
|
|
|
9
|
+
import numpy as np
|
|
10
|
+
|
|
10
11
|
from . import device
|
|
11
12
|
|
|
12
13
|
|
|
@@ -446,6 +447,20 @@ class TestPlayDispatch(unittest.TestCase):
|
|
|
446
447
|
fake_audio_widget.assert_called_once()
|
|
447
448
|
fake_display.assert_called_once()
|
|
448
449
|
|
|
450
|
+
def test_missing_sample_rate_raises(self):
|
|
451
|
+
import numpy as np
|
|
452
|
+
|
|
453
|
+
from .audio import Audio
|
|
454
|
+
|
|
455
|
+
audio = Audio(np.zeros(100, dtype=np.float32)) # no sample_rate
|
|
456
|
+
with (
|
|
457
|
+
mock.patch.object(device, "_in_ipython_notebook", return_value=False),
|
|
458
|
+
mock.patch.object(device.sd, "play") as mock_play,
|
|
459
|
+
):
|
|
460
|
+
with self.assertRaises(ValueError):
|
|
461
|
+
device.play(audio)
|
|
462
|
+
mock_play.assert_not_called()
|
|
463
|
+
|
|
449
464
|
def test_force_sounddevice_overrides_notebook(self):
|
|
450
465
|
audio = self._make_audio()
|
|
451
466
|
with (
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyquist
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.3
|
|
4
4
|
Summary: Barebones utilities for low-level computer music programming in Python and NumPy. Teaching library for CMU 15-322.
|
|
5
5
|
Author: Chris Donahue
|
|
6
6
|
License-Expression: MIT
|
|
@@ -158,10 +158,11 @@ pre-commit install
|
|
|
158
158
|
|
|
159
159
|
### Pick default audio devices
|
|
160
160
|
|
|
161
|
-
Once installed, the `pyquist` CLI lets you choose persistent default input/output devices (handy for laptops with multiple interfaces):
|
|
161
|
+
Once installed, the `pyquist` CLI (also available as `pq`) lets you choose persistent default input/output devices (handy for laptops with multiple interfaces):
|
|
162
162
|
|
|
163
163
|
```sh
|
|
164
164
|
pyquist devices
|
|
165
|
+
pyquist play test
|
|
165
166
|
```
|
|
166
167
|
|
|
167
168
|
### Run notebooks
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pyquist-0.2.1 → pyquist-0.2.3}/pyquist/test_data/388954__fullmetaljedi__blues-riff-in-g-nylon.wav
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|