Toolbelt.Blazor.SpeechSynthesis 2.0.0

SpeechSynthesis API access for your Blazor apps.

There is a newer version of this package available.
See the version list below for details.
Install-Package Toolbelt.Blazor.SpeechSynthesis -Version 2.0.0
dotnet add package Toolbelt.Blazor.SpeechSynthesis --version 2.0.0
<PackageReference Include="Toolbelt.Blazor.SpeechSynthesis" Version="2.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Toolbelt.Blazor.SpeechSynthesis --version 2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Toolbelt.Blazor.SpeechSynthesis, 2.0.0"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install Toolbelt.Blazor.SpeechSynthesis as a Cake Addin
#addin nuget:?package=Toolbelt.Blazor.SpeechSynthesis&version=2.0.0

// Install Toolbelt.Blazor.SpeechSynthesis as a Cake Tool
#tool nuget:?package=Toolbelt.Blazor.SpeechSynthesis&version=2.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Blazor SpeechSynthesis NuGet Package

Summary

This is a class library for Blazor app to provide Speech Synthesis API access.

How to install and use?

1. Installation and Registration

Step.1-1 Install the library via NuGet package, like this.

> dotnet add package Toolbelt.Blazor.SpeechSynthesis

Step.1-2 Register "SpeechSynthesis" service into the DI container, at ConfigureService method in the Startup class of your Blazor application.

// Startup.cs

using Toolbelt.Blazor.Extensions.DependencyInjection; // <- Add this, and...
...
public class Startup
{
  public void ConfigureServices(IServiceCollection services)
  {
    services.AddSpeechSynthesis(); // <- Add this line.
    ...

2. Usage in your Blazor component (.cshtml)

Step.2-1 Open the Toolbelt.Blazor.SpeechSynthesis namespace, and inject the SpeechSynthesis service into the component.

@{/* This is your component .cshtml*/}
@using Toolbelt.Blazor.SpeechSynthesis @{/* Add these two lines. */}
@inject SpeechSynthesis SpeechSynthesis
...

Step.2-2 Invoke Speak() method of the SpeechSynthesis service instance to speak!

@using Toolbelt.Blazor.SpeechSynthesis
@inject SpeechSynthesis SpeechSynthesis

<div> <textarea bind="@Text"></textarea> </div>

<div> <button onclick="@onClickSpeak">Speak</button> </div>

@functions {

  string Text;

  void onClickSpeak() {
    this.SpeechSynthesis.Speak(this.Text); // <-- Speak!
  }
}

You can also speak with detail parameters, such as picth, rate, volume, by using SpeechSynthesisUtterance object.

  void onClickSpeak() {
    var utterancet = new SpeechSynthesisUtterance {
        Text = this.Text,
        Lang = "en-US", // BCP 47 language tag
        Pitch = 1.0, // 0.0 ~ 2.0 (Default 1.0)
        Rate = 1.0, // 0.1 ~ 10.0 (Default 1.0)
        Volume = 1.0 // 0.0 ~ 1.0 (Default 1.0)
    }
    this.SpeechSynthesis.Speak(utterancet); // <-- Speak!
  }

If you want to chose type of voices, you can do it with GetVoicesAsync() method of SpeechSynthesis service instance.

  IEnumerable<SpeechSynthesisVoice> Voices;

  protected async override Task OnInitAsync()
  {
    this.Voices = await this.SpeechSynthesis.GetVoicesAsync();
  }

  void onClickSpeak() {
    var utterancet = new SpeechSynthesisUtterance {
        Text = this.Text,
        Voice = this.Voices.FirstOrDefault(v => v.Name.Contains("Haruka"));
    }
    this.SpeechSynthesis.Speak(utterancet); // <-- Speak with "Haruka"'s voice!
  }

Release Note

  • v.2.0.0 - BREAKING CHANGE: Support Blazor v.0.8.0 (not compatible with v.0.7.0 or before.)
  • v.1.0.0 - 1st release.

License

Mozilla Public License Version 2.0

Blazor SpeechSynthesis NuGet Package

Summary

This is a class library for Blazor app to provide Speech Synthesis API access.

How to install and use?

1. Installation and Registration

Step.1-1 Install the library via NuGet package, like this.

> dotnet add package Toolbelt.Blazor.SpeechSynthesis

Step.1-2 Register "SpeechSynthesis" service into the DI container, at ConfigureService method in the Startup class of your Blazor application.

// Startup.cs

using Toolbelt.Blazor.Extensions.DependencyInjection; // <- Add this, and...
...
public class Startup
{
  public void ConfigureServices(IServiceCollection services)
  {
    services.AddSpeechSynthesis(); // <- Add this line.
    ...

2. Usage in your Blazor component (.cshtml)

Step.2-1 Open the Toolbelt.Blazor.SpeechSynthesis namespace, and inject the SpeechSynthesis service into the component.

@{/* This is your component .cshtml*/}
@using Toolbelt.Blazor.SpeechSynthesis @{/* Add these two lines. */}
@inject SpeechSynthesis SpeechSynthesis
...

Step.2-2 Invoke Speak() method of the SpeechSynthesis service instance to speak!

@using Toolbelt.Blazor.SpeechSynthesis
@inject SpeechSynthesis SpeechSynthesis

<div> <textarea bind="@Text"></textarea> </div>

<div> <button onclick="@onClickSpeak">Speak</button> </div>

@functions {

  string Text;

  void onClickSpeak() {
    this.SpeechSynthesis.Speak(this.Text); // <-- Speak!
  }
}

You can also speak with detail parameters, such as picth, rate, volume, by using SpeechSynthesisUtterance object.

  void onClickSpeak() {
    var utterancet = new SpeechSynthesisUtterance {
        Text = this.Text,
        Lang = "en-US", // BCP 47 language tag
        Pitch = 1.0, // 0.0 ~ 2.0 (Default 1.0)
        Rate = 1.0, // 0.1 ~ 10.0 (Default 1.0)
        Volume = 1.0 // 0.0 ~ 1.0 (Default 1.0)
    }
    this.SpeechSynthesis.Speak(utterancet); // <-- Speak!
  }

If you want to chose type of voices, you can do it with GetVoicesAsync() method of SpeechSynthesis service instance.

  IEnumerable<SpeechSynthesisVoice> Voices;

  protected async override Task OnInitAsync()
  {
    this.Voices = await this.SpeechSynthesis.GetVoicesAsync();
  }

  void onClickSpeak() {
    var utterancet = new SpeechSynthesisUtterance {
        Text = this.Text,
        Voice = this.Voices.FirstOrDefault(v => v.Name.Contains("Haruka"));
    }
    this.SpeechSynthesis.Speak(utterancet); // <-- Speak with "Haruka"'s voice!
  }

Release Note

  • v.2.0.0 - BREAKING CHANGE: Support Blazor v.0.8.0 (not compatible with v.0.7.0 or before.)
  • v.1.0.0 - 1st release.

License

Mozilla Public License Version 2.0

Release Notes

v.2.0.0
- BREAKING CHANGE: Support Blazor v.0.8.0 (not compatible with v.0.7.0 or before.)
v.1.0.0
- 1st release.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
9.0.0 71 9/5/2021
8.1.1 374 5/8/2021
8.1.0 5,135 12/6/2020
8.0.0 5,640 1/8/2020
7.0.0.1 1,379 9/6/2019
7.0.0 167 9/6/2019
6.0.0 174 8/19/2019
5.0.0 193 6/16/2019
4.0.0 267 5/2/2019
3.0.0 277 3/9/2019
2.0.0 334 2/10/2019
1.0.0 420 10/19/2018
Show less