/// <summary> /// 切割mp3 /// </summary> /// <param name="mp3"></param> /// <param name="mp3FilePath"></param> /// <param name="savePath"></param> public void SplitMP3(MP3Info mp3, string mp3FilePath, string savePath) { Process ffmpegProcess = new Process(); ffmpegProcess.StartInfo.UseShellExecute = false; ffmpegProcess.StartInfo.ErrorDialog = true; ffmpegProcess.StartInfo.CreateNoWindow = true; ffmpegProcess.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + "/ffmpeg/ffmpeg.exe"; string beginTime = ToHourTime(mp3.StartTime).ToString("HH:mm:ss.fff"); string endTime; if (string.IsNullOrEmpty(mp3.NextPosTime)) { Shell32.ShellClass sc = new Shell32.ShellClass(); var fd = sc.NameSpace(Path.GetDirectoryName(mp3FilePath)); var item = fd.ParseName(Path.GetFileName(mp3FilePath)); mp3.NextPosTime = fd.GetDetailsOf(item, 27).Substring(3) + ".00"; } endTime = GetSplitTime(ToHourTime(mp3.NextPosTime).AddSeconds(-0.2) - ToHourTime(mp3.StartTime));//尾部去除部分衔接静音(这里是0.2秒) ffmpegProcess.StartInfo.Arguments = "-y -i " + mp3FilePath + " -ss " + mp3.StartTime + " -t " + endTime + " -acodec copy " + savePath + "/" + mp3.Name + ".mp3"; ffmpegProcess.Start(); ffmpegProcess.WaitForExit(); }
/// <summary> /// 读取MP3歌词列表(每行一句,每句一个对象) /// </summary> /// <returns></returns> public List<MP3Info> GetMp3List() { if (!File.Exists(lrcPath)) { throw new FileNotFoundException("文件不存在!"); } //[00:38.10]ちゅうごくじん 〔名〕 中国人 var regexLine = new Regex(@"^\[\d{2}:\d{2}\.\d{1,}\](?<lyric>\S+)\s*.*");//截取歌词内容 var regexTime = new Regex(@"^\[(?<time>\d{2}:\d{2}\.\d{1,})\].*");//截取开始时间 //读取Lrc using (StreamReader sr = new StreamReader(lrcPath, System.Text.Encoding.GetEncoding("gb2312"))) { string line; while ((line = sr.ReadLine()) != null) { var groups = regexLine.Match(line).Groups; if (groups != null && groups["lyric"].Success) { //特别处理 if (line.Contains("---")) { continue; } var word = groups["lyric"].ToString(); if (!WordTable.ContainsKey(word)) { continue; } var pos = new MP3Info(); pos.Name = "w" + WordTable[word].ToString(); pos.StartTime = regexTime.Match(line).Groups["time"].ToString(); int i = MP3LrcList.Count - 1;//上一句歌词 MP3LrcList.Add(pos); //修改上句歌词的结局时间为当前歌词的开始时间 if (i > -1) { MP3LrcList[i].NextPosTime = pos.StartTime; } } } } return MP3LrcList; }