BlazorSpeech 1.0.4
dotnet add package BlazorSpeech --version 1.0.4
NuGet\Install-Package BlazorSpeech -Version 1.0.4
<PackageReference Include="BlazorSpeech" Version="1.0.4" />
<PackageVersion Include="BlazorSpeech" Version="1.0.4" />
<PackageReference Include="BlazorSpeech" />
paket add BlazorSpeech --version 1.0.4
#r "nuget: BlazorSpeech, 1.0.4"
#:package BlazorSpeech@1.0.4
#addin nuget:?package=BlazorSpeech&version=1.0.4
#tool nuget:?package=BlazorSpeech&version=1.0.4
BlazorSpeech
<p align="center"> <a href="https://www.nuget.org/packages/BlazorSpeech/1.0.1" target="_blank"> <img src="https://img.shields.io/nuget/v/BlazorSpeech.svg?label=NuGet%20v" alt="NuGet version" style="max-height:300px;" /> <img src="https://img.shields.io/nuget/dt/BlazorSpeech.svg?label=Downloads" alt="NuGet downloads" style="max-height:300px;" /> </a> <img src="https://img.shields.io/badge/Platform-.NET%2010-orange.svg" style="max-height:300px;" alt=".NET 10" /> <img src="https://img.shields.io/github/license/GimliCZ/BlazorSpeech" alt="License" /> <br /> <img src="https://img.shields.io/github/issues/GimliCZ/BlazorSpeech" alt="Issues" /> <img src="https://img.shields.io/github/stars/GimliCZ/BlazorSpeech" alt="Stars" /> <img src="https://img.shields.io/github/forks/GimliCZ/BlazorSpeech" alt="Forks" /> <img src="https://img.shields.io/github/last-commit/GimliCZ/BlazorSpeech" alt="Last Commit" /> </p>
BlazorSpeech is a lightweight Blazor library for easy and reliable speech synthesis in web applications. It
provides simple JavaScript interop for working with browser SpeechSynthesis APIs and managing available voices.
Features
- Automatic detection of available speech voices
- One-time initialization with
voiceReadypromise - Simple integration with Blazor projects
- Includes
cleanspeech.jsfor easy JS interop
Installation
Install via NuGet:
dotnet add package BlazorSpeech
Quick Start
Register
builder.Services.AddBlazorSpeech();
Inject to page
@inject ISpeechSynthesizer Speech
Speak
private async Task SpeakAsync()
{
if (string.IsNullOrWhiteSpace(text))
return;
try
{
var options = new SpeechOptions
{
VoiceName = string.IsNullOrWhiteSpace(selectedVoice) ? null : selectedVoice,
Rate = rate,
Pitch = pitch,
Volume = volume
};
await Speech.SpeakAsync(text, options);
}
catch (Exception ex)
{
Console.WriteLine("Error {0}", ex.Message);
}
finally
{
StateHasChanged();
}
}
Subscribe on Speech Changes
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await LoadVoicesAsync();
Speech.SpeakingStateChanged += OnSpeakingStateChanged;
isSpeaking = await Speech.IsSpeakingOrPendingSpeechAsync();
}
await base.OnAfterRenderAsync(firstRender);
}
React to change of voice state
private async Task OnSpeakingStateChanged(bool speaking)
{
isSpeaking = speaking;
// Ensure UI update happens
await InvokeAsync(StateHasChanged);
}
Stop Speaking
private async Task StopAsync()
{
try
{
await Speech.CancelAsync();
}
catch (Exception ex)
{
Console.WriteLine("Error {0}", ex.Message);
}
finally
{
StateHasChanged();
}
}
Cleanup after use
public void Dispose()
{
Speech.SpeakingStateChanged -= OnSpeakingStateChanged;
}
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Microsoft.AspNetCore.Components.Web (>= 10.0.1)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.