public static void SaveAndViewSpectrogramImage(Image image, string opDir, string fName, string imageViewer) { string imagePath = Path.Combine(opDir, fName); image.Save(imagePath, ImageFormat.Png); var fiImage = new FileInfo(imagePath); if (fiImage.Exists) { LoggedConsole.WriteError("Showing image is no longer supported"); } }
public static T FindAndCheckAnalyser <T>(string analysisIdentifier, string partialIdentifier) where T : class, IAnalyser2 { string searchName; if (analysisIdentifier.IsNotWhitespace()) { searchName = analysisIdentifier; Log.Debug($"Searching for exact analysis identifier name {searchName} (from a CLI option)"); } else { // split name (e.g. "Towsey.Acoustics.Zooming.yml") on periods var fragments = partialIdentifier.Split(new[] { "." }, StringSplitOptions.RemoveEmptyEntries); Contract.Requires <CommandLineArgumentException>( fragments.Length >= 2, $"We need at least two segments to search for an analyzer, supplied name `{partialIdentifier}` is insufficient."); // assume indentifier (e.g. "Towsey.Acoustic") in first two segments searchName = fragments[0] + "." + fragments[1]; Log.Debug($"Searching for partial analysis identifier name. `{searchName}` extracted from `{partialIdentifier}`"); } var analysers = AnalysisCoordinator.GetAnalyzers <T>(typeof(MainEntry).Assembly).ToList(); T analyser = analysers.FirstOrDefault(a => a.Identifier == searchName); if (analyser == null) { var error = $"We can not determine what analysis you want to run. We tried to search for \"{searchName}\""; LoggedConsole.WriteError(error); var knownAnalyzers = analysers.Aggregate(string.Empty, (a, i) => a + $" {i.Identifier}\n"); LoggedConsole.WriteLine("Available analysers are:\n" + knownAnalyzers); throw new ValidationException($"Cannot find an IAnalyser2 with the name `{searchName}`"); } Log.Info($"Using analyzer {analyser.Identifier}"); return(analyser); }
private static async Task <double> CreateSegment( ISourcePreparer sourcePreparer, ISegment <FileInfo> fileSegment, AnalysisSettings settings, Arguments arguments, int itemNumber, int itemCount, bool mixDownToMono) { var timer = Stopwatch.StartNew(); FileSegment preparedFile; try { preparedFile = await sourcePreparer.PrepareFile( arguments.OutputDir.ToDirectoryInfo(), fileSegment, settings.SegmentMediaType, settings.AnalysisTargetSampleRate, settings.AnalysisTempDirectory, null, mixDownToMono); } catch (IOException ioex) { LoggedConsole.WriteError($"Failed to cut segment {itemNumber} of {itemCount}:" + ioex.Message); return(double.NaN); } LoggedConsole.WriteLine( "Created segment {0} of {1}: {2}", itemNumber, itemCount, preparedFile.SourceMetadata.Identifier); return(timer.Elapsed.TotalSeconds); }