private void CmdSaveAs_Executed(object sender, ExecutedRoutedEventArgs e) { var para = e.Parameter.ToString(); if (para == "srt") { StringBuilder sb = new StringBuilder(); int index = 1; foreach (var sentence in this.ContentDocument.Sentences) { if (sentence.BeginTime >= sentence.EndTime) { continue; } sb.AppendLine(index.ToString()); var timeString = string.Format("{0} --> {1}", sentence.BeginTime.ToString().Replace('.', ','), sentence.EndTime.ToString().Replace('.', ',')); sb.AppendLine(timeString); sb.AppendLine(sentence.Translation); sb.AppendLine(); index += 1; } File.WriteAllText(this.SrtFilePath, sb.ToString(), Encoding.Unicode); } else { Lyrics lrc = new Lyrics() { NeedSort = true }; foreach (var sentence in this.ContentDocument.Sentences) { if (sentence.BeginTime >= sentence.EndTime) { continue; } var phrase = new LyricsPhrase() { Text = sentence.Translation, BeginTime = sentence.BeginTime, EndTime = sentence.EndTime }; lrc.Phrases.Add(phrase); } lrc.Save(this.LyricsFilePath); } }
static void Main(string[] args) { string currentFilePath = ""; args = new string[1] { Path.Combine(Environment.CurrentDirectory, "SGTV.wav") }; if (args != null && args.Length > 0) { var str = args[0]; Console.WriteLine("Args : " + str); var waveFile = str + ".wav";// str.ToLower().Replace(".mp3", ".wav"); var lrcFile = str + ".lrc"; currentFilePath = str + ".xml"; if (File.Exists(currentFilePath) == true) { Console.WriteLine("xml file is E"); DMDocument doc = DMDocument.Load(currentFilePath); Lyrics lrc = new Lyrics(); foreach (var sentence in doc.Sentences) { LyricsPhrase phrase = new LyricsPhrase() { BeginTime = sentence.BeginTime, EndTime = sentence.EndTime, Text = sentence.Text }; lrc.Phrases.Add(phrase); } lrc.Save(lrcFile); } else { WaveDecoder wd = new WaveDecoder(); wd.ProcessForRecognize(str, waveFile); DictationSyncEngine engine = new DictationSyncEngine("en-US"); engine.SentenceRecognized += engine_SentenceRecognized; engine.RecognizeCompleted += engine_RecognizeCompleted; engine.Process(waveFile); } } else { Console.WriteLine("Args is null!"); } Console.ReadLine(); }