diff --git a/src/libse/SubtitleFormats/AudacityLabels.cs b/src/libse/SubtitleFormats/AudacityLabels.cs new file mode 100644 index 000000000..940b56a42 --- /dev/null +++ b/src/libse/SubtitleFormats/AudacityLabels.cs @@ -0,0 +1,40 @@ +using Nikse.SubtitleEdit.Core.Common; +using System; +using System.Collections.Generic; +using System.Globalization; + +namespace Nikse.SubtitleEdit.Core.SubtitleFormats +{ + public class AudacityLabels : SubtitleFormat + { + public override string Extension => ".txt"; + + public override string Name => "Audacity labels"; + + public override void LoadSubtitle(Subtitle subtitle, List lines, string fileName) + { + _errorCount = 0; + foreach (var line in lines) + { + var arr = line.Split('\t'); + if (arr.Length == 3 && + double.TryParse(arr[0], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var start) && + double.TryParse(arr[1], NumberStyles.AllowDecimalPoint, CultureInfo.InvariantCulture, out var end)) + { + subtitle.Paragraphs.Add(new Paragraph(arr[2], start * TimeCode.BaseUnit, end * TimeCode.BaseUnit)); + } + else + { + _errorCount++; + } + } + + subtitle.Renumber(); + } + + public override string ToText(Subtitle subtitle, string title) + { + throw new NotImplementedException(); + } + } +} diff --git a/src/libse/SubtitleFormats/SubtitleFormat.cs b/src/libse/SubtitleFormats/SubtitleFormat.cs index cc2a862d9..d957cf428 100644 --- a/src/libse/SubtitleFormats/SubtitleFormat.cs +++ b/src/libse/SubtitleFormats/SubtitleFormat.cs @@ -651,6 +651,7 @@ namespace Nikse.SubtitleEdit.Core.SubtitleFormats new MacCaption10(), new Rdf1(), new CombinedXml(), + new AudacityLabels(), }; }