How to add continuous speech/talk - .NET MAUI Speech

Johnson 81 Reputation points
2024-07-19T12:58:44.29+00:00

I have the below .Net MAUI code that works great.

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

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

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

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;

}

}

.NET
.NET
Microsoft Technologies based on the .NET software framework.
3,915 questions
.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,588 questions
0 comments No comments
{count} votes

Accepted answer
  1. Yonglun Liu (Shanghai Wicresoft Co,.Ltd.) 43,931 Reputation points Microsoft Vendor
    2024-07-22T02:41:18.97+00:00

    Hello,

    Thanks for your feedback.

    According to the CommunityToolkit documentation, SpeechToText currently does not provide an API for pausing and resuming. Therefore, it is recommended that you publish this issue as a feature request to the official repository to make the development team aware of it.

    Best Regards,

    Alec Liu.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.