From 18c42bd5f4332b10fdc0bcd9e03a45b1fa53dc29 Mon Sep 17 00:00:00 2001 From: Argo Date: Tue, 10 Jan 2023 13:04:19 +0000 Subject: [PATCH] =?UTF-8?q?!3745=20feat(#I69V9Y):=20add=20speed=20config?= =?UTF-8?q?=20item=20for=20Baidu=20synthesizer=20*=20chore:=20bump=20versi?= =?UTF-8?q?on=207.1.0=20*=20feat:=20=E5=A2=9E=E5=8A=A0=E8=AF=AD=E9=80=9F?= =?UTF-8?q?=E6=8E=A7=E5=88=B6=E9=85=8D=E7=BD=AE=E9=A1=B9=20*=20doc:=20?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E5=8C=96=E6=96=87=E6=A1=A3=20*=20refactor:?= =?UTF-8?q?=20=E6=B6=88=E9=99=A4=E8=AD=A6=E5=91=8A=E4=BF=A1=E6=81=AF=20*?= =?UTF-8?q?=20refactor:=20=E6=9B=B4=E6=94=B9=E4=B8=BA=20switch=20*=20refac?= =?UTF-8?q?tor:=20=E7=B2=BE=E7=AE=80=E4=BB=A3=E7=A0=81=20*=20refactor:=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=AF=AD=E9=80=9F=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../BaiduSpeechOption.cs | 5 ++ .../BootstrapBlazor.BaiduSpeech.csproj | 2 +- .../Services/BaiduSynthesizerProvider.cs | 53 +++++++++---------- 3 files changed, 32 insertions(+), 28 deletions(-) diff --git a/src/Extensions/Components/BootstrapBlazor.BaiduSpeech/BaiduSpeechOption.cs b/src/Extensions/Components/BootstrapBlazor.BaiduSpeech/BaiduSpeechOption.cs index 4bad542b1..181634d5a 100644 --- a/src/Extensions/Components/BootstrapBlazor.BaiduSpeech/BaiduSpeechOption.cs +++ b/src/Extensions/Components/BootstrapBlazor.BaiduSpeech/BaiduSpeechOption.cs @@ -26,4 +26,9 @@ public class BaiduSpeechOption /// [NotNull] public string? Secret { get; set; } + + /// + /// 获得/设置 语速 值范围 0 - 9 默认值 5 + /// + public int Speed { get; set; } = 5; } diff --git a/src/Extensions/Components/BootstrapBlazor.BaiduSpeech/BootstrapBlazor.BaiduSpeech.csproj b/src/Extensions/Components/BootstrapBlazor.BaiduSpeech/BootstrapBlazor.BaiduSpeech.csproj index c3d52a292..5fa568ded 100644 --- a/src/Extensions/Components/BootstrapBlazor.BaiduSpeech/BootstrapBlazor.BaiduSpeech.csproj +++ b/src/Extensions/Components/BootstrapBlazor.BaiduSpeech/BootstrapBlazor.BaiduSpeech.csproj @@ -1,7 +1,7 @@ - 7.0.0 + 7.1.0 diff --git a/src/Extensions/Components/BootstrapBlazor.BaiduSpeech/Services/BaiduSynthesizerProvider.cs b/src/Extensions/Components/BootstrapBlazor.BaiduSpeech/Services/BaiduSynthesizerProvider.cs index 8f8c35587..d78c7d15c 100644 --- a/src/Extensions/Components/BootstrapBlazor.BaiduSpeech/Services/BaiduSynthesizerProvider.cs +++ b/src/Extensions/Components/BootstrapBlazor.BaiduSpeech/Services/BaiduSynthesizerProvider.cs @@ -55,33 +55,35 @@ public class BaiduSynthesizerProvider : ISynthesizerProvider, IAsyncDisposable if (Module == null) { var moduleName = "./_content/BootstrapBlazor.BaiduSpeech/js/synthesizer.js"; - Logger.LogInformation($"load module {moduleName}"); + Logger.LogInformation("load module {moduleName}", moduleName); Module = await JSRuntime.InvokeAsync("import", moduleName); } Interop ??= DotNetObjectReference.Create(this); - if (Option.MethodName == "bb_baidu_speech_synthesizerOnce" && !string.IsNullOrEmpty(Option.Text)) + switch (Option.MethodName) { - var result = Client.Synthesis(Option.Text); - if (result.Success) - { - await Module.InvokeVoidAsync(Option.MethodName, Interop, nameof(Callback), result.Data); - } - else - { - - } - Logger.LogInformation($"bb_baidu_speech_synthesizerOnce {result.Success}"); - if (!result.Success) - { - Logger.LogError($"{result.ErrorCode}: {result.ErrorMsg}"); - } - } - else if (Option.MethodName == "bb_baidu_close_synthesizer") - { - // 停止语音 - await Module.InvokeVoidAsync(Option.MethodName, Interop, nameof(Callback)); - Logger.LogInformation("bb_baidu_close_synthesizer"); + case "bb_baidu_speech_synthesizerOnce" when !string.IsNullOrEmpty(Option.Text): + { + var result = Client.Synthesis(Option.Text, new Dictionary() + { + { "spd", SpeechOption.Speed } + }); + if (result.Success) + { + await Module.InvokeVoidAsync(Option.MethodName, Interop, nameof(Callback), result.Data); + } + Logger.LogInformation("bb_baidu_speech_synthesizerOnce {result}", result.Success); + if (!result.Success) + { + Logger.LogError("{ErrorCode}: {ErrorMsg}", result.ErrorCode, result.ErrorMsg); + } + break; + } + case "bb_baidu_close_synthesizer": + // 停止语音 + await Module.InvokeVoidAsync(Option.MethodName, Interop, nameof(Callback)); + Logger.LogInformation("bb_baidu_close_synthesizer"); + break; } } @@ -107,11 +109,8 @@ public class BaiduSynthesizerProvider : ISynthesizerProvider, IAsyncDisposable { if (disposing) { - if (Interop != null) - { - Interop.Dispose(); - } - if (Module is not null) + Interop?.Dispose(); + if (Module != null) { await Module.DisposeAsync(); }