/// <summary> /// Zwaraca liste wsp. mfcc dla kolejnych ramek sgnalu mowy /// </summary> /// <param name="wave"></param> /// <returns></returns> private List<double[]> GetMfccsHelper(LightWaveFileReader wave) { if (wave.Frequency != FREQUENCY) throw new ArgumentException("Only 44100Hz waves are supported"); const int WIN_DELTA = WINDOW_SIZE - OVERLAP; var results = new List<double[]>(); var windowData = new double[WINDOW_SIZE]; for (int windowBegining = 0; windowBegining < wave.SamplesCount - WINDOW_SIZE; windowBegining += WIN_DELTA) { CopyWindowData(wave, windowData, windowBegining); double power = windowData.Sum(x => Math.Abs(x)) / WINDOW_SIZE; if (power > SPEAK_POWER_THRESHOLD) { var mfcc = MFCCCoefficients.GetMFCC(FREQUENCY, windowData, filters, algorithmParams.MfccCount); results.Add(mfcc); } } if (results.Count < algorithmParams.SignalFramesCount) { throw new ArgumentException("Too little usable voice samples found in wave file"); } Debug.WriteLine("Z pliku wyodrebiono {0} ramek", results.Count); return results; }
private List<double[]> GetMfccsFromFile(string path) { LightWaveFileReader wave = null; try { wave = new LightWaveFileReader(path); } catch (ThreadAbortException) { throw; } catch (Exception ex) { throw new WaveFileException(path, ex.Message, ex); } return GetMfccsHelper(wave); }
private List<double[]> GetMfccsFromStream(Stream stream) { var wave = new LightWaveFileReader(stream); return GetMfccsHelper(wave); }
private void CopyWindowData(LightWaveFileReader wave, double[] windowData, int windowBegining) { Debug.Assert(windowData.Length == WINDOW_SIZE); for (int i = 0; i < WINDOW_SIZE; i++) { windowData[i] = wave.SoundSamples[windowBegining + i]; } }