Skip to content

Commit

Permalink
#51 ストリーム周りの修正
Browse files Browse the repository at this point in the history
  • Loading branch information
aiueo-1234 committed May 3, 2024
1 parent a984402 commit 8a6b5d3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
4 changes: 1 addition & 3 deletions Epub/KoeBook.Epub/Services/EpubGenerateService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ public async ValueTask<string> GenerateEpubAsync(BookScripts bookScripts, string
{
var scriptLine = bookScripts.ScriptLines[i];
var wavData = await _soundGenerationService.GenerateLineSoundAsync(scriptLine, bookScripts.Options, cancellationToken).ConfigureAwait(false);
var ms = new MemoryStream();
ms.Write(wavData);
ms.Position = 0;
using var ms = new MemoryStream(wavData);
using var reader = new WaveFileReader(ms);
var tmpMp3Path = Path.Combine(tempDirectory, $"{document.Title}{i}.mp3");
MediaFoundationEncoder.EncodeToMp3(reader, tmpMp3Path);
Expand Down
5 changes: 3 additions & 2 deletions KoeBook.Core/Models/Audio.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using NAudio.Wave;
using System.IO;
using NAudio.Wave;

namespace KoeBook.Epub.Models;

Expand All @@ -9,6 +10,6 @@ public sealed class Audio(TimeSpan totalTIme, string tempFilePath)

public FileStream GetStream()
{
return File.OpenRead(TempFilePath);
return new FileStream(TempFilePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, true);
}
}
4 changes: 1 addition & 3 deletions KoeBook.Core/Services/SoundGenerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ public async ValueTask<byte[]> GenerateLineSoundAsync(ScriptLine scriptLine, Boo
ArrayPool<byte>.Shared.Return(dataBuffer);
dataBuffer = ArrayPool<byte>.Shared.Rent(voice.Length);
}
using var msReader = new MemoryStream();
await msReader.WriteAsync(voice, cancellationToken);
msReader.Position = 0;
using var msReader = new MemoryStream(voice);
using var reader = new WaveFileReader(msReader);
var read = await reader.ReadAsync(dataBuffer, cancellationToken);
if (writer is null)
Expand Down

0 comments on commit 8a6b5d3

Please sign in to comment.