/// <summary> /// DoSnr = true; /// DoFullBandwidth = false; /// </summary> /// <param name="config">read from file</param> private void Initialize(ConfigDictionary config) { if (config == null) { throw new ArgumentNullException(nameof(config)); } this.CallName = config.GetString(ConfigKeys.Recording.Key_RecordingCallName); this.SourceFName = config.GetString(ConfigKeys.Recording.Key_RecordingFileName); var duration = config.GetDoubleNullable("WAV_DURATION"); if (duration != null) { this.Duration = TimeSpan.FromSeconds(duration.Value); } //FRAMING PARAMETERS this.WindowSize = config.GetInt(ConfigKeys.Windowing.Key_WindowSize); this.WindowOverlap = config.GetDouble(ConfigKeys.Windowing.Key_WindowOverlap); //NOISE REDUCTION PARAMETERS this.DoSnr = true; // set false if only want to string noisereduce = config.GetString(AnalysisKeys.NoiseReductionType); //this.NoiseReductionType = (NoiseReductionType)Enum.Parse(typeof(NoiseReductionType), noisereduce.ToUpperInvariant()); this.NoiseReductionType = (NoiseReductionType)Enum.Parse(typeof(NoiseReductionType), noisereduce); //FREQ BAND PARAMETERS this.DoFullBandwidth = false; // set true if only want to this.MinFreqBand = config.GetIntNullable(ConfigKeys.Mfcc.Key_MinFreq); this.MaxFreqBand = config.GetIntNullable(ConfigKeys.Mfcc.Key_MaxFreq); this.MidFreqBand = this.MinFreqBand + ((this.MaxFreqBand - this.MinFreqBand) / 2); //SEGMENTATION PARAMETERS EndpointDetectionConfiguration.SetConfig(config); //MFCC PARAMETERS this.DoMelScale = config.GetBoolean(ConfigKeys.Mfcc.Key_DoMelScale); this.mfccConfig = new MfccConfiguration(config); this.DeltaT = config.GetInt(ConfigKeys.Mfcc.Key_DeltaT); // Frames between acoustic vectors // for generating only spectrogram. }
/// <summary> /// /// </summary> /// <param name="fiAudio"></param> /// <param name="fiConfig"></param> /// <param name="fiImage"></param> /// <returns></returns> public static Image GetImageFromAudioSegment(FileInfo fiAudio, FileInfo fiConfig, FileInfo fiImage, IAnalyser2 analyser) { var config = new ConfigDictionary(fiConfig.FullName); //read in config file bool doAnnotate = config.GetBoolean(AnalysisKeys.AnnotateSonogram); //bool doNoiseReduction = config.GetBoolean(Keys.NOISE_DO_REDUCTION); //double bgNoiseThreshold = config.GetDouble(Keys.NOISE_BG_REDUCTION); var diOutputDir = new DirectoryInfo(Path.GetDirectoryName(fiImage.FullName)); //Image image = null; if (doAnnotate) { if (analyser == null) { string analyisName = config.GetString(AnalysisKeys.AnalysisName); LoggedConsole.WriteLine("\nWARNING: Could not construct annotated image because analysis name not recognized:"); LoggedConsole.WriteLine("\t " + analyisName); return(null); } throw new NotSupportedException("Code intentionally broken because it is out of date and not used"); /* * Image image = null; * var settings = new AnalysisSettings * { * ConfigDict = config.GetDictionary(), * SegmentAudioFile = fiAudio, * ConfigFile = fiConfig, * SegmentImageFile = fiImage, * SegmentOutputDirectory = diOutputDir * }; * * // want to pass SampleRate of the original file. * settings.SampleRateOfOriginalAudioFile = int.Parse(settings.ConfigDict[AnalysisKeys.ResampleRate]); * * analyser.BeforeAnalyze(settings); * * var results = analyser.Analyze(settings, new SegmentSettings<FileInfo>(se)); * * image = results.ImageFile == null ? null : Image.FromFile(results.ImageFile.FullName); * * analyser = null; * return image;*/ } else { analyser = null; var configDict = config.GetDictionary(); BaseSonogram sonogram = Audio2DecibelSonogram(fiAudio, configDict); var mti = Sonogram2MultiTrackImage(sonogram, configDict); var image = mti.GetImage(); if (image != null) { if (fiImage.Exists) { fiImage.Delete(); } image.Save(fiImage.FullName, ImageFormat.Png); } return(image); } }