mirror of
https://gitee.com/LongbowEnterprise/BootstrapBlazor.git
synced 2024-12-02 03:59:14 +08:00
feat(WebSpeechRecognition): add Callback parameter (#4162)
* refactor: 更正语音包设置 * refactor: 增加回调事件条件 * chore: bump version 8.0.0 * chore: 更新 WinBox 依赖包 * chore: bump version 8.8.5-beta01
This commit is contained in:
parent
5f41cfb2e9
commit
d58768cd80
@ -59,8 +59,12 @@ public partial class WebSpeeches
|
||||
_speechVoices.AddRange(voices);
|
||||
}
|
||||
|
||||
_voices.AddRange(_speechVoices.Select(i => new SelectedItem(i.Name!, $"{i.Name}({i.Lang})")));
|
||||
_voiceName = _speechVoices.Find(i => i.Lang == CultureInfo.CurrentUICulture.Name)?.Name;
|
||||
_voices.AddRange(_speechVoices.Select(i => new SelectedItem($"{i.Name}({i.Lang})", $"{i.Name}({i.Lang})")));
|
||||
var voice = _speechVoices.Find(i => i.Lang == CultureInfo.CurrentUICulture.Name);
|
||||
if (voice != null)
|
||||
{
|
||||
_voiceName = $"{voice.Name}({voice.Lang})";
|
||||
}
|
||||
|
||||
_text = Localizer["WebSpeechText"];
|
||||
_buttonText = Localizer["WebSpeechSpeakButtonText"];
|
||||
@ -137,7 +141,7 @@ public partial class WebSpeeches
|
||||
_star = true;
|
||||
StateHasChanged();
|
||||
|
||||
await _entry.SpeakAsync(_text, _speechVoices.Find(i => i.Name == _voiceName));
|
||||
await _entry.SpeakAsync(_text, _speechVoices.Find(i => $"{i.Name}({i.Lang})" == _voiceName));
|
||||
await _tcs.Task;
|
||||
_star = false;
|
||||
_tcs = null;
|
||||
|
@ -1,7 +1,7 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk.Razor">
|
||||
|
||||
<PropertyGroup>
|
||||
<Version>8.8.4</Version>
|
||||
<Version>8.8.5-beta01</Version>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net5.0'">
|
||||
|
@ -63,7 +63,11 @@ public class WebSpeechRecognition(JSModule module, IComponentIdGenerator compone
|
||||
await module.InvokeVoidAsync("start", _id, _interop, new
|
||||
{
|
||||
TriggerStart = OnStartAsync != null,
|
||||
TriggerSpeechStart = OnSpeechStartAsync != null
|
||||
TriggerSpeechStart = OnSpeechStartAsync != null,
|
||||
TriggerSpeechEnd = OnSpeechEndAsync != null,
|
||||
TriggerNoMatch = OnNoMatchAsync != null,
|
||||
TriggerEnd = OnEndAsync != null,
|
||||
TriggerError = OnErrorAsync != null
|
||||
}, option);
|
||||
}
|
||||
|
||||
|
@ -21,22 +21,33 @@ export async function start(id, invoke, trigger, option) {
|
||||
}
|
||||
recognition.onspeechend = () => {
|
||||
recognition.stop();
|
||||
invoke.invokeMethodAsync("TriggerSpeechEndCallback");
|
||||
if (trigger.triggerSpeechEnd) {
|
||||
invoke.invokeMethodAsync("TriggerSpeechEndCallback");
|
||||
}
|
||||
}
|
||||
recognition.onnomatch = e => {
|
||||
invoke.invokeMethodAsync("TriggerNoMatchCallback", {
|
||||
error: 'no-match',
|
||||
message: 'No match found.'
|
||||
});
|
||||
Data.remove(id);
|
||||
if (trigger.triggerNoMatch) {
|
||||
invoke.invokeMethodAsync("TriggerNoMatchCallback", {
|
||||
error: 'no-match',
|
||||
message: 'No match found.'
|
||||
});
|
||||
}
|
||||
}
|
||||
recognition.onend = () => {
|
||||
invoke.invokeMethodAsync("TriggerEndCallback");
|
||||
Data.remove(id);
|
||||
if (trigger.triggerEnd) {
|
||||
invoke.invokeMethodAsync("TriggerEndCallback");
|
||||
}
|
||||
}
|
||||
recognition.onerror = e => {
|
||||
invoke.invokeMethodAsync("TriggerErrorCallback", {
|
||||
error: e.error,
|
||||
message: e.message
|
||||
});
|
||||
Data.remove(id);
|
||||
if (trigger.triggerError) {
|
||||
invoke.invokeMethodAsync("TriggerErrorCallback", {
|
||||
error: e.error,
|
||||
message: e.message
|
||||
});
|
||||
}
|
||||
}
|
||||
recognition.onresult = e => {
|
||||
let final_transcript = '';
|
||||
@ -69,9 +80,8 @@ export async function start(id, invoke, trigger, option) {
|
||||
if (continuous !== void 0) {
|
||||
recognition.continuous = continuous;
|
||||
}
|
||||
recognition.start();
|
||||
|
||||
Data.set(id, recognition);
|
||||
recognition.start();
|
||||
}
|
||||
|
||||
export function stop(id) {
|
||||
|
Loading…
Reference in New Issue
Block a user