public void Setup()
        {
            SIL.Reporting.ErrorReport.IsOkToInteractWithUser = false;

            _tempAudioFile = MediaFileInfoTests.GetLongerTestAudioFile();
            _timeTier      = new TimeTier(_tempAudioFile);
            _timeTier.AddSegment(0f, 10f);
            _timeTier.AddSegment(10f, 20f);
            _timeTier.AddSegment(20f, 30f);

            _textTier = new TextTier(TextTier.ElanTranscriptionTierId);

            var annotationFile = new Mock <AnnotationComponentFile>();

            annotationFile.Setup(a => a.Tiers).Returns(new TierCollection {
                _timeTier, _textTier
            });

            _componentFile = new Mock <ComponentFile>();
            _componentFile.Setup(f => f.PathToAnnotatedFile).Returns(_tempAudioFile);
            _componentFile.Setup(f => f.GetAnnotationFile()).Returns(annotationFile.Object);

            CreateNewModel();
            Directory.CreateDirectory(_model.OralAnnotationsFolder);

            Assert.IsNotNull(_model.OrigWaveStream);
        }
Esempio n. 2
0
        /// ------------------------------------------------------------------------------------
        public override string GetFullPathOfOtherAnnotationFileForTimeRange(TimeRange timeRange)
        {
            var segment = TimeTier.Segments.FirstOrDefault(s => s.TimeRange == timeRange) ??
                          new AnnotationSegment(null, timeRange);

            return(TimeTier.GetFullPathToCarefulSpeechFile(segment));
        }
        /// ------------------------------------------------------------------------------------
        public void SetIgnoredFlagForSegment(AnnotationSegment segment, bool ignore)
        {
            if (segment != null)
            {
                var segmentIndex = TimeTier.GetIndexOfSegment(segment);
                var timeRange    = segment.TimeRange.Copy();
                if (ignore)
                {
                    Action restoreState = GetActionToRestoreStateWhenUndoingAnIgnore(segment);

                    Tiers.MarkSegmentAsIgnored(segmentIndex);
                    _undoStack.Push(new SegmentChange(SegmentChangeType.Ignored, timeRange, timeRange, sc =>
                    {
                        Tiers.MarkSegmentAsUnignored(segmentIndex);
                        restoreState();
                    }));
                }
                else
                {
                    Tiers.MarkSegmentAsUnignored(segmentIndex);
                    _undoStack.Push(new SegmentChange(SegmentChangeType.Unignored, timeRange, timeRange,
                                                      sc => Tiers.MarkSegmentAsIgnored(segmentIndex)));
                }
            }
            else
            {
                if (!ignore)
                {
                    throw new InvalidOperationException("New segment can never be unignored.");
                }
                AddIgnoredSegment(VirtualBoundaryBeyondLastSegment);
            }
        }
Esempio n. 4
0
        /// ------------------------------------------------------------------------------------
        internal static void CreateAndAnnotateSegment(TimeTier tier, float startTime, float endTime)
        {
            var segment = tier.AddSegment(startTime, endTime);

            File.OpenWrite(Path.Combine(tier.SegmentFileFolder, tier.GetFullPathToCarefulSpeechFile(segment))).Close();
            File.OpenWrite(Path.Combine(tier.SegmentFileFolder, tier.GetFullPathToOralTranslationFile(segment))).Close();
        }
        /// ------------------------------------------------------------------------------------
        public SegmenterDlgBaseViewModel(ComponentFile file)
        {
            ComponentFile  = file;
            OrigWaveStream = new WaveFileReader(ComponentFile.PathToAnnotatedFile);

            Tiers = file.GetAnnotationFile() != null?
                    file.GetAnnotationFile().Tiers.Copy() : new TierCollection(ComponentFile.PathToAnnotatedFile);

            TimeTier = Tiers.GetTimeTier();

            if (TimeTier == null)
            {
                TimeTier = new TimeTier(ComponentFile.PathToAnnotatedFile);
                Tiers.Insert(0, TimeTier);
            }

            OralAnnotationsFolder = ComponentFile.PathToAnnotatedFile +
                                    Settings.Default.OralAnnotationsFolderSuffix;

            TempOralAnnotationsFolder = Path.Combine(Path.GetTempPath(), "SayMoreOralAnnotations");
            if (Directory.Exists(TempOralAnnotationsFolder))
            {
                foreach (var tempFile in Directory.EnumerateFiles(TempOralAnnotationsFolder))
                {
                    File.Delete(tempFile);
                }
            }
            _oralAnnotationFilesBeforeChanges = GetListOfOralAnnotationSegmentFilesBeforeChanges().ToList();
            TimeTier.BackupOralAnnotationSegmentFileAction = BackupOralAnnotationSegmentFile;
        }
Esempio n. 6
0
        private void DoExportSubtitleDialog(string fileNameSuffix, TimeTier timeTier, TextTier textTeir)
        {
            textTeir.AddTimeRangeData(timeTier);

            var action = new Action <string>(path => SRTFormatSubTitleExporter.Export(path, textTeir));

            DoSimpleExportDialog(".srt", "SRT Subtitle File", fileNameSuffix, string.Empty, action);
        }
        /// ------------------------------------------------------------------------------------
        public bool CanMoveBoundary(TimeSpan boundaryToAdjust, int millisecondsToMove)
        {
            var secondsToMove = Math.Abs(millisecondsToMove) / 1000f;
            var boundary      = (float)boundaryToAdjust.TotalSeconds;

            return(millisecondsToMove < 0 ?
                   TimeTier.CanBoundaryMoveLeft(boundary, secondsToMove) :
                   TimeTier.CanBoundaryMoveRight(boundary, secondsToMove, (float)OrigWaveStream.TotalTime.TotalSeconds));
        }
Esempio n. 8
0
        private void DoExportSubtitleDialog(string fileNameSuffix, TimeTier timeTier, TextTier textTeir)
        {
            textTeir.AddTimeRangeData(timeTier);

            var action = new Action <string>(path => SRTFormatSubTitleExporter.Export(path, textTeir));

            DoSimpleExportDialog(".srt",
                                 LocalizationManager.GetString("SessionsView.Transcription.TextAnnotation.ExportMenu.srtSubtitlesTranscriptionExport.TranscriptionFileDescriptor", "SRT Subtitle File ({0})"),
                                 fileNameSuffix, string.Empty, action);
        }
        public void GetFullPathToAnnotationFileForSegment_ReturnsPathWithCorrectFolder()
        {
            // This test only checks for the correct folder because testing for
            // correct file name is done in the TimeTier tests.

            var tier = new TimeTier(_model.OralAnnotationsFolder.Replace("_Annotations", string.Empty));

            Assert.AreEqual(_model.OralAnnotationsFolder, Path.GetDirectoryName(
                                _model.GetFullPathToAnnotationFileForSegment(new AnnotationSegment(tier, 1f, 2f))));
        }
        /// ------------------------------------------------------------------------------------
        public bool DeleteBoundary(TimeSpan boundary)
        {
            var seg = TimeTier.GetSegmentHavingEndBoundary((float)boundary.TotalSeconds);

            if (!Tiers.RemoveTierSegments(TimeTier.GetIndexOfSegment(seg)))
            {
                return(false);
            }

            OnSegmentDeleted(seg);
            OnSegmentBoundaryChanged();
            return(true);
        }
Esempio n. 11
0
        /// ------------------------------------------------------------------------------------
        internal static void CreateAnnotationFiles(TimeTier tier, params string[] files)
        {
            Directory.CreateDirectory(tier.SegmentFileFolder);

            foreach (var file in files)
            {
                File.OpenWrite(Path.Combine(tier.SegmentFileFolder, file)).Close();
            }

            foreach (var file in files)
            {
                Assert.IsTrue(File.Exists(Path.Combine(tier.SegmentFileFolder, file)));
            }
        }
        /// ------------------------------------------------------------------------------------
        private bool UpdateSegmentBoundary(AnnotationSegment seg, TimeSpan newEndTime)
        {
            var origTimeRange = seg.TimeRange.Copy();

            if (TimeTier.ChangeSegmentsEndBoundary(seg.TimeRange.EndSeconds, (float)newEndTime.TotalSeconds) !=
                BoundaryModificationResult.Success)
            {
                return(false);
            }

            _undoStack.Push(new SegmentChange(SegmentChangeType.EndBoundaryMoved, origTimeRange, seg.TimeRange.Copy(),
                                              c => SegmentBoundaryMoved(c.NewRange.End, c.OriginalRange.End)));
            return(true);
        }
Esempio n. 13
0
        public void Setup()
        {
            var tempMediaPath = MediaFileInfoTests.GetLongerTestAudioFile();

            _tempFolder = new TemporaryFolder("TierCollectionTests");
            var mediaFile = Path.Combine(_tempFolder.Path, "mediaFile.wav");

            File.Move(tempMediaPath, mediaFile);

            _collection = new TierCollection(mediaFile);
            _collection.Clear();
            var timeTier = new TimeTier("timeTier", mediaFile);

            _collection.Add(timeTier);

            var transcriptionTier = new TextTier(TextTier.ElanTranscriptionTierId);

            _collection.Add(transcriptionTier);

            var translationTier = new TextTier(TextTier.ElanTranslationTierId);

            _collection.Add(translationTier);

            var otherTextTier = new TextTier("otherTextTier");

            _collection.Add(otherTextTier);

            timeTier.AddSegment(10f, 20f);
            timeTier.AddSegment(20f, 30f);
            timeTier.AddSegment(30f, 40f);

            transcriptionTier.AddSegment("trans1");
            transcriptionTier.AddSegment("trans2");
            transcriptionTier.AddSegment("trans3");

            translationTier.AddSegment("free1");
            translationTier.AddSegment("free2");
            translationTier.AddSegment(null);

            otherTextTier.AddSegment("other1");
            otherTextTier.AddSegment(null);
            otherTextTier.AddSegment(null);

            Assert.AreEqual(mediaFile, _collection.AnnotatedMediaFile);
            Assert.AreEqual(4, _collection.Count);
        }
        /// ------------------------------------------------------------------------------------
        private void CreateAnnotationFile(AudioRecordingType fileType, float start, float end)
        {
            if (!Directory.Exists(_model.OralAnnotationsFolder))
            {
                Directory.CreateDirectory(_model.OralAnnotationsFolder);
            }

            if (fileType == AudioRecordingType.Careful)
            {
                File.OpenWrite(Path.Combine(_model.OralAnnotationsFolder,
                                            TimeTier.ComputeFileNameForCarefulSpeechSegment(start, end))).Close();
            }
            else
            {
                File.OpenWrite(Path.Combine(_model.OralAnnotationsFolder,
                                            TimeTier.ComputeFileNameForOralTranslationSegment(start, end))).Close();
            }
        }
Esempio n. 15
0
        public void Setup()
        {
            var tempMediaPath = MediaFileInfoTests.GetLongerTestAudioFile();

            _tempFolder = new TemporaryFolder("TierCollectionTests");
            var mediaFile = Path.Combine(_tempFolder.Path, "mediaFile.wav");

            File.Move(tempMediaPath, mediaFile);
            _tier = new TimeTier("test tier", mediaFile);
            _tier.AddSegment(10f, 20f);
            _tier.AddSegment(20f, 30f);
            _tier.AddSegment(30f, 40f);

            Assert.AreEqual("test tier", _tier.Id);
            Assert.AreEqual(string.Empty, _tier.DisplayName);
            Assert.AreEqual(mediaFile, _tier.MediaFileName);
            Assert.AreEqual(Path.Combine(_tempFolder.Path, "mediaFile.wav_Annotations"), _tier.SegmentFileFolder);

            Assert.IsInstanceOf <AudioWaveFormColumn>(_tier.GridColumn);
        }
        public void Setup()
        {
            _tempAudioFile = MediaFileInfoTests.GetLongerTestAudioFile();
            var tier = new TimeTier(_tempAudioFile);

            tier.AddSegment(0f, 5f);
            tier.AddSegment(5f, 10f);
            tier.AddSegment(15f, 20f);
            tier.AddSegment(25f, 30f);

            var annotationFile = new Mock <AnnotationComponentFile>();

            annotationFile.Setup(a => a.Tiers).Returns(new TierCollection {
                tier
            });

            _componentFile = new Mock <ComponentFile>();
            _componentFile.Setup(f => f.PathToAnnotatedFile).Returns(_tempAudioFile);
            _componentFile.Setup(f => f.GetAnnotationFile()).Returns(annotationFile.Object);

            _model = OralAnnotationRecorderDlgViewModel.Create(_componentFile.Object, AudioRecordingType.Careful);
        }
        /// ------------------------------------------------------------------------------------
        private void CreateModelAndAnnotationFileForType(AudioRecordingType modelType,
                                                         AudioRecordingType fileType, float start, float end)
        {
            if (Directory.Exists(_model.OralAnnotationsFolder))
            {
                Directory.Delete(_model.OralAnnotationsFolder, true);
            }

            _model.Dispose();
            _model = OralAnnotationRecorderDlgViewModel.Create(_componentFile.Object, modelType);

            Directory.CreateDirectory(_model.OralAnnotationsFolder);

            if (fileType == AudioRecordingType.Careful)
            {
                WriteWavFile(Path.Combine(_model.OralAnnotationsFolder,
                                          TimeTier.ComputeFileNameForCarefulSpeechSegment(start, end)));
            }
            else
            {
                WriteWavFile(Path.Combine(_model.OralAnnotationsFolder,
                                          TimeTier.ComputeFileNameForOralTranslationSegment(start, end)));
            }
        }
Esempio n. 18
0
        /// ------------------------------------------------------------------------------------
        private void CreateTestTier()
        {
            var tier = new TextTier(TextTier.ElanTranscriptionTierId);

            tier.AddSegment("up");
            tier.AddSegment("down");
            tier.AddSegment("over");

            var dependentTier = new TextTier(TextTier.ElanTranslationTierId);

            dependentTier.AddSegment("in");
            dependentTier.AddSegment("around");
            dependentTier.AddSegment("through");

            var timeTier = new TimeTier("test tier", _mediaFile);

            timeTier.AddSegment(10f, 20f);
            timeTier.AddSegment(20f, 30f);
            timeTier.AddSegment(30f, 40f);

            _helper = new FLExTextExporter(null, "Homer", new TierCollection {
                tier, dependentTier, timeTier
            }, "en", "fr", "filename1", "filename2");
        }
Esempio n. 19
0
 public void GetFileNameForOralTranslationSegment_PassGoodStartAndEnd_ReturnsCorrectFileName()
 {
     Assert.AreEqual("3.456_to_10.321_Translation.wav",
                     TimeTier.ComputeFileNameForOralTranslationSegment(3.456f, 10.321f));
 }
Esempio n. 20
0
 public void GetFileNameForCarefulSpeechSegment_PassNullSegment_ThrowsException()
 {
     Assert.Throws <NullReferenceException>(() => TimeTier.ComputeFileNameForCarefulSpeechSegment(null as AnnotationSegment));
 }
Esempio n. 21
0
 /// ------------------------------------------------------------------------------------
 public bool GetSelectedSegmentIsLongEnough()
 {
     return(TimeTier.GetIsAcceptableSegmentLength(GetSelectedTimeRange().StartSeconds,
                                                  GetSelectedTimeRange().EndSeconds));
 }
Esempio n. 22
0
 public void ComputeFileNameForCarefulSpeechSegment_PassGoodSegment_ReturnsCorrectFileName()
 {
     Assert.AreEqual("0_to_4.75_Careful.wav",
                     TimeTier.ComputeFileNameForCarefulSpeechSegment(new AnnotationSegment(null, 0f, 4.75f)));
 }
 /// ------------------------------------------------------------------------------------
 public bool GetIsSegmentIgnored(AnnotationSegment segment)
 {
     return(GetIsSegmentIgnored(TimeTier.GetIndexOfSegment(segment)));
 }
Esempio n. 24
0
 public void ComputeFileNameForCarefulSpeechSegment_PassGoodStartAndEnd_ReturnsCorrectFileName()
 {
     Assert.AreEqual("3.456_to_10.321_Careful.wav",
                     TimeTier.ComputeFileNameForCarefulSpeechSegment(3.456f, 10.321f));
 }
Esempio n. 25
0
 public void ComputeFileNameForOralTranslationSegment_PassNullSegment_ThrowsException()
 {
     Assert.Throws <NullReferenceException>(() => TimeTier.ComputeFileNameForOralTranslationSegment(null as AnnotationSegment));
 }
Esempio n. 26
0
 public void ComputeFileNameForOralTranslationSegment_PassGoodSegment_ReturnsCorrectFileName()
 {
     Assert.AreEqual("0_to_4.75_Translation.wav",
                     TimeTier.ComputeFileNameForOralTranslationSegment(new AnnotationSegment(null, 0f, 4.75f)));
 }