Bloom.Edit.LameEncoder.Encode C# (CSharp) Method

Encode() public method

public Encode ( string sourcePath, string destPathWithoutExtension, IProgress progress ) : void
sourcePath string
destPathWithoutExtension string
progress IProgress
return void
        public void Encode(string sourcePath, string destPathWithoutExtension, IProgress progress)
        {
            LocateAndRememberLAMEPath();

            if (RobustFile.Exists(destPathWithoutExtension + ".mp3"))
                RobustFile.Delete(destPathWithoutExtension + ".mp3");

            progress.WriteMessage(LocalizationManager.GetString("LameEncoder.Progress", " Converting to mp3", "Appears in progress indicator"));

            //-a downmix to mono
            string arguments = string.Format("-a \"{0}\" \"{1}.mp3\"", sourcePath, destPathWithoutExtension);
            //ClipRepository.RunCommandLine(progress, _pathToLAME, arguments);
            ExecutionResult result = CommandLineRunner.Run(_pathToLAME, arguments, null, 60, progress);
            result.RaiseExceptionIfFailed("");
        }

Usage Example

        private void Recorder_Stopped(IAudioRecorder arg1, ErrorEventArgs arg2)
        {
            Recorder.Stopped -= Recorder_Stopped;
            Directory.CreateDirectory(System.IO.Path.GetDirectoryName(PathToCurrentAudioSegment));             // make sure audio directory exists
            int millisecondsToTrimFromEndForMouseClick = 100;

            try
            {
                var minimum = TimeSpan.FromMilliseconds(300);           // this is arbitrary
                AudioRecorder.TrimWavFile(PathToTemporaryWav, PathToCurrentAudioSegment, new TimeSpan(), TimeSpan.FromMilliseconds(millisecondsToTrimFromEndForMouseClick), minimum);
                RobustFile.Delete(PathToTemporaryWav);                  // Otherwise, these continue to clutter up the temp directory.
            }
            catch (Exception error)
            {
                Logger.WriteEvent(error.Message);
                RobustFile.Copy(PathToTemporaryWav, PathToCurrentAudioSegment, true);
            }

            //We don't actually need the mp3 now, so let people play with recording even without LAME (previously it could crash BL-3159).
            //We could put this off entirely until we make the ePUB.
            //I'm just gating this for now because maybe the thought was that it's better to do it a little at a time?
            //That's fine so long as it doesn't make the UI unresponsive on slow machines.
            if (LameEncoder.IsAvailable())
            {
                _mp3Encoder.Encode(PathToCurrentAudioSegment, PathToCurrentAudioSegment.Substring(0, PathToCurrentAudioSegment.Length - 4), new NullProgress());
                // Note: we need to keep the .wav file as well as the mp3 one. The mp3 format (or alternative mp4)
                // is required for ePUB. The wav file is a better permanent record of the recording; also,
                // it is used for playback.
            }
        }
All Usage Examples Of Bloom.Edit.LameEncoder::Encode