|
8 | 8 | using Microsoft.AspNetCore.Mvc; |
9 | 9 | using Microsoft.VisualBasic.FileIO; |
10 | 10 | using NAudio.Lame; |
11 | | -using NAudio.Wave; |
| 11 | +using SimaiSharp; |
12 | 12 | using Vanara.Windows.Forms; |
| 13 | +using Xabe.FFmpeg; |
13 | 14 | using FolderBrowserDialog = System.Windows.Forms.FolderBrowserDialog; |
14 | 15 |
|
15 | 16 | namespace MaiChartManager.Controllers.Music; |
@@ -548,26 +549,13 @@ public async Task ExportAsMaidata(int id, string assetDir, bool ignoreVideo = fa |
548 | 549 | await using var zipStream = HttpContext.Response.BodyWriter.AsStream(); |
549 | 550 | using var zipArchive = new ZipArchive(zipStream, ZipArchiveMode.Create, leaveOpen: true); |
550 | 551 |
|
551 | | - // 计算由于WAV转MP3导致的音频开头增加的空白段的长度,以便稍后通过&first参数给予修正。 |
552 | | - // 具体的情况和原理,详见https://github.com/MuNET-OSS/MaiChartManager/issues/40 |
553 | | - var wavPath = await AudioConvert.GetCachedWavPath(GetAudioCandidateIds(music)); |
554 | | - if (wavPath is null) |
555 | | - { |
556 | | - var message = BuildAudioResolveErrorMessage(music); |
557 | | - logger.LogError("{message}", message); |
558 | | - throw new FileNotFoundException(message); |
559 | | - } |
560 | | - using var wavReader = new WaveFileReader(wavPath); |
561 | | - // 根据上面issue中的结论,wav转mp3引起的开头空白段的长度为1728采样点 |
562 | | - var audioDelay = 1728 / (double)wavReader.WaveFormat.SampleRate; |
563 | | - |
564 | 552 | Ma2Parser parser = new(); |
565 | 553 | var simaiFile = new StringBuilder(); |
566 | 554 |
|
567 | 555 | simaiFile.AppendLine($"&title={music.Name}"); |
568 | 556 | simaiFile.AppendLine($"&artist={music.Artist}"); |
569 | 557 | simaiFile.AppendLine($"&wholebpm={music.Bpm}"); |
570 | | - simaiFile.AppendLine($"&first={audioDelay:0.####}"); |
| 558 | + simaiFile.AppendLine("&first=0.0333"); |
571 | 559 | simaiFile.AppendLine($"&shortid={music.Id}"); |
572 | 560 | simaiFile.AppendLine($"&genreid={music.GenreId}"); |
573 | 561 | var genre = StaticSettings.GenreList.FirstOrDefault(it => it.Id == music.GenreId); |
@@ -646,10 +634,16 @@ public async Task ExportAsMaidata(int id, string assetDir, bool ignoreVideo = fa |
646 | 634 | Comment = version?.GenreName, |
647 | 635 | AlbumArt = img, |
648 | 636 | }; |
| 637 | + var wavPath = await AudioConvert.GetCachedWavPath(GetAudioCandidateIds(music)); |
| 638 | + if (wavPath is null) |
| 639 | + { |
| 640 | + var message = BuildAudioResolveErrorMessage(music); |
| 641 | + logger.LogError("{message}", message); |
| 642 | + throw new FileNotFoundException(message); |
| 643 | + } |
649 | 644 |
|
650 | | - AudioConvert.ConvertWavToMp3Stream(wavReader, soundStream, tag); |
| 645 | + AudioConvert.ConvertWavPathToMp3Stream(wavPath, soundStream, tag); |
651 | 646 | soundStream.Close(); |
652 | | - wavReader.Close(); |
653 | 647 |
|
654 | 648 | if (!ignoreVideo && StaticSettings.MovieDataMap.TryGetValue(music.NonDxId, out var movieUsmPath)) |
655 | 649 | { |
|
0 commit comments