Beispiel #1
0
 public void Stop()
 {
     if (mSaveAudio)
     {
         wav_out.Close();
         wav_out = null;
     }
     mRunning = false;
     mRunningEvent.Reset();
 }
Beispiel #2
0
 public void Start()
 {
     if(mSaveAudio){
         string path2 = @"C:\Users\ian\Desktop\audio\client-" + DateTime.Now.ToString("HHmmssff") + ".wav";
         wav_out = new WavUtils(16, path2);
     }
     mRunningEvent.Set();
     mRunning = true;
     if(!mThread.IsAlive) mThread.Start();
 }
        //public const double CutSecondsBefore = 0.1;
        //public const double CutSecondsAfter = 0.1;

        // TODO: introduce a pause between phrases for watermark
        public static void SaveMusicMp3ToSegmentedFile(string filename, XmlAudiobook meta)
        {
            // save mp3
            var result = new WavComposite(filename);

            foreach (var seg in meta.Segments)
            {
                var segFilename = UtilsCore.GetFullPathWithoutExtension(filename) + "/" + seg.Filename;
                var lengthSec   = ((double)WavUtils.TotalLengthMillis(segFilename)) / 1000;
                result.WritePieceOfSomeFileWav(
                    segFilename,
                    Settings.Default.CutSecondsBefore,
                    lengthSec - Settings.Default.CutSecondsAfter);
            }
            result.Close();
        }
Beispiel #4
0
        private void readCurLang1Phrase()
        {
            if (Lang1CurSegment == null)
            {
                return;
            }
            var fname = Lang1CurSegment.Filename;

            if (fname == null)
            {
                return;
            }
            if (Lang1CurSegment.Type == WavEventType.WavRecording1)
            {
                WavUtils.PlayAllOfFile(AudioBooker.classes.UtilsCore.GetFullPathWithoutExtension(Lang1Mp3) + "/" + fname);
            }
            else
            {
                Mp3Utils.PlayPieceOfAFile(
                    Lang1Mp3,
                    Lang1CurSegment.TimeIn.TotalSeconds,
                    Lang1CurSegment.TimeOut.TotalSeconds);
            }
        }
Beispiel #5
0
        public void IsAdpcm(string path, bool expectedResult)
        {
            bool actualResult = WavUtils.IsAdpcm(path);

            Assert.AreEqual(expectedResult, actualResult);
        }
Beispiel #6
0
        public void Run()
        {
            var logger = new Logger(_options);

            Convert(_options.InputPath);
            logger.Dump();

            void Convert(string folder)
            {
                string folderName = Path.GetFileName(folder);

                if (folderName.Equals(_options.BackupFolderName, StringComparison.OrdinalIgnoreCase))
                {
                    return;
                }

                foreach (string wavPath in Directory.EnumerateFiles(folder, "*.wav"))
                {
                    logger.Start("Converting", wavPath);

                    if (_options.AdpcmOnly && !WavUtils.IsAdpcm(wavPath))
                    {
                        logger.Skip("Not ADPCM encoded.");
                        continue;
                    }

                    string oggPath = Path.ChangeExtension(wavPath, ".ogg");
                    if (File.Exists(oggPath) && !_options.AllowOverwrite)
                    {
                        logger.Skip(".ogg already exists.");
                        continue;
                    }

                    Process ffmpeg = Process.Start(new ProcessStartInfo
                    {
                        FileName               = _options.FfmpegPath,
                        Arguments              = $"-i \"{wavPath}\" -codec:a libvorbis -q:a {_options.Quality} -y \"{oggPath}\"",
                        UseShellExecute        = false,
                        RedirectStandardError  = true,
                        RedirectStandardOutput = true
                    });

                    string ffmpegOutput = ffmpeg.StandardError.ReadToEnd();
                    ffmpeg.WaitForExit();

                    if (ffmpeg.ExitCode != 0)
                    {
                        logger.Fail($"Unexpected ffmpeg output: {ffmpegOutput}");
                        continue;
                    }

                    if (!_options.DoNotBackup)
                    {
                        string backupFolderPath = Path.Combine(folder, _options.BackupFolderName);
                        Directory.CreateDirectory(backupFolderPath);

                        string wavName       = Path.GetFileName(wavPath);
                        string wavBackupPath = Path.Combine(backupFolderPath, wavName);
                        File.Move(wavPath, wavBackupPath);
                    }

                    logger.Success();
                }

                if (_options.AllowRecursion)
                {
                    foreach (string subfolder in Directory.EnumerateDirectories(folder))
                    {
                        Convert(subfolder);
                    }
                }
            }
        }