/// <summary> /// Segment a <paramref name="source"/> audio file. /// <paramref name="output"/> file will be created. /// </summary> /// <param name="source"> /// The <paramref name="source"/> audio file. /// </param> /// <param name="sourceMediaType"> /// The <paramref name="source"/> Mime Type. /// </param> /// <param name="output"> /// The <paramref name="output"/> audio file. Ensure the file does not exist. /// </param> /// <param name="outputMediaType"> /// The <paramref name="output"/> Mime Type. /// </param> /// <param name="request"> /// The segment <paramref name="request"/>. /// </param> public virtual void Modify(FileInfo source, string sourceMediaType, FileInfo output, string outputMediaType, AudioUtilityRequest request) { this.CheckFile(source); sourceMediaType = MediaTypes.CanonicaliseMediaType(sourceMediaType); outputMediaType = MediaTypes.CanonicaliseMediaType(outputMediaType); this.ValidateMimeTypeExtension(source, sourceMediaType, output, outputMediaType); this.CanProcess(source, this.ValidSourceMediaTypes, this.InvalidSourceMediaTypes); this.CanProcess(output, this.ValidOutputMediaTypes, this.InvalidOutputMediaTypes); request.ValidateChecked(); this.CheckRequestValid(source, sourceMediaType, output, outputMediaType, request); this.CheckRequestValidForMediaType(output, outputMediaType, request); using (var process = new ProcessRunner(this.ExecutableModify.FullName)) { string args = this.ConstructModifyArgs(source, output, request); this.RunExe(process, args, output.DirectoryName); } if (this.Log.IsDebugEnabled) { this.Log.Trace("Source " + this.BuildFileDebuggingOutput(source)); this.Log.Trace("Output " + this.BuildFileDebuggingOutput(output)); } this.CheckFile(output); }
/// <summary> /// The check request valid for output. /// </summary> /// <param name="output"> /// The output. /// </param> /// <param name="outputMediaType"> /// The output media type. /// </param> /// <param name="request"> /// The request. /// </param> protected void CheckRequestValidForMediaType(FileInfo output, string outputMediaType, AudioUtilityRequest request) { var mediaType = MediaTypes.CanonicaliseMediaType(outputMediaType); if (mediaType == MediaTypes.MediaTypeMp3) { if (request.TargetSampleRate.HasValue) { this.CheckMp3SampleRate(request.TargetSampleRate.Value); } } }
/// <summary> /// Get a string representation of this audio reading request. /// </summary> /// <returns> /// String representation. /// </returns> public override string ToString() { var duration = (this.End - this.Start).Duration(); var segment = $"Request starts at {this.Start.Humanise()} ({this.Start.TotalMilliseconds}ms) and finishes at {this.End.Humanise()} ({this.End.TotalMilliseconds}ms) ({duration.Humanise()} - {duration.TotalMilliseconds}ms)."; var mediaType = string.IsNullOrWhiteSpace(this.MediaType) ? string.Empty : " Media type of " + MediaTypes.CanonicaliseMediaType(this.MediaType) + "."; var channels = this.Channels.HasValue ? " " + this.Channels.Value + " channel(s)." : string.Empty; var sampleRate = this.SampleRate.HasValue ? " Sample rate of " + this.SampleRate.Value + " hertz." : string.Empty; return(segment + mediaType + channels + sampleRate); }