Package: torch-yin
Torch-YinThis package implements the Yin pitch estimation algorithm described byA De Cheveigné, et alfor thePyTorchdeep learning framework. It is based
on the excellent NumPy implementation byPatrice Guyot, which has been extended
for full vectorization and to support batched computation.StatusInstall with pippipinstalltorch-yinUsageHere we estimate the fundamental frequency of a simple 1 second sinusoid at
440Hz:importtorchimporttorchyinFS=48000y=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].importtorchimporttorchyinFS=48000f=2**((torch.arange(88)-48)/12)*440t=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
outthis blog post, see themodule documentation,
or runhelp(torchyin).DevelopmentSetupThe following script creates a virtual environment usingpyenvfor the project and installs
dependencies.pyenvinstall3.9.10
pyenvvirtualenv3.9.10torch-yin
pipinstall-rrequirements.txtYou can then run tests, etc. follows:pytest--cov=torchyin
black.
flake8.
mypytorchyinThese can also be used with thepre-commiitlibrary to run all checks at commit time.DeploymentThe project uses setup.py for installation and is deployed toPyPI. The source distribution can be
built for deployment with the following command:pythonsetup.pyclean--all
rm-r./dist
pythonsetup.pysdistThe distribution can then be uploaded to PyPI using twine.twineupload--repository-url=https://upload.pypi.org/legacy/dist/*For deployment testing, the following command can be used to upload to the
PyPI test repository:twineupload--repository-url=https://test.pypi.org/legacy/dist/*LicenseCopyright © 2022 Brent M. SpellLicensed 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 athttps://opensource.org/licenses/MITUnless 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.