!3745 feat(#I69V9Y): add speed config item for Baidu synthesizer

* chore: bump version 7.1.0
* feat: 增加语速控制配置项
* doc: 格式化文档
* refactor: 消除警告信息
* refactor: 更改为 switch
* refactor: 精简代码
* refactor: 增加语速配置
This commit is contained in:
Argo 2023-01-10 13:04:19 +00:00
parent 2275add0cd
commit 18c42bd5f4
3 changed files with 32 additions and 28 deletions

View File

@ -26,4 +26,9 @@ public class BaiduSpeechOption
/// </summary>
[NotNull]
public string? Secret { get; set; }
/// <summary>
/// 获得/设置 语速 值范围 0 - 9 默认值 5
/// </summary>
public int Speed { get; set; } = 5;
}

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<Version>7.0.0</Version>
<Version>7.1.0</Version>
</PropertyGroup>
<PropertyGroup>

View File

@ -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<IJSObjectReference>("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<string, object>()
{
{ "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();
}