Пример #1
0
        public void EndLogging()
        {
            if ((m_fOwner != null) && (m_fOwner is MainForm))
            {
                TaskbarList.SetProgressState(m_fOwner, TbpFlag.NoProgress);
            }

            m_bCanClose = true;
        }
Пример #2
0
        public void StartLogging(string strOperation, bool bWriteOperationToLog)
        {
            SetProgressGlobal(strOperation, -1);
            m_bCanClose = false;

            if ((m_fOwner != null) && (m_fOwner is MainForm))
            {
                TaskbarList.SetProgressState(m_fOwner, TbpFlag.Indeterminate);
            }
        }
Пример #3
0
        private void GenerateBatch()
        {
            groupBoxInputFiles.Enabled = false;
            _batchFileNumber           = 0;
            textBoxLog.AppendText("Batch mode" + Environment.NewLine);
            foreach (ListViewItem lvi in listViewInputFiles.Items)
            {
                _batchFileNumber++;
                var videoFileName = lvi.Text;
                listViewInputFiles.SelectedIndices.Clear();
                lvi.Selected         = true;
                progressBar1.Maximum = 100;
                progressBar1.Value   = 0;
                progressBar1.Visible = true;
                var modelFileName = Path.Combine(_voskFolder, comboBoxModels.Text);
                buttonGenerate.Enabled  = false;
                buttonDownload.Enabled  = false;
                buttonBatchMode.Enabled = false;
                var waveFileName = GenerateWavFile(videoFileName, 0);
                textBoxLog.AppendText("Wav file name: " + waveFileName + Environment.NewLine);
                progressBar1.Style = ProgressBarStyle.Blocks;
                var transcript = TranscribeViaVosk(waveFileName, modelFileName);
                if (_cancel)
                {
                    TaskbarList.SetProgressState(_parentForm.Handle, TaskbarButtonProgressFlags.NoProgress);
                    if (!_batchMode)
                    {
                        DialogResult = DialogResult.Cancel;
                    }

                    groupBoxInputFiles.Enabled = true;
                    return;
                }

                var postProcessor = new AudioToTextPostProcessor(GetLanguage(comboBoxModels.Text))
                {
                    ParagraphMaxChars = Configuration.Settings.General.SubtitleLineMaximumLength * 2,
                };
                TranscribedSubtitle = postProcessor.Generate(transcript, checkBoxUsePostProcessing.Checked, true, true, true, true);

                SaveToSourceFolder(videoFileName);
                TaskbarList.SetProgressValue(_parentForm.Handle, _batchFileNumber, listViewInputFiles.Items.Count);
            }

            progressBar1.Visible = false;
            labelTime.Text       = string.Empty;

            TaskbarList.StartBlink(_parentForm, 10, 1, 2);
            MessageBox.Show(string.Format(LanguageSettings.Current.AudioToText.XFilesSavedToVideoSourceFolder, listViewInputFiles.Items.Count));
            groupBoxInputFiles.Enabled = true;
            buttonGenerate.Enabled     = true;
            buttonDownload.Enabled     = true;
            buttonBatchMode.Enabled    = true;
            DialogResult = DialogResult.Cancel;
        }
Пример #4
0
        public static void HideTaskbarProgress()
        {
            if (disableTaskbarProgress || !isWindowsVistaOrGreater)
            {
                return;
            }

            if (LastHwnd != IntPtr.Zero)
            {
                TaskbarList.SetProgressState(LastHwnd, TBPFLAG.TBPF_NOPROGRESS);
                LastHwnd = IntPtr.Zero;
            }
        }
Пример #5
0
 private static void SetProgressState(IntPtr hwnd, TaskbarProgressBarStatus state)
 {
     if (Enabled && IsPlatformSupported && hwnd != IntPtr.Zero)
     {
         try
         {
             TaskbarList.SetProgressState(hwnd, state);
         }
         catch (FileNotFoundException)
         {
             Enabled = false;
         }
     }
 }
Пример #6
0
        private void ButtonGenerate_Click(object sender, EventArgs e)
        {
            if (comboBoxModels.Items.Count == 0)
            {
                buttonDownload_Click(null, null);
                return;
            }

            if (_batchMode)
            {
                if (listViewInputFiles.Items.Count == 0)
                {
                    buttonAddFile_Click(null, null);
                    return;
                }

                GenerateBatch();
                TaskbarList.SetProgressState(_parentForm.Handle, TaskbarButtonProgressFlags.NoProgress);
                return;
            }

            progressBar1.Maximum = 100;
            progressBar1.Value   = 0;
            progressBar1.Visible = true;
            var modelFileName = Path.Combine(_voskFolder, comboBoxModels.Text);

            buttonGenerate.Enabled  = false;
            buttonDownload.Enabled  = false;
            buttonBatchMode.Enabled = false;
            var waveFileName = GenerateWavFile(_videoFileName, 0);

            textBoxLog.AppendText("Wav file name: " + waveFileName);
            textBoxLog.AppendText(Environment.NewLine);
            progressBar1.Style = ProgressBarStyle.Blocks;
            var transcript = TranscribeViaVosk(waveFileName, modelFileName);

            if (_cancel)
            {
                DialogResult = DialogResult.Cancel;
                return;
            }

            var postProcessor = new AudioToTextPostProcessor(GetLanguage(comboBoxModels.Text))
            {
                ParagraphMaxChars = Configuration.Settings.General.SubtitleLineMaximumLength * 2,
            };

            TranscribedSubtitle = postProcessor.Generate(transcript, checkBoxUsePostProcessing.Checked, true, true, true, true);
            DialogResult        = DialogResult.OK;
        }
        private void ButtonGenerate_Click(object sender, EventArgs e)
        {
            if (comboBoxModels.Items.Count == 0)
            {
                buttonDownload_Click(null, null);
                return;
            }

            if (listViewInputFiles.Items.Count == 0)
            {
                return;
            }

            GenerateBatch();
            TaskbarList.SetProgressState(_parentForm.Handle, TaskbarButtonProgressFlags.NoProgress);
        }
        private void GenerateBatch()
        {
            groupBoxInputFiles.Enabled = false;
            _batchFileNumber           = 0;
            textBoxLog.AppendText("Batch mode" + Environment.NewLine);
            var postProcessor = new AudioToTextPostProcessor(GetLanguage(comboBoxModels.Text))
            {
                ParagraphMaxChars = Configuration.Settings.General.SubtitleLineMaximumLength * 2,
            };

            progressBar1.Visible = true;
            foreach (ListViewItem lvi in listViewInputFiles.Items)
            {
                _batchFileNumber++;
                var videoFileName = lvi.Text;
                listViewInputFiles.SelectedIndices.Clear();
                lvi.Selected = true;
                var modelFileName = Path.Combine(_voskFolder, comboBoxModels.Text);
                buttonGenerate.Enabled = false;
                buttonDownload.Enabled = false;
                var waveFileName = videoFileName;
                textBoxLog.AppendText("Wav file name: " + waveFileName + Environment.NewLine);
                var transcript = TranscribeViaVosk(waveFileName, modelFileName);
                if (_cancel)
                {
                    TaskbarList.SetProgressState(_parentForm.Handle, TaskbarButtonProgressFlags.NoProgress);
                    DialogResult = DialogResult.Cancel;
                    return;
                }

                TranscribedSubtitle = postProcessor.Generate(transcript, checkBoxUsePostProcessing.Checked, false, true, false, false);

                progressBar1.Value = (int)Math.Round(_batchFileNumber * 100.0 / _audioClips.Count, MidpointRounding.AwayFromZero);
                progressBar1.Refresh();
                Application.DoEvents();

                SaveToAudioClip(_batchFileNumber - 1);

                TaskbarList.SetProgressValue(_parentForm.Handle, _batchFileNumber, listViewInputFiles.Items.Count);
            }

            progressBar1.Value = 100;
            labelTime.Text     = string.Empty;
            PostFix(postProcessor);

            DialogResult = DialogResult.OK;
        }
Пример #9
0
        public static void ShowTaskbarProgress(IntPtr hwnd, ThumbnailProgressState state)
        {
            if (disableTaskbarProgress || !isWindowsVistaOrGreater)
            {
                return;
            }

            HideTaskbarProgress();

            if (hwnd == IntPtr.Zero)
            {
                hwnd = GetHandleOfTheMainWindow();
            }

            if (hwnd != IntPtr.Zero)
            {
                LastHwnd = hwnd;
                TaskbarList.SetProgressState(LastHwnd, (TBPFLAG)state);
            }
        }
Пример #10
0
        private void ButtonStartRippingClick(object sender, EventArgs e)
        {
            if (buttonStartRipping.Text == _language.Abort)
            {
                _abort = true;
                buttonStartRipping.Text = _language.StartRipping;
                return;
            }
            _abort = false;
            buttonStartRipping.Text       = _language.Abort;
            _lastPresentationTimestamp    = 0;
            _lastVobPresentationTimestamp = 0;
            _lastNavEndPts = 0;
            _accumulatedPresentationTimestamp = 0;

            progressBarRip.Visible = true;
            var ms = new MemoryStream();
            int i  = 0;

            foreach (string vobFileName in listBoxVobFiles.Items)
            {
                i++;
                labelStatus.Text = string.Format(_language.RippingVobFileXofYZ, Path.GetFileName(vobFileName), i, listBoxVobFiles.Items.Count);
                Refresh();
                Application.DoEvents();

                if (!_abort)
                {
                    RipSubtitles(vobFileName, ms, i - 1); // Rip/demux subtitle vob packs
                }
            }
            progressBarRip.Visible = false;
            TaskbarList.SetProgressState(_taskbarFormHandle, TaskbarButtonProgressFlags.NoProgress);
            buttonStartRipping.Enabled = false;
            if (_abort)
            {
                labelStatus.Text           = _language.AbortedByUser;
                buttonStartRipping.Text    = _language.StartRipping;
                buttonStartRipping.Enabled = true;
                return;
            }

            labelStatus.Text = string.Format(_language.ReadingSubtitleData);
            Refresh();
            Application.DoEvents();
            var vobSub = new VobSubParser(radioButtonPal.Checked);

            vobSub.Open(ms);
            ms.Close();
            labelStatus.Text = string.Empty;

            MergedVobSubPacks = vobSub.MergeVobSubPacks(); // Merge splitted-packs to whole-packs
            if (MergedVobSubPacks.Count == 0)
            {
                MessageBox.Show(Configuration.Settings.Language.Main.NoSubtitlesFound);
                buttonStartRipping.Text    = _language.StartRipping;
                buttonStartRipping.Enabled = true;
                return;
            }
            Languages = new List <string>();
            for (int k = 0; k < comboBoxLanguages.Items.Count; k++)
            {
                Languages.Add(comboBoxLanguages.Items[k].ToString());
            }

            buttonStartRipping.Text    = _language.StartRipping;
            buttonStartRipping.Enabled = true;
            DialogResult = DialogResult.OK;
        }
Пример #11
0
        private void buttonRipWave_Click(object sender, EventArgs e)
        {
            if (listViewInputFiles.Items.Count == 0)
            {
                MessageBox.Show(Configuration.Settings.Language.BatchConvert.NothingToConvert);
                return;
            }
            _converting                = true;
            buttonRipWave.Enabled      = false;
            progressBar1.Style         = ProgressBarStyle.Blocks;
            progressBar1.Maximum       = listViewInputFiles.Items.Count;
            progressBar1.Value         = 0;
            progressBar1.Visible       = progressBar1.Maximum > 2;
            buttonInputBrowse.Enabled  = false;
            buttonSearchFolder.Enabled = false;
            _abort = false;
            listViewInputFiles.BeginUpdate();
            foreach (ListViewItem item in listViewInputFiles.Items)
            {
                item.SubItems[3].Text = "-";
            }
            listViewInputFiles.EndUpdate();
            Refresh();
            int index = 0;

            while (index < listViewInputFiles.Items.Count && _abort == false)
            {
                var item = listViewInputFiles.Items[index];
                item.SubItems[3].Text = Configuration.Settings.Language.AddWaveformBatch.ExtractingAudio;
                string fileName = item.Text;
                try
                {
                    string  targetFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".wav");
                    Process process;
                    try
                    {
                        string encoderName;
                        process        = AddWaveform.GetCommandLineProcess(fileName, -1, targetFile, Configuration.Settings.General.VlcWaveTranscodeSettings, out encoderName);
                        labelInfo.Text = encoderName;
                    }
                    catch (DllNotFoundException)
                    {
                        if (MessageBox.Show(Configuration.Settings.Language.AddWaveform.VlcMediaPlayerNotFound + Environment.NewLine +
                                            Environment.NewLine +
                                            Configuration.Settings.Language.AddWaveform.GoToVlcMediaPlayerHomePage,
                                            Configuration.Settings.Language.AddWaveform.VlcMediaPlayerNotFoundTitle, MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            Process.Start("http://www.videolan.org/");
                        }
                        buttonRipWave.Enabled = true;
                        return;
                    }

                    process.Start();
                    while (!process.HasExited && !_abort)
                    {
                        Application.DoEvents();
                    }


                    // check for delay in matroska files
                    var audioTrackNames      = new List <string>();
                    var mkvAudioTrackNumbers = new Dictionary <int, int>();
                    if (fileName.ToLower().EndsWith(".mkv", StringComparison.OrdinalIgnoreCase))
                    {
                        MatroskaFile matroska = null;
                        try
                        {
                            matroska = new MatroskaFile(fileName);

                            if (matroska.IsValid)
                            {
                                foreach (var track in matroska.GetTracks())
                                {
                                    if (track.IsAudio)
                                    {
                                        if (track.CodecId != null && track.Language != null)
                                        {
                                            audioTrackNames.Add("#" + track.TrackNumber + ": " + track.CodecId.Replace("\0", string.Empty) + " - " + track.Language.Replace("\0", string.Empty));
                                        }
                                        else
                                        {
                                            audioTrackNames.Add("#" + track.TrackNumber);
                                        }
                                        mkvAudioTrackNumbers.Add(mkvAudioTrackNumbers.Count, track.TrackNumber);
                                    }
                                }
                                if (mkvAudioTrackNumbers.Count > 0)
                                {
                                    _delayInMilliseconds = (int)matroska.GetTrackStartTime(mkvAudioTrackNumbers[0]);
                                }
                            }
                        }
                        catch
                        {
                            _delayInMilliseconds = 0;
                        }
                        finally
                        {
                            if (matroska != null)
                            {
                                matroska.Dispose();
                            }
                        }
                    }

                    item.SubItems[3].Text = Configuration.Settings.Language.AddWaveformBatch.Calculating;
                    MakeWaveformAndSpectrogram(fileName, targetFile, _delayInMilliseconds);

                    // cleanup
                    try
                    {
                        File.Delete(targetFile);
                    }
                    catch
                    {
                        // don't show error about unsuccessful delete
                    }

                    IncrementAndShowProgress();

                    item.SubItems[3].Text = Configuration.Settings.Language.AddWaveformBatch.Done;
                }
                catch
                {
                    IncrementAndShowProgress();
                    item.SubItems[3].Text = "ERROR";
                }
                index++;
            }
            _converting          = false;
            labelProgress.Text   = string.Empty;
            labelInfo.Text       = string.Empty;
            progressBar1.Visible = false;
            TaskbarList.SetProgressState(Handle, TaskbarButtonProgressFlags.NoProgress);
            buttonRipWave.Enabled      = true;
            buttonInputBrowse.Enabled  = true;
            buttonSearchFolder.Enabled = true;
        }
Пример #12
0
        public static void SetTaskbarProgressState(IntPtr hwnd, ThumbnailProgressState state)
        {
            HResult result = TaskbarList.SetProgressState(hwnd, (uint)state);

            result.ThrowIf();
        }
Пример #13
0
        public List <ResultText> TranscribeViaVosk(string waveFileName, string modelFileName)
        {
            labelProgress.Text = LanguageSettings.Current.AudioToText.LoadingVoskModel;
            labelProgress.Refresh();
            Application.DoEvents();
            Directory.SetCurrentDirectory(_voskFolder);
            Vosk.Vosk.SetLogLevel(0);
            if (_model == null)
            {
                _model = new Model(modelFileName);
            }

            var rec = new VoskRecognizer(_model, 16000.0f);

            rec.SetMaxAlternatives(0);
            rec.SetWords(true);
            var list = new List <ResultText>();

            labelProgress.Text = LanguageSettings.Current.AudioToText.Transcribing;
            if (_batchMode)
            {
                labelProgress.Text = string.Format(LanguageSettings.Current.AudioToText.TranscribingXOfY, _batchFileNumber, listViewInputFiles.Items.Count);
            }
            else
            {
                TaskbarList.SetProgressValue(_parentForm.Handle, 1, 100);
            }

            labelProgress.Refresh();
            Application.DoEvents();
            var buffer = new byte[4096];

            _bytesWavTotal = new FileInfo(waveFileName).Length;
            _bytesWavRead  = 0;
            _startTicks    = DateTime.UtcNow.Ticks;
            timer1.Start();
            using (var source = File.OpenRead(waveFileName))
            {
                int bytesRead;
                while ((bytesRead = source.Read(buffer, 0, buffer.Length)) > 0)
                {
                    _bytesWavRead     += bytesRead;
                    progressBar1.Value = (int)(_bytesWavRead * 100.0 / _bytesWavTotal);
                    progressBar1.Refresh();
                    Application.DoEvents();
                    if (rec.AcceptWaveform(buffer, bytesRead))
                    {
                        var res     = rec.Result();
                        var results = ParseJsonToResult(res);
                        list.AddRange(results);
                    }
                    else
                    {
                        var res = rec.PartialResult();
                        textBoxLog.AppendText(res.RemoveChar('\r', '\n'));
                    }

                    if (!_batchMode)
                    {
                        TaskbarList.SetProgressValue(_parentForm.Handle, Math.Max(1, progressBar1.Value), progressBar1.Maximum);
                    }

                    if (_cancel)
                    {
                        TaskbarList.SetProgressState(_parentForm.Handle, TaskbarButtonProgressFlags.NoProgress);
                        return(null);
                    }
                }

                if (!_batchMode)
                {
                    TaskbarList.StartBlink(_parentForm, 10, 1, 2);
                }
            }

            var finalResult  = rec.FinalResult();
            var finalResults = ParseJsonToResult(finalResult);

            list.AddRange(finalResults);
            timer1.Stop();
            return(list);
        }
Пример #14
0
        private void buttonRipWave_Click(object sender, EventArgs e)
        {
            if (listViewInputFiles.Items.Count == 0)
            {
                MessageBox.Show(LanguageSettings.Current.BatchConvert.NothingToConvert);
                return;
            }

            _converting                = true;
            buttonRipWave.Enabled      = false;
            progressBar1.Style         = ProgressBarStyle.Blocks;
            progressBar1.Maximum       = listViewInputFiles.Items.Count;
            progressBar1.Value         = 0;
            progressBar1.Visible       = progressBar1.Maximum > 2;
            buttonInputBrowse.Enabled  = false;
            buttonSearchFolder.Enabled = false;
            _abort = false;
            listViewInputFiles.BeginUpdate();
            foreach (ListViewItem item in listViewInputFiles.Items)
            {
                item.SubItems[3].Text = "-";
            }

            listViewInputFiles.EndUpdate();
            Refresh();
            var index = 0;

            while (index < listViewInputFiles.Items.Count && _abort == false)
            {
                var item = listViewInputFiles.Items[index];

                void UpdateStatus(string status)
                {
                    item.SubItems[3].Text = status;
                    Refresh();
                }

                UpdateStatus(LanguageSettings.Current.AddWaveformBatch.ExtractingAudio);
                var fileName = item.Text;
                try
                {
                    var     targetFile = Path.Combine(Path.GetTempPath(), Guid.NewGuid() + ".wav");
                    Process process;
                    try
                    {
                        process        = AddWaveform.GetCommandLineProcess(fileName, -1, targetFile, Configuration.Settings.General.VlcWaveTranscodeSettings, out var encoderName);
                        labelInfo.Text = encoderName;
                    }
                    catch (DllNotFoundException)
                    {
                        var isFfmpegAvailable = !string.IsNullOrEmpty(Configuration.Settings.General.FFmpegLocation) && File.Exists(Configuration.Settings.General.FFmpegLocation);
                        if (isFfmpegAvailable)
                        {
                            Configuration.Settings.General.UseFFmpegForWaveExtraction = true;
                            process        = AddWaveform.GetCommandLineProcess(fileName, -1, targetFile, Configuration.Settings.General.VlcWaveTranscodeSettings, out var encoderName);
                            labelInfo.Text = encoderName;
                        }
                        else
                        {
                            if (MessageBox.Show(LanguageSettings.Current.AddWaveform.FfmpegNotFound, "Subtitle Edit", MessageBoxButtons.YesNoCancel) != DialogResult.Yes)
                            {
                                buttonRipWave.Enabled = true;
                                return;
                            }

                            using (var form = new DownloadFfmpeg())
                            {
                                if (form.ShowDialog(this) == DialogResult.OK && !string.IsNullOrEmpty(form.FFmpegPath))
                                {
                                    Configuration.Settings.General.FFmpegLocation             = form.FFmpegPath;
                                    Configuration.Settings.General.UseFFmpegForWaveExtraction = true;
                                    process        = AddWaveform.GetCommandLineProcess(fileName, -1, targetFile, Configuration.Settings.General.VlcWaveTranscodeSettings, out var encoderName);
                                    labelInfo.Text = encoderName;
                                }
                                else
                                {
                                    buttonRipWave.Enabled = true;
                                    return;
                                }
                            }
                        }
                    }

                    process.Start();
                    while (!process.HasExited && !_abort)
                    {
                        Application.DoEvents();
                    }

                    // check for delay in matroska files
                    var audioTrackNames      = new List <string>();
                    var mkvAudioTrackNumbers = new Dictionary <int, int>();
                    if (fileName.ToLowerInvariant().EndsWith(".mkv", StringComparison.OrdinalIgnoreCase))
                    {
                        try
                        {
                            using (var matroska = new MatroskaFile(fileName))
                            {
                                if (matroska.IsValid)
                                {
                                    foreach (var track in matroska.GetTracks())
                                    {
                                        if (track.IsAudio)
                                        {
                                            if (track.CodecId != null && track.Language != null)
                                            {
                                                audioTrackNames.Add("#" + track.TrackNumber + ": " + track.CodecId.Replace("\0", string.Empty) + " - " + track.Language.Replace("\0", string.Empty));
                                            }
                                            else
                                            {
                                                audioTrackNames.Add("#" + track.TrackNumber);
                                            }

                                            mkvAudioTrackNumbers.Add(mkvAudioTrackNumbers.Count, track.TrackNumber);
                                        }
                                    }
                                    if (mkvAudioTrackNumbers.Count > 0)
                                    {
                                        _delayInMilliseconds = (int)matroska.GetAudioTrackDelayMilliseconds(mkvAudioTrackNumbers[0]);
                                    }
                                }
                            }
                        }
                        catch (Exception exception)
                        {
                            SeLogger.Error(exception, $"Error getting delay from mkv: {fileName}");
                            _delayInMilliseconds = 0;
                        }
                    }

                    UpdateStatus(LanguageSettings.Current.AddWaveformBatch.Calculating);
                    MakeWaveformAndSpectrogram(fileName, targetFile, _delayInMilliseconds);

                    if (checkBoxGenerateSceneChanges.Visible && checkBoxGenerateSceneChanges.Checked)
                    {
                        GenerateSceneChanges(fileName);
                    }

                    // cleanup
                    try
                    {
                        File.Delete(targetFile);
                    }
                    catch
                    {
                        // don't show error about unsuccessful delete
                    }

                    IncrementAndShowProgress();

                    UpdateStatus(LanguageSettings.Current.AddWaveformBatch.Done);
                }
                catch
                {
                    IncrementAndShowProgress();

                    UpdateStatus(LanguageSettings.Current.AddWaveformBatch.Error);
                }
                index++;
            }
            _converting          = false;
            labelProgress.Text   = string.Empty;
            labelInfo.Text       = string.Empty;
            progressBar1.Visible = false;
            TaskbarList.SetProgressState(Owner.Handle, TaskbarButtonProgressFlags.NoProgress);
            buttonRipWave.Enabled      = true;
            buttonInputBrowse.Enabled  = true;
            buttonSearchFolder.Enabled = true;
        }
Пример #15
0
 private void SetProgressState()
 {
     // must be Windows7orGreater
     TaskbarList.SetProgressState(Handle, m_State);
     SetProgressValue();
 }