A community member has associated this post with a similar question:
How to add continuous speech/talk - .NET MAUI Speech

Only moderators can edit this content.

How to add continuous speech/talk - Increase pause .NET MAUI SpeechToText

Johnson 81 Reputation points
2024-07-20T12:59:52.91+00:00

I have the below .Net MAUI code that works great. I use SpeechToText in CommunityToolkit.Maui 7.0.1

I want to add continuous speech, I mean when I speak, it must not stop listening until I press stop button.

In the below code, when I stop speaking, or I pause for like 2-3 sec, it stops itself listening, so I don't want it to behave like that.

In brief :

I want it to continue listening even if i pause my speech for 2-3 sec.

or I want to increase the pause, like instead of 2-3 sec, increase it to 5 sec then it can stop listening.

public class SpeechToTextImplementation : ISpeechToText { public event EventHandler<SpeechToTextRecognitionResultUpdatedEventArgs> RecognitionResultUpdated = null!; public event EventHandler<SpeechToTextRecognitionResultCompletedEventArgs> RecognitionResultCompleted = null!; public event EventHandler<SpeechToTextStateChangedEventArgs> StateChanged = null!; public SpeechToTextState CurrentState { get; private set; } = SpeechToTextState.Idle; public async Task<SpeechToTextResult> ListenAsync(CultureInfo culture, IProgress<string>? recognitionResult, CancellationToken cancellationToken) {

await Task.Delay(2000, cancellationToken); string finalText = "Recognized text from ListenAsync."; recognitionResult?.Report(finalText); return new SpeechToTextResult(finalText, null); } public async Task StartListenAsync(CultureInfo culture, CancellationToken cancellationToken) { await Task.Delay(1000, cancellationToken); CurrentState = SpeechToTextState.Listening; StateChanged?.Invoke(this, new SpeechToTextStateChangedEventArgs(CurrentState)); Device.StartTimer(TimeSpan.FromSeconds(1), () => { RecognitionResultUpdated?.Invoke(this, new SpeechToTextRecognitionResultUpdatedEventArgs(new SpeechToTextRecognitionResult("Simulated intermediate result."))); return true; }); } public async Task StopListenAsync(CancellationToken cancellationToken) { await Task.Delay(500, cancellationToken); CurrentState = SpeechToTextState.Stopped; StateChanged?.Invoke(this, new SpeechToTextStateChangedEventArgs(CurrentState)); RecognitionResultCompleted?.Invoke(this, new SpeechToTextRecognitionResultCompletedEventArgs(new SpeechToTextRecognitionResult("Simulated final result."))); } public async Task<bool> RequestPermissions(CancellationToken cancellationToken) { await Task.Delay(500, cancellationToken); return true; } public ValueTask DisposeAsync() { return ValueTask.CompletedTask; } }

Xamarin
Xamarin
A Microsoft open-source app platform for building Android and iOS apps with .NET and C#.
5,362 questions
.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,905 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,578 questions
0 comments No comments
{count} votes