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.
}
}