Skip to main content

Speech Recognition in .NET MAUI with CommunityToolkit

Note: This is a guest blog post by Vladislav Antonyuk, who is a senior software engineer at DataArt and a core contributor of the .NET MAUI Community Toolkit.

The .NET MAUI Community Toolkit is a collection of extensions and components that can be used to extend the functionality of .NET MAUI apps. The toolkit is open-source and community-driven, and it is constantly being updated with new features and improvements.

One of the features that the .NET MAUI Community Toolkit offers is Speech To Text. This allows converting spoken words into text, which can be used in a variety of ways. For example, users could use speech-to-text to create a voice-activated assistant or to transcribe audio recordings.

Here’s an example of how to use SpeechToText in C#:

var isGranted = await SpeechToText.Default.RequestPermissions(cancellationToken);
if (!isGranted)
{
    await Toast.Make("Permission not granted").Show(CancellationToken.None);
    return;
}
var recognitionResult = await SpeechToText.Default.ListenAsync(
                                    CultureInfo.GetCultureInfo("uk-ua"),
                                    new Progress(partialText =>
                                    {
                                        RecognitionText += partialText + " ";
                                    }), cancellationToken);
if (recognitionResult.IsSuccessful)
{
    RecognitionText = recognitionResult.Text;
}
else
{
    await Toast.Make(recognitionResult.Exception?.Message ?? "Unable to recognize speech").Show(CancellationToken.None);
}

This code requests microphone and speech recognition permissions, then starts listening for speech input, in a result it will set any recognized text to the RecognitionText variable.

When using SpeechToText, it captures and handles all exceptions while returning the result of the operation. However, if you prefer to specifically handle certain exceptions, such as when the user cancels the operation, you can enclose your code within a try/catch block and utilize the EnsureSuccess method:

var isGranted = await SpeechToText.Default.RequestPermissions(cancellationToken);
if (!isGranted)
{
    await Toast.Make("Permission not granted").Show(CancellationToken.None);
    return;
}
var recognitionResult = await SpeechToText.Default.ListenAsync(
                                    CultureInfo.GetCultureInfo("uk-ua"),
                                    new Progress(), cancellationToken);
recognitionResult.EnsureSuccess();
await Toast.Make($"RecognizedText: {recognitionResult.Text}").Show(cancellationToken);

Note: SpeechToText requires additional permissions for the app.

Please read the documentation to correctly set up the application.

Summary

SpeechToText is a powerful new feature that can be found as part of the CommunityToolkit.Maui library. It can be used to create a variety of more accurate, more responsive, and more engaging speech-enabled applications.

When utilizing speech-to-text, there are several additional factors to take into account:

  • The availability of an Internet connection may be necessary depending on the chosen recognition language. On Windows, the speech recognition system automatically adjusts between online and offline modes based on Internet accessibility.
  • The accuracy of speech-to-text is influenced by factors such as microphone quality and the surrounding environment.
  • Enhancing the accuracy of speech-to-text can be achieved by using a noise-canceling microphone and speaking clearly and at a slower pace.
  • Training the speech recognizer with your own voice is another method to improve the accuracy of speech-to-text.

Finally, be sure to check out the full release notes for .NET MAUI CommunityToolkit version 5.2.0 for even more great resources for .NET MAUI developers.

The post Speech Recognition in .NET MAUI with CommunityToolkit appeared first on .NET Blog.



source https://devblogs.microsoft.com/dotnet/speech-recognition-in-dotnet-maui-with-community-toolkit/

Comments

Popular posts from this blog

Fake CVR Generator Denmark

What Is Danish CVR The Central Business Register (CVR) is the central register of the state with information on all Danish companies. Since 1999, the Central Business Register has been the authoritative register for current and historical basic data on all registered companies in Denmark. Data comes from the companies' own registrations on Virk Report. There is also information on associations and public authorities in the CVR. As of 2018, CVR also contains information on Greenlandic companies, associations and authorities. In CVR at Virk you can do single lookups, filtered searches, create extracts and subscriptions, and retrieve a wide range of company documents and transcripts. Generate Danish CVR For Test (Fake) Click the button below to generate the valid CVR number for Denmark. You can click multiple times to generate several numbers. These numbers can be used to Test your sofware application that uses CVR, or Testing CVR APIs that Danish Govt provide. Generate

How To Iterate Dictionary Object

Dictionary is a object that can store values in Key-Value pair. its just like a list, the only difference is: List can be iterate using index(0-n) but not the Dictionary . Generally when we try to iterate the dictionary we get below error: " Collection was modified; enumeration operation may not execute. " So How to parse a dictionary and modify its values?? To iterate dictionary we must loop through it's keys or key - value pair. Using keys

How To Append Data to HTML5 localStorage or sessionStorage?

The localStorage property allows you to access a local Storage object. localStorage is similar to sessionStorage. The only difference is that, while data stored in localStorage has no expiration time untill unless user deletes his cache, data stored in sessionStorage gets cleared when the originating window or tab get closed. These are new HTML5 objects and provide these methods to deal with it: The following snippet accesses the current domain's local Storage object and adds a data item to it using Storage.setItem() . localStorage.setItem('myFav', 'Taylor Swift'); or you can use the keyname directly as : localStorage.myFav = 'Taylor Swift'; To grab the value set in localStorage or sessionStorage, we can use localStorage.getItem("myFav"); or localStorage.myFav There's no append function for localStorage or sessionStorage objects. It's not hard to write one though.The simplest solution goes here: But we can kee