Torch-Yin
This package implements the Yin pitch estimation algorithm described by A De Cheveigné, et al for the PyTorch deep learning framework. It is based on the excellent NumPy implementation by Patrice Guyot, which has been extended for full vectorization and to support batched computation.
Status
Install with pip
pip install torch-yin
Usage
Here we estimate the fundamental frequency of a simple 1 second sinusoid at 440Hz:
import torch
import torchyin
FS = 48000
y = torch.sin(2 * torch.pi * 440 / FS * torch.arange(FS))
pitch = torchyin.estimate(y, sample_rate=FS)
pitch[0]
tensor(440.3669)
Pitch can also be calculated for batches of signals, shaped [batch, samples].
In this example, we create a batch of signals for the 88 standard piano keys
using broadcasting, shaped [88, 48000].
import torch
import torchyin
FS = 48000
f = 2 ** ((torch.arange(88) - 48) / 12) * 440
t = torch.arange(FS)
y = torch.sin(2 * torch.pi * f.unsqueeze(1) / FS * t.unsqueeze(0))
pitch = torchyin.estimate(
y,
sample_rate=FS,
pitch_min=20,
pitch_max=5000,
)
pitch[:, 0]
tensor([ 27.5072, 29.1439, 30.8682, 32.6975, 34.6570, 36.6973,
38.8979, 41.2017, 43.6364, 46.2428, 48.9796, 51.8919,
54.9828, 58.2524, 61.6967, 65.3951, 69.2641, 73.3945,
77.7958, 82.4742, 87.2727, 92.4855, 97.9592, 103.8961,
110.0917, 116.5049, 123.3933, 130.7902, 138.7283, 146.7890,
155.3398, 164.9485, 174.5455, 185.3282, 195.9184, 207.7922,
220.1835, 233.0097, 247.4227, 262.2951, 277.4566, 294.4785,
311.6883, 328.7671, 350.3650, 369.2308, 393.4426, 413.7931,
440.3669, 466.0194, 494.8453, 521.7391, 551.7241, 585.3658,
623.3766, 657.5342, 695.6522, 738.4615, 786.8852, 827.5862,
872.7272, 941.1765, 979.5918, 1043.4783, 1116.2791, 1170.7317,
1230.7693, 1333.3334, 1411.7648, 1500.0000, 1548.3871, 1655.1724,
1777.7778, 1846.1539, 2000.0000, 2086.9565, 2181.8184, 2400.0000,
2526.3159, 2666.6667, 2823.5295, 3000.0000, 3200.0002, 3428.5715,
3428.5715, 3692.3079, 4000.0000, 4363.6367])
For more information and detailed parameter descriptions, please check
out this blog post, see the
module documentation,
or run help(torchyin).
Development
Setup
The following script creates a virtual environment using pyenv for the project and installs dependencies.
pyenv install 3.9.10
pyenv virtualenv 3.9.10 torch-yin
pip install -r requirements.txt
You can then run tests, etc. follows:
pytest --cov=torchyin
black .
flake8 .
mypy torchyin
These can also be used with the pre-commiit library to run all checks at commit time.
Deployment
The project uses setup.py for installation and is deployed to PyPI. The source distribution can be built for deployment with the following command:
python setup.py clean --all
rm -r ./dist
python setup.py sdist
The distribution can then be uploaded to PyPI using twine.
twine upload --repository-url=https://upload.pypi.org/legacy/ dist/*
For deployment testing, the following command can be used to upload to the PyPI test repository:
twine upload --repository-url=https://test.pypi.org/legacy/ dist/*
License
Copyright © 2022 Brent M. Spell
Licensed under the MIT License (the "License"). You may not use this package except in compliance with the License. You may obtain a copy of the License at
https://opensource.org/licenses/MIT
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Metadata
Release files for torch-yin 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| torch-yin-0.1.3.tar.gz | 6.0 kB | Without provenance | Details for torch-yin-0.1.3.tar.gz |
Release files / torch-yin-0.1.3.tar.gz
| Download URL | torch-yin-0.1.3.tar.gz |
|---|---|
| Size | 6.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9e76caba01b73dfb18dc28d592bf5cc2d0d0641aa8184e53b9bf92ad5dd65776
|
|
BLAKE2b-256 checksum How to use checksums |
ca195356025dc0c6425e3881d1a9e6cb41590bf5908611f741dce2873b26a4bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10
|
Security for torch-yin 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.