CommunityToolkit / CommunityToolkit/dotnet

SpeechToText.ListenAsync reports twice

Open
#844 2 comments 0 reactions 0 assignees View on GitHub
bug :bug:
Dominant language
C#
Stars
3.8k
Forks
400
PR merge metrics
No merged PRs in 30d

Description

### Describe the bug

iOS (iPAD 10)

There could be two issues here.

First, I don't know if it's a typo by Vladislav Antonyuk but on this page: https://devblogs.microsoft.com/dotnet/speech-recognition-in-dotnet-maui-with-community-toolkit/

It refers to using the listenAsync like this:

var recognitionResult = await SpeechToText.Default.ListenAsync(
CultureInfo.GetCultureInfo("uk-ua"),
new Progress(partialText =>
{
RecognitionText += partialText + " ";
}), cancellationToken);

The recognitionText += partialText + " ";

will duplicate the sentence / phrase being spoken. It's like it's meant to spit out word by word instead of repeating words.

And since the recognitionComplete event is not firing, I've reverted to using timers. But I noticed another weird issue. I have another open case on here regarding that. I can get the recognitionComplete to fire, only if I watch with a breakpoint on the recognitionUpdated event. But that's for the other bug report.

If I say one word like "test", or "one" the SpeechToText will fire off this word twice which is causing issues with my events handing the incoming test.

### Regression

_No response_

### Steps to reproduce

```text
.net 8, Maui

This is my code:

var recognitionResult = await speechToText.ListenAsync(CultureInfo.GetCultureInfo("en-us"),
new Progress(partialText =>
{
Debug.WriteLine("--- " + partialText + "---");

RecognitionText = partialText + " ";

}), cancellationToken);

I say "one" and in the debug window I'll see:

--- One---
--- One---

There is about a 1-2 second pause between the two displays.

If there was a way to clear out the buffer that would fix it, but I have a feeling that this behavior isn't supposed to be occurring..

Incidentally, the await speecToText.ListenAsync continuously listens, it never returns so I cannot use the "recognitionResult". Probably because of the fact that it doesn't ever hit the OnRecognitionTextComplete event...?
```

### Expected behavior

Should only report once. I'm also thinking it should report the words as it sees, not the full sentence each time. And if it is supposed to be reporting the full sentence, then it should only report once.

### Screenshots

_No response_

### IDE and version

VS 2022

### IDE version

17.9

### Nuget packages

- [ ] CommunityToolkit.Common
- [ ] CommunityToolkit.Diagnostics
- [ ] CommunityToolkit.HighPerformance
- [X] CommunityToolkit.Mvvm (aka MVVM Toolkit)

### Nuget package version(s)

mvvm - 8.2.2, maui - 7.0.1

### Additional context

_No response_

### Help us help you

No, just wanted to report this

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.