Pythorch的STFT/ISTFT

torch-stft的Python项目详细描述


Build Status

pytorch中的stft/istft

用一维卷积用pytorch写成的stft/istft。要求是最新版本的pytorch、numpy和librosa(用于在test_stft.py中加载音频)。感谢shrikant venkataramani共享代码,这是基于和rafael valle捕获错误和添加适当的窗口逻辑。使用Python3。

安装

使用pip轻松安装:

pip install torch_stft

用法

import torch
from torch_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'
filter_length = 1024
hop_length = 256
win_length = 1024 # doesn't need to be specified. if not specified, it's the same as filter_length
window = 'hann'

audio = torch.FloatTensor(audio)
audio = audio.unsqueeze(0)
audio = audio.to(device)

stft = STFT(
    filter_length=filter_length, 
    hop_length=hop_length, 
    win_length=win_length,
    window=window
).to(device)

magnitude, phase = stft.transform(audio)
output = stft.inverse(magnitude, phase)
output = output.cpu().data.numpy()[..., :]
audio = audio.cpu().data.numpy()[..., :]
print(np.mean((output - audio) ** 2)) # on order of 1e-16

输出^{}

images/stft.png

测试

只需克隆此repo并运行

pip install -r requirements.txt
python -m pytest .

不幸的是,由于它是用一维卷积实现的,所以有些滤波器的长度/跳长 当在足够大的输入上运行时,组合可能会导致GPU内存不足错误。

贡献

欢迎拉取请求。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java我可以使用Hibernate连接不同的数据库并从表中导入数据吗?没有预定义的对象类   java为什么getBoundsInLocal获取错误的坐标?   java在处理并发哈希映射时必须使用锁   java将过滤的JTable数据导出到文本文件   从命令行编译java不使用库   Java使用方法和构造函数绘制图形   java理解优先级队列中的排序方法   尝试解密文件时,java CipherInputStream为空   在Java中将字符串解析为长字符串   java我想在raspberry pi重新启动时在crontabe中执行arecord命令   弹性搜索弹性搜索Lucene公式的Java计算   java使用apachepoi和docx4j读取doc文件   swing显示JavaGUI是否需要特殊处理?   java使用字符串进行数学运算   java在SpringMVC中用JSP初始化菜单项选择表单数据的最佳方法   无多线程的java多客户端程序   swing如何在Java中对BuffereImage进行去饱和?   java在安卓中创建自定义地图