Skip to content

Commit 18c42bd

Browse files
committed
!3745 feat(#I69V9Y): add speed config item for Baidu synthesizer
* chore: bump version 7.1.0 * feat: 增加语速控制配置项 * doc: 格式化文档 * refactor: 消除警告信息 * refactor: 更改为 switch * refactor: 精简代码 * refactor: 增加语速配置
1 parent 2275add commit 18c42bd

3 files changed

Lines changed: 32 additions & 28 deletions

File tree

src/Extensions/Components/BootstrapBlazor.BaiduSpeech/BaiduSpeechOption.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,9 @@ public class BaiduSpeechOption
2626
/// </summary>
2727
[NotNull]
2828
public string? Secret { get; set; }
29+
30+
/// <summary>
31+
/// 获得/设置 语速 值范围 0 - 9 默认值 5
32+
/// </summary>
33+
public int Speed { get; set; } = 5;
2934
}

src/Extensions/Components/BootstrapBlazor.BaiduSpeech/BootstrapBlazor.BaiduSpeech.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
4-
<Version>7.0.0</Version>
4+
<Version>7.1.0</Version>
55
</PropertyGroup>
66

77
<PropertyGroup>

src/Extensions/Components/BootstrapBlazor.BaiduSpeech/Services/BaiduSynthesizerProvider.cs

Lines changed: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -55,33 +55,35 @@ public async Task InvokeAsync(SynthesizerOption option)
5555
if (Module == null)
5656
{
5757
var moduleName = "./_content/BootstrapBlazor.BaiduSpeech/js/synthesizer.js";
58-
Logger.LogInformation($"load module {moduleName}");
58+
Logger.LogInformation("load module {moduleName}", moduleName);
5959
Module = await JSRuntime.InvokeAsync<IJSObjectReference>("import", moduleName);
6060
}
6161
Interop ??= DotNetObjectReference.Create(this);
6262

63-
if (Option.MethodName == "bb_baidu_speech_synthesizerOnce" && !string.IsNullOrEmpty(Option.Text))
63+
switch (Option.MethodName)
6464
{
65-
var result = Client.Synthesis(Option.Text);
66-
if (result.Success)
67-
{
68-
await Module.InvokeVoidAsync(Option.MethodName, Interop, nameof(Callback), result.Data);
69-
}
70-
else
71-
{
72-
73-
}
74-
Logger.LogInformation($"bb_baidu_speech_synthesizerOnce {result.Success}");
75-
if (!result.Success)
76-
{
77-
Logger.LogError($"{result.ErrorCode}: {result.ErrorMsg}");
78-
}
79-
}
80-
else if (Option.MethodName == "bb_baidu_close_synthesizer")
81-
{
82-
// 停止语音
83-
await Module.InvokeVoidAsync(Option.MethodName, Interop, nameof(Callback));
84-
Logger.LogInformation("bb_baidu_close_synthesizer");
65+
case "bb_baidu_speech_synthesizerOnce" when !string.IsNullOrEmpty(Option.Text):
66+
{
67+
var result = Client.Synthesis(Option.Text, new Dictionary<string, object>()
68+
{
69+
{ "spd", SpeechOption.Speed }
70+
});
71+
if (result.Success)
72+
{
73+
await Module.InvokeVoidAsync(Option.MethodName, Interop, nameof(Callback), result.Data);
74+
}
75+
Logger.LogInformation("bb_baidu_speech_synthesizerOnce {result}", result.Success);
76+
if (!result.Success)
77+
{
78+
Logger.LogError("{ErrorCode}: {ErrorMsg}", result.ErrorCode, result.ErrorMsg);
79+
}
80+
break;
81+
}
82+
case "bb_baidu_close_synthesizer":
83+
// 停止语音
84+
await Module.InvokeVoidAsync(Option.MethodName, Interop, nameof(Callback));
85+
Logger.LogInformation("bb_baidu_close_synthesizer");
86+
break;
8587
}
8688
}
8789

@@ -107,11 +109,8 @@ private async ValueTask DisposeAsync(bool disposing)
107109
{
108110
if (disposing)
109111
{
110-
if (Interop != null)
111-
{
112-
Interop.Dispose();
113-
}
114-
if (Module is not null)
112+
Interop?.Dispose();
113+
if (Module != null)
115114
{
116115
await Module.DisposeAsync();
117116
}

0 commit comments

Comments
 (0)