Exemplo n.º 1
0
        // This is a highly experimental export which may evolve as we work on this with Age of Learning.
        public void ExportAudioFiles1PerPage()
        {
            var container = System.IO.Path.Combine(System.IO.Path.GetTempPath(), "bloom audio export");

            Directory.CreateDirectory(container);
            var parentFolderForAllOfTheseExports = TemporaryFolder.TrackExisting(container);
            var folderForThisBook = new TemporaryFolder(parentFolderForAllOfTheseExports, Path.GetFileName(this.BookSelection.CurrentSelection.FolderPath));
            var pageIndex         = 0;

            foreach (XmlElement pageElement in this.BookSelection.CurrentSelection.GetPageElements())
            {
                ++pageIndex;
                //var durations = new StringBuilder();
                //var accumulatedDuration = 0;
                try
                {
                    // These elements are marked as audio-sentence but we're not sure yet if the user actually recorded them yet
                    var audioSentenceElements = HtmlDom.SelectAudioSentenceElements(pageElement)
                                                .Cast <XmlElement>();

                    var mergeFiles =
                        audioSentenceElements
                        .Select(s =>
                                AudioProcessor.GetOrCreateCompressedAudio(
                                    this.BookSelection.CurrentSelection.FolderPath, s.Attributes["id"]?.Value))
                        .Where(s => !string.IsNullOrEmpty(s));
                    if (mergeFiles.Any())
                    {
                        // enhance: it would be nice if we could somehow provide info on what should be highlighted and when,
                        // though I don't know how that would work with Age of Learning's PDF viewer.
                        // The following was a start on that before I realized that I don't know how that would be accomplished,
                        // but I'm leaving it here in case I pick it up again.
                        // foreach (var audioSentenceElement in audioSentenceElements)
                        //{
                        //	var id = HtmlDom.GetAttributeValue(audioSentenceElement, "id");
                        //	var element = this.BookSelection.CurrentSelection.OurHtmlDom.SelectSingleNode($"//div[@id='{id}']");
                        //	var duration = HtmlDom.GetAttributeValue(audioSentenceElement, "data-duration");
                        //   Here we would need to determine the duration if data-duration is empty.
                        //	accumulatedDuration += int.Parse(duration);
                        //	durations.AppendLine(accumulatedDuration.ToString() + "\t" + duration);
                        //}
                        var bookName = Path.GetFileName(this.BookSelection.CurrentSelection.FolderPath);                        // not title, that isn't sanitized to safe characters
                        var filename =
                            $"{bookName}_{this._currentlyLoadedBook.BookData.Language1.Name}_{pageIndex:0000}.mp3".Replace(' ', '_');
                        var combinedAudioPath = Path.Combine(folderForThisBook.FolderPath, filename);
                        var errorMessage      = AudioProcessor.MergeAudioFiles(mergeFiles, combinedAudioPath);
                        if (errorMessage != null)
                        {
                            File.WriteAllText(Path.Combine(folderForThisBook.FolderPath, $"error page{pageIndex}.txt"),
                                              errorMessage);
                        }
                        //File.WriteAllText(Path.Combine(folderForThisBook.FolderPath, $"page{pageIndex} timings.txt"),
                        //	durations.ToString());
                    }
                }
                catch (Exception e)
                {
                    File.WriteAllText(Path.Combine(folderForThisBook.FolderPath, $"error page{pageIndex}.txt"),
                                      e.Message);
                }
            }

            Process.Start(folderForThisBook.FolderPath);
        }
Exemplo n.º 2
0
 internal bool DoAnyNeededAudioCompression()
 {
     return(AudioProcessor.TryCompressingAudioAsNeeded(BookSelection.CurrentSelection.FolderPath, LoadBookIfNeeded().RawDom));
 }