From 2db6811e92433589e88fb5e92510282b6a891129 Mon Sep 17 00:00:00 2001
From: herring101 <81513223+herring101@users.noreply.github.com>
Date: Thu, 22 Feb 2024 13:43:52 +0900
Subject: [PATCH 1/4] =?UTF-8?q?TTS=E5=91=A8=E3=82=8A=E3=81=AE=E3=82=A4?=
=?UTF-8?q?=E3=83=B3=E3=82=BF=E3=83=BC=E3=83=95=E3=82=A7=E3=83=BC=E3=82=B9?=
=?UTF-8?q?=E3=83=BB=E3=83=A2=E3=83=83=E3=82=AF=E4=BD=9C=E6=88=90?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../Contracts/Services/ISoundGeneration.cs | 15 +++++++++++++++
.../ISoundGenerationSelectorService.cs | 13 +++++++++++++
.../Services/Mocks/SoundGenerationMock.cs | 16 ++++++++++++++++
.../SoundGenerationSelectorServiceMock.cs | 18 ++++++++++++++++++
4 files changed, 62 insertions(+)
create mode 100644 KoeBook.Core/Contracts/Services/ISoundGeneration.cs
create mode 100644 KoeBook.Core/Contracts/Services/ISoundGenerationSelectorService.cs
create mode 100644 KoeBook/Contracts/Services/Mocks/SoundGenerationMock.cs
create mode 100644 KoeBook/Contracts/Services/Mocks/SoundGenerationSelectorServiceMock.cs
diff --git a/KoeBook.Core/Contracts/Services/ISoundGeneration.cs b/KoeBook.Core/Contracts/Services/ISoundGeneration.cs
new file mode 100644
index 0000000..4a8f3c7
--- /dev/null
+++ b/KoeBook.Core/Contracts/Services/ISoundGeneration.cs
@@ -0,0 +1,15 @@
+using KoeBook.Core.Models;
+
+namespace KoeBook.Core.Contracts.Services;
+
+internal interface ISoundGeneration
+{
+ ///
+ /// 1文の音声を生成します
+ ///
+ ///
+ ///
+ ///
+ ///
+ ValueTask GenerateLineSoundAsync(ScriptLine scriptLine, BookOptions bookOptions, CancellationToken cancellationToken);
+}
diff --git a/KoeBook.Core/Contracts/Services/ISoundGenerationSelectorService.cs b/KoeBook.Core/Contracts/Services/ISoundGenerationSelectorService.cs
new file mode 100644
index 0000000..d88868f
--- /dev/null
+++ b/KoeBook.Core/Contracts/Services/ISoundGenerationSelectorService.cs
@@ -0,0 +1,13 @@
+namespace KoeBook.Core.Contracts.Services;
+
+public interface ISoundGenerationSelectorService
+{
+ ///
+ /// サウンドモデル・スタイルの一覧
+ ///
+ public IReadOnlyList Models { get; }
+
+ public ValueTask InitializeAsync(CancellationToken cancellationToken);
+}
+
+public record SoundModel(string name, string[] styles);
diff --git a/KoeBook/Contracts/Services/Mocks/SoundGenerationMock.cs b/KoeBook/Contracts/Services/Mocks/SoundGenerationMock.cs
new file mode 100644
index 0000000..626af33
--- /dev/null
+++ b/KoeBook/Contracts/Services/Mocks/SoundGenerationMock.cs
@@ -0,0 +1,16 @@
+using KoeBook.Core.Models;
+
+namespace KoeBook.Contracts.Services.Mocks;
+
+internal class SoundGenerationMock
+{
+ public async ValueTask GenerateLineSoundAsync(ScriptLine scriptLine, BookOptions bookOptions, CancellationToken cancellationToken)
+ {
+ await Task.Delay(1000, cancellationToken);
+ // 適当なバイト列を返す
+ var random = new Random();
+ var buffer = new byte[44100 * 2];
+ random.NextBytes(buffer);
+ return buffer;
+ }
+}
diff --git a/KoeBook/Contracts/Services/Mocks/SoundGenerationSelectorServiceMock.cs b/KoeBook/Contracts/Services/Mocks/SoundGenerationSelectorServiceMock.cs
new file mode 100644
index 0000000..31842d3
--- /dev/null
+++ b/KoeBook/Contracts/Services/Mocks/SoundGenerationSelectorServiceMock.cs
@@ -0,0 +1,18 @@
+using KoeBook.Core.Contracts.Services;
+
+namespace KoeBook.Contracts.Services.Mocks;
+
+internal class SoundGenerationSelectorServiceMock : ISoundGenerationSelectorService
+{
+ public IReadOnlyList Models { get; private set; } = Array.Empty();
+
+ public async ValueTask InitializeAsync(CancellationToken cancellationToken)
+ {
+ await Task.Delay(1000, cancellationToken);
+ Models = [
+ new SoundModel("メロス",["narration", "neutral", "laughing", "happy", "sad", "cry", "surprised", "angry" ]),
+ new SoundModel("老爺",["narration", "neutral", "laughing", "happy", "sad", "cry", "surprised", "angry" ]),
+ new SoundModel("王",["narration", "neutral", "laughing", "happy", "sad", "cry", "surprised", "angry" ]),
+ ];
+ }
+}
From cee38b9a701088745783e9788bd2a398b180e320 Mon Sep 17 00:00:00 2001
From: miyaji255 <84168445+miyaji255@users.noreply.github.com>
Date: Thu, 22 Feb 2024 14:58:29 +0900
Subject: [PATCH 2/4] =?UTF-8?q?#27=20=E3=83=A2=E3=83=83=E3=82=AF=E3=81=AE?=
=?UTF-8?q?=E5=90=8D=E5=89=8D=E3=80=81=E4=BD=8D=E7=BD=AE=E3=81=AE=E4=BF=AE?=
=?UTF-8?q?=E6=AD=A3?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../ISoundGenerationSelectorService.cs | 6 ++---
...neration.cs => ISoundGenerationService.cs} | 2 +-
KoeBook.Core/KoeBook.Core.csproj | 2 +-
KoeBook.Core/Models/SoundModel.cs | 5 +++++
.../SoundGenerationSelectorServiceMock.cs | 22 +++++++++++++++++++
.../Mocks/SoundGenerationServiceMock.cs | 9 ++++----
KoeBook/App.xaml.cs | 11 ++++++++--
.../SoundGenerationSelectorServiceMock.cs | 18 ---------------
KoeBook/KoeBook.csproj | 4 ----
KoeBook/Models/MockOptions.cs | 8 +++++++
.../SoundGenerationSelectorServiceMock.cs | 19 ++++++++++++++++
KoeBook/appsettings.json | 10 ++++++---
12 files changed, 80 insertions(+), 36 deletions(-)
rename KoeBook.Core/Contracts/Services/{ISoundGeneration.cs => ISoundGenerationService.cs} (91%)
create mode 100644 KoeBook.Core/Models/SoundModel.cs
create mode 100644 KoeBook.Core/Services/Mocks/SoundGenerationSelectorServiceMock.cs
rename KoeBook/Contracts/Services/Mocks/SoundGenerationMock.cs => KoeBook.Core/Services/Mocks/SoundGenerationServiceMock.cs (57%)
delete mode 100644 KoeBook/Contracts/Services/Mocks/SoundGenerationSelectorServiceMock.cs
create mode 100644 KoeBook/Models/MockOptions.cs
create mode 100644 KoeBook/Services/CoreMocks/SoundGenerationSelectorServiceMock.cs
diff --git a/KoeBook.Core/Contracts/Services/ISoundGenerationSelectorService.cs b/KoeBook.Core/Contracts/Services/ISoundGenerationSelectorService.cs
index d88868f..ee95559 100644
--- a/KoeBook.Core/Contracts/Services/ISoundGenerationSelectorService.cs
+++ b/KoeBook.Core/Contracts/Services/ISoundGenerationSelectorService.cs
@@ -1,4 +1,6 @@
-namespace KoeBook.Core.Contracts.Services;
+using KoeBook.Core.Models;
+
+namespace KoeBook.Core.Contracts.Services;
public interface ISoundGenerationSelectorService
{
@@ -9,5 +11,3 @@ public interface ISoundGenerationSelectorService
public ValueTask InitializeAsync(CancellationToken cancellationToken);
}
-
-public record SoundModel(string name, string[] styles);
diff --git a/KoeBook.Core/Contracts/Services/ISoundGeneration.cs b/KoeBook.Core/Contracts/Services/ISoundGenerationService.cs
similarity index 91%
rename from KoeBook.Core/Contracts/Services/ISoundGeneration.cs
rename to KoeBook.Core/Contracts/Services/ISoundGenerationService.cs
index 4a8f3c7..4c8836d 100644
--- a/KoeBook.Core/Contracts/Services/ISoundGeneration.cs
+++ b/KoeBook.Core/Contracts/Services/ISoundGenerationService.cs
@@ -2,7 +2,7 @@
namespace KoeBook.Core.Contracts.Services;
-internal interface ISoundGeneration
+public interface ISoundGenerationService
{
///
/// 1文の音声を生成します
diff --git a/KoeBook.Core/KoeBook.Core.csproj b/KoeBook.Core/KoeBook.Core.csproj
index 0c399d6..2386f06 100644
--- a/KoeBook.Core/KoeBook.Core.csproj
+++ b/KoeBook.Core/KoeBook.Core.csproj
@@ -1,4 +1,4 @@
-
+
net8.0
KoeBook.Core
diff --git a/KoeBook.Core/Models/SoundModel.cs b/KoeBook.Core/Models/SoundModel.cs
new file mode 100644
index 0000000..93b6efa
--- /dev/null
+++ b/KoeBook.Core/Models/SoundModel.cs
@@ -0,0 +1,5 @@
+namespace KoeBook.Core.Models;
+
+public record SoundModel(
+ string name,
+ IReadOnlyList styles);
diff --git a/KoeBook.Core/Services/Mocks/SoundGenerationSelectorServiceMock.cs b/KoeBook.Core/Services/Mocks/SoundGenerationSelectorServiceMock.cs
new file mode 100644
index 0000000..c78ccd8
--- /dev/null
+++ b/KoeBook.Core/Services/Mocks/SoundGenerationSelectorServiceMock.cs
@@ -0,0 +1,22 @@
+using KoeBook.Core.Contracts.Services;
+using KoeBook.Core.Models;
+
+namespace KoeBook.Core.Services.Mocks;
+
+internal class SoundGenerationSelectorServiceMock : ISoundGenerationSelectorService
+{
+ public IReadOnlyList Models { get; private set; } = [];
+
+ public async ValueTask InitializeAsync(CancellationToken cancellationToken)
+ {
+ await Task.Delay(1000, cancellationToken).ConfigureAwait(false);
+ Models = [
+ new SoundModel("青年1", ["neutral", "laughing", "happy", "sad", "cry", "surprised", "angry"]),
+ new SoundModel("青年2", ["neutral", "laughing", "happy", "sad", "cry", "surprised", "angry"]),
+ new SoundModel("女性1", ["neutral", "laughing", "happy", "sad", "cry", "surprised", "angry"]),
+ new SoundModel("女性2", ["neutral", "laughing", "happy", "sad", "cry", "surprised", "angry"]),
+ new SoundModel("ナレーション (男性)", ["narration"]),
+ new SoundModel("ナレーション (女性)", ["narration"]),
+ ];
+ }
+}
diff --git a/KoeBook/Contracts/Services/Mocks/SoundGenerationMock.cs b/KoeBook.Core/Services/Mocks/SoundGenerationServiceMock.cs
similarity index 57%
rename from KoeBook/Contracts/Services/Mocks/SoundGenerationMock.cs
rename to KoeBook.Core/Services/Mocks/SoundGenerationServiceMock.cs
index 626af33..7d0c37c 100644
--- a/KoeBook/Contracts/Services/Mocks/SoundGenerationMock.cs
+++ b/KoeBook.Core/Services/Mocks/SoundGenerationServiceMock.cs
@@ -1,12 +1,13 @@
-using KoeBook.Core.Models;
+using KoeBook.Core.Contracts.Services;
+using KoeBook.Core.Models;
-namespace KoeBook.Contracts.Services.Mocks;
+namespace KoeBook.Core.Services.Mocks;
-internal class SoundGenerationMock
+public class SoundGenerationServiceMock : ISoundGenerationService
{
public async ValueTask GenerateLineSoundAsync(ScriptLine scriptLine, BookOptions bookOptions, CancellationToken cancellationToken)
{
- await Task.Delay(1000, cancellationToken);
+ await Task.Delay(1000, cancellationToken).ConfigureAwait(false);
// 適当なバイト列を返す
var random = new Random();
var buffer = new byte[44100 * 2];
diff --git a/KoeBook/App.xaml.cs b/KoeBook/App.xaml.cs
index 1b73cee..cccf6c9 100644
--- a/KoeBook/App.xaml.cs
+++ b/KoeBook/App.xaml.cs
@@ -3,13 +3,13 @@
using KoeBook.Contracts.Services;
using KoeBook.Core.Contracts.Services;
using KoeBook.Core.Services;
-using KoeBook.Helpers;
+using KoeBook.Core.Services.Mocks;
using KoeBook.Models;
using KoeBook.Notifications;
using KoeBook.Services;
using KoeBook.ViewModels;
using KoeBook.Views;
-
+using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.UI.Xaml;
@@ -86,6 +86,13 @@ public App()
// Configuration
services.Configure(context.Configuration.GetSection(nameof(LocalSettingsOptions)));
+
+ // Core Services Mock
+ var mockOptions = context.Configuration.GetSection(nameof(MockOptions)).Get();
+ if (mockOptions.ISoundGenerationSelectorService.HasValue && mockOptions.ISoundGenerationSelectorService.Value)
+ services.AddSingleton();
+ if(mockOptions.ISoundGenerationService.HasValue && mockOptions.ISoundGenerationService.Value)
+ services.AddSingleton();
})
.Build();
diff --git a/KoeBook/Contracts/Services/Mocks/SoundGenerationSelectorServiceMock.cs b/KoeBook/Contracts/Services/Mocks/SoundGenerationSelectorServiceMock.cs
deleted file mode 100644
index 31842d3..0000000
--- a/KoeBook/Contracts/Services/Mocks/SoundGenerationSelectorServiceMock.cs
+++ /dev/null
@@ -1,18 +0,0 @@
-using KoeBook.Core.Contracts.Services;
-
-namespace KoeBook.Contracts.Services.Mocks;
-
-internal class SoundGenerationSelectorServiceMock : ISoundGenerationSelectorService
-{
- public IReadOnlyList Models { get; private set; } = Array.Empty();
-
- public async ValueTask InitializeAsync(CancellationToken cancellationToken)
- {
- await Task.Delay(1000, cancellationToken);
- Models = [
- new SoundModel("メロス",["narration", "neutral", "laughing", "happy", "sad", "cry", "surprised", "angry" ]),
- new SoundModel("老爺",["narration", "neutral", "laughing", "happy", "sad", "cry", "surprised", "angry" ]),
- new SoundModel("王",["narration", "neutral", "laughing", "happy", "sad", "cry", "surprised", "angry" ]),
- ];
- }
-}
diff --git a/KoeBook/KoeBook.csproj b/KoeBook/KoeBook.csproj
index a8f17d5..74966d7 100644
--- a/KoeBook/KoeBook.csproj
+++ b/KoeBook/KoeBook.csproj
@@ -58,10 +58,6 @@
-
-
-
-
true
diff --git a/KoeBook/Models/MockOptions.cs b/KoeBook/Models/MockOptions.cs
new file mode 100644
index 0000000..79e0558
--- /dev/null
+++ b/KoeBook/Models/MockOptions.cs
@@ -0,0 +1,8 @@
+namespace KoeBook.Models;
+
+internal class MockOptions
+{
+ public bool? ISoundGenerationSelectorService { get; set; }
+
+ public bool? ISoundGenerationService { get; set; }
+}
diff --git a/KoeBook/Services/CoreMocks/SoundGenerationSelectorServiceMock.cs b/KoeBook/Services/CoreMocks/SoundGenerationSelectorServiceMock.cs
new file mode 100644
index 0000000..e1c2009
--- /dev/null
+++ b/KoeBook/Services/CoreMocks/SoundGenerationSelectorServiceMock.cs
@@ -0,0 +1,19 @@
+using KoeBook.Core.Contracts.Services;
+using KoeBook.Core.Models;
+
+namespace KoeBook.Core.Services.Mocks;
+
+internal class SoundGenerationSelectorServiceMock : ISoundGenerationSelectorService
+{
+ public IReadOnlyList Models { get; private set; } = [];
+
+ public async ValueTask InitializeAsync(CancellationToken cancellationToken)
+ {
+ await Task.Delay(1000, cancellationToken).ConfigureAwait(false);
+ Models = [
+ new SoundModel("青年1", ["neutral", "laughing", "happy", "sad", "cry", "surprised", "angry"]),
+ new SoundModel("青年2", ["neutral", "laughing", "happy", "sad", "cry", "surprised", "angry"]),
+ new SoundModel("王", ["narration", "neutral", "laughing", "happy", "sad", "cry", "surprised", "angry"]),
+ ];
+ }
+}
diff --git a/KoeBook/appsettings.json b/KoeBook/appsettings.json
index 0817c9f..197db10 100644
--- a/KoeBook/appsettings.json
+++ b/KoeBook/appsettings.json
@@ -1,6 +1,10 @@
-{
+{
"LocalSettingsOptions": {
- "ApplicationDataFolder": "KoeBook/ApplicationData",
- "LocalSettingsFile": "LocalSettings.json"
+ "ApplicationDataFolder": "KoeBook/ApplicationData",
+ "LocalSettingsFile": "LocalSettings.json"
+ },
+ "MockOptions": {
+ "ISoundGenerationSelectorService": false,
+ "ISoundGenerationService": false
}
}
From 6fd5dad0c79ce471478d1bfec6e7ecdf2681b66a Mon Sep 17 00:00:00 2001
From: miyaji255 <84168445+miyaji255@users.noreply.github.com>
Date: Thu, 22 Feb 2024 15:02:01 +0900
Subject: [PATCH 3/4] =?UTF-8?q?SecretSettingsService=E3=81=AE=E3=83=95?=
=?UTF-8?q?=E3=82=A1=E3=82=A4=E3=83=AB=E5=AD=98=E5=9C=A8=E3=83=81=E3=82=A7?=
=?UTF-8?q?=E3=83=83=E3=82=AF=E3=82=92=E8=BF=BD=E5=8A=A0?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
KoeBook.Core/Services/SercretSettingsService.cs | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/KoeBook.Core/Services/SercretSettingsService.cs b/KoeBook.Core/Services/SercretSettingsService.cs
index 57935d3..da725be 100644
--- a/KoeBook.Core/Services/SercretSettingsService.cs
+++ b/KoeBook.Core/Services/SercretSettingsService.cs
@@ -23,7 +23,10 @@ public SecretSettingsService()
return Task.Run(async () =>
{
cancellationToken.ThrowIfCancellationRequested();
- var data = await File.ReadAllBytesAsync(Path.Combine(folderPath, "alt"), cancellationToken).ConfigureAwait(false);
+ var path = Path.Combine(folderPath, "alt");
+ if (!File.Exists(path))
+ return null;
+ var data = await File.ReadAllBytesAsync(path, cancellationToken).ConfigureAwait(false);
if (data is null)
return null;
From 0bd034139d96c8749a1845de4676f729a8b2d8ad Mon Sep 17 00:00:00 2001
From: miyaji255 <84168445+miyaji255@users.noreply.github.com>
Date: Thu, 22 Feb 2024 15:04:06 +0900
Subject: [PATCH 4/4] =?UTF-8?q?#27=20=E3=83=95=E3=82=A9=E3=83=BC=E3=83=9E?=
=?UTF-8?q?=E3=83=83=E3=83=88?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
KoeBook/App.xaml.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/KoeBook/App.xaml.cs b/KoeBook/App.xaml.cs
index cccf6c9..91ce47b 100644
--- a/KoeBook/App.xaml.cs
+++ b/KoeBook/App.xaml.cs
@@ -91,7 +91,7 @@ public App()
var mockOptions = context.Configuration.GetSection(nameof(MockOptions)).Get();
if (mockOptions.ISoundGenerationSelectorService.HasValue && mockOptions.ISoundGenerationSelectorService.Value)
services.AddSingleton();
- if(mockOptions.ISoundGenerationService.HasValue && mockOptions.ISoundGenerationService.Value)
+ if (mockOptions.ISoundGenerationService.HasValue && mockOptions.ISoundGenerationService.Value)
services.AddSingleton();
})
.Build();