赞
踩
目录
C# Mel-Spectrogram 梅尔频谱
利用NWaves实现Mel-Spectrogram 梅尔频谱
NWaves github 地址:https://github.com/ar1st0crat/NWaves
NWaves is a .NET DSP library with a lot of audio processing functions.
NWaves was initially intended for research, visualizing and teaching basics of DSP and sound programming.
Usually, DSP code is quite complicated and difficult to read, because it's full of optimizations (which is actually a very good thing). NWaves project aims in particular at achieving a tradeoff between good understandable code/design and satisfactory performance. Yet, the main purpose of this lib is to offer the DSP codebase that would be:
using NWaves.Audio;
using NWaves.FeatureExtractors;
using NWaves.FeatureExtractors.Options;
using NWaves.Filters.Fda;
using NWaves.Signals;
using NWaves.Windows;
using System;
using System.IO;
using System.Text;
using System.Windows.Forms;
namespace C__Mel_Spectrogram_梅尔频谱
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
WaveFile waveContainer;
StringBuilder sb = new StringBuilder();
private void button1_Click(object sender, EventArgs e)
{
using (var stream = new FileStream("你好.wav", FileMode.Open))
{
waveContainer = new WaveFile(stream);
}
DiscreteSignal left = waveContainer[Channels.Left];
//DiscreteSignal right = waveContainer[Channels.Right];
//Mel-Spectrogram
var fftSize = 1024;
var hopSize = 512;
var melCount = 16;
int samplingRate = left.SamplingRate;
var mfccExtractor = new FilterbankExtractor(
new FilterbankOptions
{
SamplingRate = samplingRate,
FrameSize = fftSize,
FftSize = fftSize,
HopSize = hopSize,
Window = WindowType.Hann,
FilterBank = FilterBanks.Triangular(fftSize, samplingRate, FilterBanks.MelBands(melCount, samplingRate)),
// if power = 1.0
// SpectrumType = SpectrumType.Magnitude
});
var mfccVectors = mfccExtractor.ParallelComputeFrom(left);
sb.Clear();
foreach (var item in mfccVectors)
{
sb.AppendLine(String.Join(",", item));
}
textBox1.Text = sb.ToString();
}
}
}
- using NWaves.Audio;
- using NWaves.FeatureExtractors;
- using NWaves.FeatureExtractors.Options;
- using NWaves.Filters.Fda;
- using NWaves.Signals;
- using NWaves.Windows;
- using System;
- using System.IO;
- using System.Text;
- using System.Windows.Forms;
-
- namespace C__Mel_Spectrogram_梅尔频谱
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
-
- WaveFile waveContainer;
- StringBuilder sb = new StringBuilder();
-
- private void button1_Click(object sender, EventArgs e)
- {
- using (var stream = new FileStream("你好.wav", FileMode.Open))
- {
- waveContainer = new WaveFile(stream);
- }
-
- DiscreteSignal left = waveContainer[Channels.Left];
- //DiscreteSignal right = waveContainer[Channels.Right];
-
- //Mel-Spectrogram
- var fftSize = 1024;
- var hopSize = 512;
- var melCount = 16;
- int samplingRate = left.SamplingRate;
-
- var mfccExtractor = new FilterbankExtractor(
- new FilterbankOptions
- {
- SamplingRate = samplingRate,
- FrameSize = fftSize,
- FftSize = fftSize,
- HopSize = hopSize,
- Window = WindowType.Hann,
- FilterBank = FilterBanks.Triangular(fftSize, samplingRate, FilterBanks.MelBands(melCount, samplingRate)),
- // if power = 1.0
- // SpectrumType = SpectrumType.Magnitude
- });
-
-
- var mfccVectors = mfccExtractor.ParallelComputeFrom(left);
-
- sb.Clear();
-
- foreach (var item in mfccVectors)
- {
- sb.AppendLine(String.Join(",", item));
- }
-
- textBox1.Text = sb.ToString();
- }
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。