Exemple #1
0
        /// ------------------------------------------------------------------------------------
        private void HandleGetStartedButtonClick(object sender, EventArgs e)
        {
            _buttonGetStarted.Enabled = false;
            ExternalProcess.CleanUpAllProcesses();
            string newAnnotationFile = null;

            if (_radioButtonManual.Checked)
            {
                Settings.Default.DefaultSegmentationMethod = 0;
                newAnnotationFile = ManualSegmenterDlg.ShowDialog(_file, this, -1);
            }
            else if (_radioButtonCarefulSpeech.Checked)
            {
                Settings.Default.DefaultSegmentationMethod = 1;
                newAnnotationFile = (!AudioUtils.GetCanRecordAudio()) ? null :
                                    _file.RecordAnnotations(FindForm(), AudioRecordingType.Careful);
            }
            else if (_radioButtonElan.Checked)
            {
                var caption = LocalizationManager.GetString(
                    "DialogBoxes.Transcription.CreateAnnotationFileDlg.LoadSegmentFileDlgCaption", "Select Segment File");

                var filetype = LocalizationManager.GetString(
                    "DialogBoxes.Transcription.CreateAnnotationFileDlg.ElanFileTypeString",
                    "ELAN File (*.eaf)|*.eaf");

                newAnnotationFile = GetAudacityOrElanFile(caption, filetype);
                Settings.Default.DefaultSegmentationMethod = 2;
            }
            else if (_radioButtonAudacity.Checked)
            {
                var caption = LocalizationManager.GetString(
                    "DialogBoxes.Transcription.CreateAnnotationFileDlg.AudacityLabelOpenFileDlg.Caption",
                    "Select Audacity Label File");

                var filetype = LocalizationManager.GetString(
                    "DialogBoxes.Transcription.CreateAnnotationFileDlg.AudacityLabelOpenFileDlg.FileTypeString",
                    "Audacity Label File (*.txt)|*.txt");

                newAnnotationFile = GetAudacityOrElanFile(caption, filetype);
                Settings.Default.DefaultSegmentationMethod = 3;
            }
            else if (_radioButtonAutoSegmenter.Checked)
            {
                var segmenter = new AutoSegmenter(_file, _project);
                newAnnotationFile = segmenter.Run();
                Settings.Default.DefaultSegmentationMethod = 4;
            }

            if (newAnnotationFile != null && ComponentFileListRefreshAction != null)
            {
                ComponentFileListRefreshAction(newAnnotationFile, null);
            }

            _buttonGetStarted.Enabled = true;
        }
        /// ------------------------------------------------------------------------------------
        private void HandleResegmentButtonClick(object sender, EventArgs e)
        {
            var  originallySelectedCell    = _grid.CurrentCellAddress;
            bool startPlayBackWhenFinished = false;

            ShowSegmentationDialog(delegate
            {
                if (ManualSegmenterDlg.ShowDialog(AssociatedComponentFile, this, _grid.CurrentCellAddress.Y) != null)
                {
                    if (!_grid.IsDisposed)
                    {
                        if (originallySelectedCell != _grid.CurrentCellAddress)
                        {
                            // User has already selected a different cell, so go ahead and
                            // start playback after refreshing the grid.
                            originallySelectedCell    = _grid.CurrentCellAddress;
                            startPlayBackWhenFinished = true;
                        }
                        SetComponentFile(_file);
                        if (_grid.RowCount > originallySelectedCell.Y && originallySelectedCell.Y >= 0 &&
                            _grid.ColumnCount > originallySelectedCell.X && originallySelectedCell.X >= 0)
                        {
                            _grid.CurrentCell = _grid.Rows[originallySelectedCell.Y].Cells[originallySelectedCell.X];
                        }
                        else
                        {
                            startPlayBackWhenFinished = false;                                     // Oops, that cell is gone!
                        }
                    }
                }
            });
            if (startPlayBackWhenFinished)
            {
                _grid.Play();
            }
        }
Exemple #3
0
        /// ------------------------------------------------------------------------------------
        public static string ShowDialog(ComponentFile file, EditorBase parent, int segmentToHighlight)
        {
            Exception error;
            string    msg;

            using (var viewModel = new ManualSegmenterDlgViewModel(file))
                using (var dlg = new ManualSegmenterDlg(viewModel, segmentToHighlight))
                {
                    try
                    {
                        if (dlg.ShowDialog(parent) != DialogResult.OK || !viewModel.WereChangesMade)
                        {
                            viewModel.DiscardChanges();
                            return(null);
                        }

                        Analytics.Track("Changes made using Manual Segmentation");

                        var annotationFile = file.GetAnnotationFile();

                        if (!viewModel.TimeTier.Segments.Any())
                        {
                            if (annotationFile != null)
                            {
                                annotationFile.Delete();
                                parent.RefreshComponentFiles(file.FileName, null);
                            }
                            return(null);
                        }

                        var eafFile = AnnotationFileHelper.Save(file.PathToAnnotatedFile, viewModel.Tiers);

                        if (annotationFile == null)
                        {
                            return(eafFile);
                        }

                        error = annotationFile.TryLoadAndReturnException();
                        if (error == null)
                        {
                            WaitCursor.Show();
                            try
                            {
                                annotationFile.AssociatedComponentFile.GenerateOralAnnotationFile(viewModel.Tiers,
                                                                                                  parent, ComponentFile.GenerateOption.ClearAndRegenerateOnDemand);
                            }
                            finally
                            {
                                WaitCursor.Hide();
                            }
                            return(eafFile);
                        }

                        msg = LocalizationManager.GetString(
                            "DialogBoxes.Transcription.ManualSegmenterDlg.SavingSegmentsErrorMsg",
                            "There was an error while trying to save segments for the file '{0}'.");
                    }
                    catch (Exception e)
                    {
                        error = e;
                        msg   = LocalizationManager.GetString(
                            "DialogBoxes.Transcription.ManualSegmenterDlg.GeneralSegmentingErrorMsg",
                            "There was an error segmenting the file '{0}'.");
                    }
                }

            ErrorReport.NotifyUserOfProblem(error, msg, file.PathToAnnotatedFile);
            return(null);
        }