예제 #1
0
 public static void InterleaveAndSaveIlyaFrankerMp3(
     string filenameOut,
     XmlIlyaFrankAbook xmlIlyaFrankAbook,
     double? speedChange1 = null,
     double? speedChange2 = null,
     bool reverseLanguages = false,
     Action<double> updateProgress = null)
 {
     // save mp3
     var filenameWav = UtilsCore.GetFullPathWithoutExtension(filenameOut) + ".wav"; //force .wav extension
     var result = new WavComposite(filenameWav);
     int totalSentences = xmlIlyaFrankAbook.Paragraphs.SelectMany(x => x.Sentences).Count();
     int i = 0;
     var sndInter = Settings.Default.SoundEffectInter.Replace("{ExePath}", Application.StartupPath);
     var sndOpen = Settings.Default.SoundEffectOpen.Replace("{ExePath}", Application.StartupPath);
     var sndClose = Settings.Default.SoundEffectClose.Replace("{ExePath}", Application.StartupPath);
     if (updateProgress != null)
         updateProgress(0);
     foreach (var para in xmlIlyaFrankAbook.Paragraphs) {
         if (!para.Sentences.Any())
             continue;
         foreach (var sen in para.Sentences) {
             // A-B-A-ding
             var segA = sen.Lang1Segments;
             var segB = sen.Lang2Segments;
             //var prefixA = xmlIlyaFrankAbook.Lang1Prefix;
             //var prefixB = xmlIlyaFrankAbook.Lang2Prefix;
             var speedChangeA = speedChange1;
             var speedChangeB = speedChange2;
             if (reverseLanguages) {
                 segB = sen.Lang1Segments;
                 segA = sen.Lang2Segments;
                 //prefixB = xmlIlyaFrankAbook.Lang1Prefix;
                 //prefixA = xmlIlyaFrankAbook.Lang2Prefix;
                 speedChangeB = speedChange1;
                 speedChangeA = speedChange2;
             }
             foreach (var seg in segA) {
                 //result.WritePieceOfSomeFile(mp3A, seg.TimeIn.TotalSeconds, seg.TimeOut.TotalSeconds);
                 result.WriteXmlWavEvent(seg, xmlIlyaFrankAbook.Lang1Prefix, xmlIlyaFrankAbook.Lang2Prefix, speedChangeA);
             }
             foreach (var seg in segB) {
                 //result.WritePieceOfSomeFile(mp3B, seg.TimeIn.TotalSeconds, seg.TimeOut.TotalSeconds);
                 result.WriteXmlWavEvent(seg, xmlIlyaFrankAbook.Lang1Prefix, xmlIlyaFrankAbook.Lang2Prefix, speedChangeB);
             }
             foreach (var seg in segA) {
                 //result.WritePieceOfSomeFile(mp3A, seg.TimeIn.TotalSeconds, seg.TimeOut.TotalSeconds);
                 result.WriteXmlWavEvent(seg, xmlIlyaFrankAbook.Lang1Prefix, xmlIlyaFrankAbook.Lang2Prefix, speedChangeA);
             }
             result.AppendAllOfFile(
                 sndInter,
                 (Settings.Default.SoundEffectFactor != 0) ? (double?)Settings.Default.SoundEffectFactor : null
             );
             i++;
         }
         // ding-AAA-ding
         result.AppendAllOfFile(
             sndOpen,
             (Settings.Default.SoundEffectFactor != 0) ? (double?)Settings.Default.SoundEffectFactor : null
         );
         foreach (var sen in para.Sentences) {
             var segA1 = sen.Lang1Segments;
             //var prefixA = xmlIlyaFrankAbook.Lang1Prefix;
             //var prefixB = xmlIlyaFrankAbook.Lang2Prefix;
             var speedChangeA = speedChange1;
             if (reverseLanguages) {
                 segA1 = sen.Lang2Segments;
                 //prefixB = xmlIlyaFrankAbook.Lang1Prefix;
                 //prefixA = xmlIlyaFrankAbook.Lang2Prefix;
                 speedChangeA = speedChange2;
             }
             foreach (var seg in segA1) {
                 //result.WritePieceOfSomeFile(mp3A, seg.TimeIn.TotalSeconds, seg.TimeOut.TotalSeconds);
                 result.WriteXmlWavEvent(seg, xmlIlyaFrankAbook.Lang1Prefix, xmlIlyaFrankAbook.Lang2Prefix, speedChangeA);
             }
         }
         result.AppendAllOfFile(
             sndClose,
             (Settings.Default.SoundEffectFactor != 0) ? (double?)Settings.Default.SoundEffectFactor : null
         );
     }
     result.Close();
 }
예제 #2
0
        //private List<XmlWavEvent> pendingRussian;
        public LogicShit(AudioRecManager recMan)
        {
            this.recMan = recMan;
            FilenameFormat = DumpFolder + "/segment_{0}.wav";

            #region FSM with XML

            fsmWithXml = new FSM<Keys>()
                .addNode_0_(LogicState.Ready)
                .addEdge___(Keys.Enter, LogicState.DeqedLang1, (args) => {
                    IlyaXml = new XmlIlyaFrankAbook() {
                        Lang1Mp3Filename = Lang1Mp3,
                        Lang1Prefix = AudioBooker.classes.UtilsCore.GetFullPathWithoutExtension(Lang1Mp3)
                    };
                    new_paragraph();
                    nextLang1Phrase();
                    readCurLang1Phrase();
                    FireHandler(CurParagraphUpdated);
                })
                .addNode_0_(LogicState.DeqedLang1)
                .addEdge___(Keys.R, LogicState.DeqedLang1, (args) => readCurLang1Phrase())
                .addEdge___(Keys.P, LogicState.DeqedLang1, (args) => {
                    purgeParaAllExceptLast();
                    FireHandler(CurParagraphUpdated);
                })
                .addEdge___(Keys.Space, LogicState.Recording1st, (args) => {
                    startSegment();
                    FireHandler(CurSegmentUpdated);
                    FireHandler(CurParagraphUpdated);
                })
                .addNode_0_(LogicState.Recording1st)
                .addEdge___(Keys.R, LogicState.Recording1st, (args) => readCurLang1Phrase())
                .addEdge___(Keys.P, LogicState.DeqedLang1, (args) => {
                    purgeParaAllExceptLast();
                    stopAndDeleteSegment();
                    FireHandler(CurSegmentUpdated);
                    FireHandler(CurParagraphUpdated);
                })
                .addEdge___(Keys.Back, LogicState.Recording1st, (args) => {
                    stopAndDeleteSegment();
                    startSegment();
                    FireHandler(CurSegmentUpdated);
                })
                .addEdge___(Keys.Space, LogicState.RecordingMore, (args) => {
                    commitSegment();
                    startSegment();
                    FireHandler(CurParagraphUpdated);
                    FireHandler(CurSegmentUpdated);
                })
                .addNode_0_(LogicState.RecordingMore)
                .addEdge___(Keys.R, LogicState.RecordingMore, (args) => readCurLang1Phrase())
                .addEdge___(Keys.Back, LogicState.RecordingMore, (args) => {
                    stopAndDeleteSegment();
                    startSegment();
                    FireHandler(CurSegmentUpdated);
                })
                .addEdge___(Keys.Space, LogicState.RecordingMore, (args) => {
                    commitSegment();
                    startSegment();
                    FireHandler(CurParagraphUpdated);
                    FireHandler(CurSegmentUpdated);
                })
                .addEdge___(Keys.D1, LogicState.RecordingMore, (args) => {
                    stopAndDeleteSegment();
                    RecordedSegments = CurIlyaSentence.Lang1Segments;
                    startSegment();
                    FireHandler(CurParagraphUpdated);
                    FireHandler(CurSegmentUpdated);
                })
                .addEdge___(Keys.D2, LogicState.RecordingMore, (args) => {
                    stopAndDeleteSegment();
                    RecordedSegments = CurIlyaSentence.Lang2Segments;
                    startSegment();
                    FireHandler(CurParagraphUpdated);
                    FireHandler(CurSegmentUpdated);
                })
                .addEdge___(Keys.Enter, LogicState.DeqedLang1, (args) => {
                    stopAndDeleteSegment();
                    nextLang1Phrase();
                    readCurLang1Phrase();
                    FireHandler(CurSegmentUpdated);
                    FireHandler(CurParagraphUpdated);
                })
                .addEdge___(Keys.P, LogicState.CommitedParagraph, (args) => {
                    stopAndDeleteSegment();
                    new_paragraph();
                    FireHandler(CurSegmentUpdated);
                    FireHandler(CurParagraphUpdated);
                })
                .addNode_0_(LogicState.CommitedParagraph)
                .addEdge___(Keys.Enter, LogicState.DeqedLang1, (args) => {
                    nextLang1Phrase();
                    readCurLang1Phrase();
                    FireHandler(CurSegmentUpdated);
                    FireHandler(CurParagraphUpdated);
                })
            ;
            fsmWithXml.Reset();

            #endregion

            #region FSM manual split

            fsmManualSplit = new FSM<Keys>()
                .addNode_0_(LogicState.Ready)
                .addEdge___(Keys.Enter, LogicState.DeqingLang1, (args) => {
                    IlyaXml = new XmlIlyaFrankAbook() {
                        Lang1Mp3Filename = Path.GetFileName(Lang1Mp3),
                        Lang1Prefix = Path.GetDirectoryName(Lang1Mp3)
                    };
                    new_paragraph();
                    AudioPlaya = new AudioPlaya(Lang1Mp3);
                    AudioPlaya.Play();
                })
                .addNode_0_(LogicState.DeqingLang1)
                .addEdge___(Keys.OemPeriod, LogicState.DeqingLang1, (args) => {
                    AudioPlaya.Pause();
                    AudioPlaya.Position += TimeSpan.FromSeconds(5);
                    AudioPlaya.Play();
                })
                .addEdge___(Keys.Oemcomma, LogicState.DeqingLang1, (args) => {
                    AudioPlaya.Pause();
                    AudioPlaya.Position -= TimeSpan.FromSeconds(5);
                    AudioPlaya.Play();
                })
                .addEdge___(Keys.Space, LogicState.DeqingLang1, (args) => {
                    ManualSegmentA = AudioPlaya.Position;
                })
                .addEdge___(Keys.Enter, LogicState.DeqedLang1, (args) => {
                    ManualSegmentB = AudioPlaya.Position;
                    AudioPlaya.Pause();
                    nextLang1Phrase_manual();
                    readCurLang1Phrase();
                    FireHandler(CurParagraphUpdated);
                })
                .addNode_0_(LogicState.DeqedLang1)
                .addEdge___(Keys.R, LogicState.DeqedLang1, (args) => readCurLang1Phrase())
                .addEdge___(Keys.P, LogicState.DeqedLang1, (args) => {
                    purgeParaAllExceptLast();
                    FireHandler(CurParagraphUpdated);
                })
                .addEdge___(Keys.Space, LogicState.Recording1st, (args) => {
                    startSegment();
                    FireHandler(CurSegmentUpdated);
                    FireHandler(CurParagraphUpdated);
                })
                .addNode_0_(LogicState.Recording1st)
                .addEdge___(Keys.R, LogicState.Recording1st, (args) => readCurLang1Phrase())
                .addEdge___(Keys.P, LogicState.DeqedLang1, (args) => {
                    purgeParaAllExceptLast();
                    stopAndDeleteSegment();
                    FireHandler(CurSegmentUpdated);
                    FireHandler(CurParagraphUpdated);
                })
                .addEdge___(Keys.Back, LogicState.Recording1st, (args) => {
                    stopAndDeleteSegment();
                    startSegment();
                    FireHandler(CurSegmentUpdated);
                })
                .addEdge___(Keys.Space, LogicState.RecordingMore, (args) => {
                    commitSegment();
                    startSegment();
                    FireHandler(CurParagraphUpdated);
                    FireHandler(CurSegmentUpdated);
                })
                .addNode_0_(LogicState.RecordingMore)
                .addEdge___(Keys.R, LogicState.RecordingMore, (args) => readCurLang1Phrase())
                .addEdge___(Keys.Back, LogicState.RecordingMore, (args) => {
                    stopAndDeleteSegment();
                    startSegment();
                    FireHandler(CurSegmentUpdated);
                })
                .addEdge___(Keys.Space, LogicState.RecordingMore, (args) => {
                    commitSegment();
                    startSegment();
                    FireHandler(CurParagraphUpdated);
                    FireHandler(CurSegmentUpdated);
                })
                .addEdge___(Keys.D1, LogicState.RecordingMore, (args) => {
                    stopAndDeleteSegment();
                    RecordedSegments = CurIlyaSentence.Lang1Segments;
                    startSegment();
                    FireHandler(CurParagraphUpdated);
                    FireHandler(CurSegmentUpdated);
                })
                .addEdge___(Keys.D2, LogicState.RecordingMore, (args) => {
                    stopAndDeleteSegment();
                    RecordedSegments = CurIlyaSentence.Lang2Segments;
                    startSegment();
                    FireHandler(CurParagraphUpdated);
                    FireHandler(CurSegmentUpdated);
                })
                .addEdge___(Keys.Enter, LogicState.DeqingLang1, (args) => {
                    stopAndDeleteSegment();
                    ManualSegmentA = AudioPlaya.Position;
                    AudioPlaya.Play();
                    FireHandler(CurSegmentUpdated);
                    FireHandler(CurParagraphUpdated);
                })
                .addEdge___(Keys.P, LogicState.CommitedParagraph, (args) => {
                    stopAndDeleteSegment();
                    new_paragraph();
                    FireHandler(CurSegmentUpdated);
                    FireHandler(CurParagraphUpdated);
                })
                .addNode_0_(LogicState.CommitedParagraph)
                .addEdge___(Keys.Enter, LogicState.DeqingLang1, (args) => {
                    ManualSegmentA = AudioPlaya.Position;
                    AudioPlaya.Play();
                    FireHandler(CurSegmentUpdated);
                    FireHandler(CurParagraphUpdated);
                })
            ;
            fsmManualSplit.Reset();

            #endregion
        }
예제 #3
0
 public void startRecording()
 {
     if (recorder.State != IRecorderState.Paused)
         xml = new XmlIlyaFrankAbook();
     //startSegment();
 }
예제 #4
0
        public static void InterleaveAndSaveIlyaFrankerMp3(
            string filenameOut,
            XmlIlyaFrankAbook xmlIlyaFrankAbook,
            double?speedChange1            = null,
            double?speedChange2            = null,
            bool reverseLanguages          = false,
            Action <double> updateProgress = null)
        {
            // save mp3
            var filenameWav    = UtilsCore.GetFullPathWithoutExtension(filenameOut) + ".wav"; //force .wav extension
            var result         = new WavComposite(filenameWav);
            int totalSentences = xmlIlyaFrankAbook.Paragraphs.SelectMany(x => x.Sentences).Count();
            int i        = 0;
            var sndInter = Settings.Default.SoundEffectInter.Replace("{ExePath}", Application.StartupPath);
            var sndOpen  = Settings.Default.SoundEffectOpen.Replace("{ExePath}", Application.StartupPath);
            var sndClose = Settings.Default.SoundEffectClose.Replace("{ExePath}", Application.StartupPath);

            if (updateProgress != null)
            {
                updateProgress(0);
            }
            foreach (var para in xmlIlyaFrankAbook.Paragraphs)
            {
                if (!para.Sentences.Any())
                {
                    continue;
                }
                foreach (var sen in para.Sentences)
                {
                    // A-B-A-ding
                    var segA = sen.Lang1Segments;
                    var segB = sen.Lang2Segments;
                    //var prefixA = xmlIlyaFrankAbook.Lang1Prefix;
                    //var prefixB = xmlIlyaFrankAbook.Lang2Prefix;
                    var speedChangeA = speedChange1;
                    var speedChangeB = speedChange2;
                    if (reverseLanguages)
                    {
                        segB = sen.Lang1Segments;
                        segA = sen.Lang2Segments;
                        //prefixB = xmlIlyaFrankAbook.Lang1Prefix;
                        //prefixA = xmlIlyaFrankAbook.Lang2Prefix;
                        speedChangeB = speedChange1;
                        speedChangeA = speedChange2;
                    }
                    foreach (var seg in segA)
                    {
                        //result.WritePieceOfSomeFile(mp3A, seg.TimeIn.TotalSeconds, seg.TimeOut.TotalSeconds);
                        result.WriteXmlWavEvent(seg, xmlIlyaFrankAbook.Lang1Prefix, xmlIlyaFrankAbook.Lang2Prefix, speedChangeA);
                    }
                    foreach (var seg in segB)
                    {
                        //result.WritePieceOfSomeFile(mp3B, seg.TimeIn.TotalSeconds, seg.TimeOut.TotalSeconds);
                        result.WriteXmlWavEvent(seg, xmlIlyaFrankAbook.Lang1Prefix, xmlIlyaFrankAbook.Lang2Prefix, speedChangeB);
                    }
                    foreach (var seg in segA)
                    {
                        //result.WritePieceOfSomeFile(mp3A, seg.TimeIn.TotalSeconds, seg.TimeOut.TotalSeconds);
                        result.WriteXmlWavEvent(seg, xmlIlyaFrankAbook.Lang1Prefix, xmlIlyaFrankAbook.Lang2Prefix, speedChangeA);
                    }
                    result.AppendAllOfFile(
                        sndInter,
                        (Settings.Default.SoundEffectFactor != 0) ? (double?)Settings.Default.SoundEffectFactor : null
                        );
                    i++;
                }
                // ding-AAA-ding
                result.AppendAllOfFile(
                    sndOpen,
                    (Settings.Default.SoundEffectFactor != 0) ? (double?)Settings.Default.SoundEffectFactor : null
                    );
                foreach (var sen in para.Sentences)
                {
                    var segA1 = sen.Lang1Segments;
                    //var prefixA = xmlIlyaFrankAbook.Lang1Prefix;
                    //var prefixB = xmlIlyaFrankAbook.Lang2Prefix;
                    var speedChangeA = speedChange1;
                    if (reverseLanguages)
                    {
                        segA1 = sen.Lang2Segments;
                        //prefixB = xmlIlyaFrankAbook.Lang1Prefix;
                        //prefixA = xmlIlyaFrankAbook.Lang2Prefix;
                        speedChangeA = speedChange2;
                    }
                    foreach (var seg in segA1)
                    {
                        //result.WritePieceOfSomeFile(mp3A, seg.TimeIn.TotalSeconds, seg.TimeOut.TotalSeconds);
                        result.WriteXmlWavEvent(seg, xmlIlyaFrankAbook.Lang1Prefix, xmlIlyaFrankAbook.Lang2Prefix, speedChangeA);
                    }
                }
                result.AppendAllOfFile(
                    sndClose,
                    (Settings.Default.SoundEffectFactor != 0) ? (double?)Settings.Default.SoundEffectFactor : null
                    );
            }
            result.Close();
        }