private IEnumerable <CutAudioLine> CutAudios()
        {
            var list = File.ReadLines(Constants.TOTAL_MAPPING_PATH)
                       .Select(x => new TotalMappingLine(x));
            int externalIndex = 0;

            foreach (var l in list)
            {
                if (!File.Exists(l.DeliveredTextPath))
                {
                    continue;
                }
                var content = File.ReadLines(l.DeliveredTextPath)
                              .Select(x => LocalCommon.ExtractTransLine(x))
                              .ToArray();
                Sanity.Requires(content.Length % 2 == 0);
                for (int i = 0; i < content.Length; i += 2)
                {
                    CutAudioLine line = new CutAudioLine
                    {
                        SourceAudioPath = l.DeliveredAudioPath,
                        SourceTextPath  = l.DeliveredTextPath,
                        Dialect         = l.Dialect,
                        ExternalIndex   = externalIndex,
                        InternalIndex   = i / 2,
                        StartTime       = content[i].StartTime.ToString(),
                        EndTime         = content[i].EndTime.ToString(),
                        SG = content[i].Content,
                        HG = content[i + 1].Content
                    };
                    yield return(line);
                }
                externalIndex++;
            }
        }
        public void CutAudio(string rootPath)
        {
            string outputFolder = Path.Combine(rootPath, Dialect, ExternalIndex.ToString());

            Directory.CreateDirectory(outputFolder);
            string outputPath = Path.Combine(outputFolder, InternalIndex + ".wav");
            double timeSpan   = double.Parse(EndTime) - double.Parse(StartTime);

            LocalCommon.CutAudioWithSox(SourceAudioPath, StartTime, timeSpan, outputPath);
        }
        public void MappingOnlineData(string workFolder)
        {
            string outputFolder       = Path.Combine(workFolder, "Output");
            string overallMappingPath = @"F:\WorkFolder\Summary\20210222\Important\OverallMappingAll.txt";
            var    taskIdNameDict     = File.ReadLines(overallMappingPath)
                                        .Select(x => new OverallMappingLine(x))
                                        .Select(x => new { x.AudioFolder, x.TaskId })
                                        .Where(x => x.TaskId != "0" && x.TaskId != "" && x.TaskId != "627" && x.TaskId != "-1" && x.TaskId != "-2")
                                        .Distinct()
                                        .ToDictionary(x => x.TaskId, x => x.AudioFolder.ToLower());
            List <string> outputList = new List <string>();
            string        outputPath = Path.Combine(workFolder, "OutputMapping.txt");

            foreach (string taskFolder in Directory.EnumerateDirectories(outputFolder))
            {
                string taskId        = taskFolder.Split('\\').Last().Split('_')[0];
                string value         = taskIdNameDict[taskId];
                string speakerFolder = Path.Combine(taskFolder, "Speaker");
                var    speakerDict   = RawMapping(speakerFolder);
                var    realDict      = RawMapping(value);
                foreach (string audioPath in Directory.EnumerateFiles(speakerFolder, "*.wav"))
                {
                    string textPath = audioPath.Replace(".wav", ".txt");
                    if (!File.Exists(textPath))
                    {
                        textPath = "";
                    }
                    string audioName = audioPath.Split('\\').Last();
                    string key       = GetRawKey(audioName);
                    if (realDict.ContainsKey(key))
                    {
                        if (realDict[key] != "")
                        {
                            Sanity.Requires(LocalCommon.AudioIdenticalLocal(realDict[key], audioPath));
                        }
                        outputList.Add($"{audioPath}\t{textPath}\t{realDict[key]}\t{value}");
                    }
                    else
                    {
                        outputList.Add($"{audioPath}\t{textPath}\t\t{value}");
                    }
                }
            }
            File.WriteAllLines(outputPath, outputList);
        }
 public IEnumerable <(string, string)> GetOfflineFiles()
 {
     return(LocalCommon.GetOfflineFolder().SelectMany(x => GetOfflineFiles(x)));
 }
 public IEnumerable <(string audioId, string filePath)> GetOnlineFiles()
 {
     return(LocalCommon.GetOnlineFolders().SelectMany(x => GetOnlineFiles(x)));
 }