jsakamoto / Toolbelt.Blazor.SpeechSynthesis

SpeechSynthesis API access for your Blazor apps.
https://jsakamoto.github.io/Toolbelt.Blazor.SpeechSynthesis/
Mozilla Public License 2.0
91 stars 19 forks source link

When Blazor Is Initialized, and you want to let the user know, "Speak" not working #11

Open dlevitan opened 2 years ago

dlevitan commented 2 years ago

What I am trying to do is to alert the user when the Blazor Application is running in their browser, and this is not working. Stepping through the code, it is executing the code, but not working until you come back to the page.

The following are the steps to reproduce:

After adding a new Blazor Wasm application, installing this library, and then updating the "Index.razor" page to:

@using Toolbelt.Blazor.SpeechSynthesis @{/* Add these two lines. */}
@inject SpeechSynthesis SpeechSynthesis
@page "/"

<PageTitle>Index</PageTitle>

<h1>Hello, world!</h1>

Welcome to your new app.

<SurveyPrompt Title="How is Blazor working for you?" />

@code {

    string Text1 = "Hello From the Blazor application's Home page";
    string Text2 = "Welcome back to the Blazor application's Home page";

    protected override void OnAfterRender(bool firstRender)
    {
        if (firstRender)
        {
            this.SpeechSynthesis.Speak(this.Text1); // <-- Speak!
            this.SpeechSynthesis.Speak(this.Text1); // <-- Speak!
            this.SpeechSynthesis.Speak(this.Text1); // <-- Speak!
        }
        else
        {
            this.SpeechSynthesis.Speak(this.Text2); // <-- Speak!
        }
    }
}

You can only here the message when you come back to the page. In addition, "firstRender" seems to be true when going back to the page. Likewise if you refresh the page, you get the same behavior. So, this may be a Blazor issue or both.

jsakamoto commented 2 years ago

@dlevitan Thank you for letting me know!

The architecture of this library causes this problem. I fixed this problem today, and I published it as ver.10.0.0.

Could you try it out?

(By the way, this version is a major update release, and it includes some breaking changes. For example, the synchronous version "Speak" method was deprecated. You can continue using the synchronous version, but the asynchronous version "SpeakAsync" is recommended.)

Again, thank you for your contribution! 👍

dlevitan commented 2 years ago

The change worked. Question, while my computer has several vocalizers, it defaults to the one on my computer with the library is for Fusion. Is there a way for the library to use different vocalizers for different purposes?

On Sat, Jul 2, 2022 at 7:04 AM jsakamoto @.***> wrote:

@dlevitan https://github.com/dlevitan Thank you for letting me know!

The architecture of this library causes this problem. I fixed this problem today, and I published it as ver.10.0.0.

- https://www.nuget.org/packages/Toolbelt.Blazor.SpeechSynthesis/10.0.0#readme-body-tab

Could you try it out?

(By the way, this version is a major update release, and it includes some breaking changes. For example, the synchronous version "Speak" method was deprecated. You can continue using the synchronous version, but the asynchronous version "SpeakAsync" is recommended.)

Again, thank you for your contribution! 👍

— Reply to this email directly, view it on GitHub https://github.com/jsakamoto/Toolbelt.Blazor.SpeechSynthesis/issues/11#issuecomment-1172904187, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABUZJVVUPX7EPCZSGGVGZFLVSBEAJANCNFSM52NGL4RA . You are receiving this because you were mentioned.Message ID: @.*** com>

jsakamoto commented 2 years ago

@dlevitan Sorry too late! I apologize that I overlooked the notification of your reply. 🙇‍♂️

By the way, I could not understand well for your question. Could you explain your question again easier or more specifically? (For example, what is the "Fusion"? I could not understand that word.)

dlevitan commented 2 years ago

The root of what Fusion is, has to do with making our applications being usable by people who are Visually Impaired. Fusion is by Scientific Freedom and provides both a visual tool [Zoom Text] for a variety of ways to aid the visually impaired as well as a vocal tool [Jaws] that the blind rely on. At this time Blazor does not provide any out of the box tools that could provide some multimedia to a Blazor app. I had hoped that their would be a way to create components in Unity or some other tool and use it within a Blazor app. I believe that an audible sound, for when the application opens and for user feedback would improve the user interface. My opinion is that with an audible click, I know that a button or link has been clicked.

jsakamoto commented 2 years ago

@dlevitan

I understood what you mentioned about this: https://www.freedomscientific.com/

My opinion is that with an audible click, I know that a button or link has been clicked.

I see, and I strongly agree with your idea.

But unfortunately, this library is just a wrapper for a web browser's API. The "Text to speech" ability is provided by web browsers, not by this library.

For more detail, please see also: https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API#web_speech_api_interfaces

The "Web Speech API" of web browsers is provided as a JavaScript interface, and it can't be invoked from Blazor C# code directly. This library just provides the bridge from Blazor C# code to the Web Speech API JavaScript interface to make it possible.

And, to the best of my knowledge, there is no way to add custom voices to the Web Speech API of web browsers. I assume the list of voices on the Web Speech API is hardcoded on web browser implementation. Therefore, you would not be able to make the Web Speech API on web browsers use any vocalizers to speak, I guess. To verify what I said, I recommend inquiring to Freedom Scientific.

jsakamoto commented 2 years ago

@dlevitan

I found an interesting discussion on the stackoverflow.com.

"HOW TO ADD MORE VOICE FROM MICROSOFT EDGE TO CHROME AND FIREFOX ( only on windows 10 fall creator update or later)" https://stackoverflow.com/posts/47485786/revisions

Is that useful for you?