Conv-STFT/iSTFT in PyTorch
Author: Shimin Zhang
The code refers to the following repo:
An STFT/iSTFT written up in PyTorch(py3) using 1D Convolutions. There are two window logic, break and continue.
break- a kaldi-like framing method
When the parameters win_len and fft_len are different, padding fft_len-win_len zero points after each frame( len(frame) = win_len ), and the window ( len(window) = win_len ) always wise-multiply with frame before padding.
continue- a librosa-like framing method.
When the parameters win_len and fft_len are different, framing the signal using win_len=fft_len, and zero padding on both sides of window ( len(window) = win_len ), which is len(center_pad(window))=fft_len
Installation
Install easily with pip:pip install conv_stft or download this repo, python setup.py install.
Usage
import torch
from conv_stft import STFT
import numpy as np
import librosa
import matplotlib.pyplot as plt
audio = librosa.load(librosa.util.example_audio_file(), duration=10.0, offset=30)[0]
device = 'cpu'
fft_len = 1024
win_hop = 256
win_len = 1024
window = 'hann'
audio = torch.FloatTensor(audio)
audio = audio.unsqueeze(0)
audio = audio.to(device)
stft = STFT(
fft_len=fft_len,
win_hop=win_hop,
win_len=win_len,
win_type=window,
).to(device)
magnitude, phase = stft.transform(audio, return_type='magphase') # 'magphase' or 'realimag'
output = stft.inverse(magnitude, phase, input_type='magphase') # 'magphase' or 'realimag'
output = output.cpu().data.numpy()[..., :]
audio = audio.cpu().data.numpy()[..., :]
print(np.mean((output - audio) ** 2)) # on order of 1e-15
Output of compare_stft.py:
Tests
Test it by just cloning this repo and running
pip install -r requirements.txt
python -m pytest .
Metadata
Release files for conv-stft 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| conv_stft-0.2.0-py3.6.egg | Legacy Egg format | - | - | Details for conv_stft-0.2.0-py3.6.egg |
Release files / conv_stft-0.2.0-py3.6.egg
| Download URL | conv_stft-0.2.0-py3.6.egg |
|---|---|
| Size | 8.4 kB |
| Tags | Egg |
|
SHA-256 checksum How to use checksums |
f5599f703149581d4b169025f5a9db9b2501d741ac3d75a0068181a24e242865
|
|
BLAKE2b-256 checksum How to use checksums |
8a674cf0e02ac64c5916ecc10a6d2f8f00ac622cfac392a6522624e92e90a7d1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.5.0 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.6.10
|
Security for conv-stft 0.2.0
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.