-
Notifications
You must be signed in to change notification settings - Fork 425
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PR] Return support Android 33 offline speech recognition #2578
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR adds support for Android 33 for offline speech recognition while refining culture/language checks and download triggers.
- Updated Android version checks from 34 to 33 where appropriate.
- Revised language support checks to distinguish between supported, pending, and installed languages.
- Introduced separate methods for triggering offline recognizer downloads on Android 33 and Android 34.
...munityToolkit.Maui.Core/Essentials/SpeechToText/OfflineSpeechToTextImplementation.android.cs
Outdated
Show resolved
Hide resolved
...munityToolkit.Maui.Core/Essentials/SpeechToText/OfflineSpeechToTextImplementation.android.cs
Show resolved
Hide resolved
} | ||
if (recognitionSupportResult.PendingOnDeviceLanguages.Contains(options.Culture.Name)) | ||
{ | ||
throw new Exception($"Speech Recognition {options.Culture.Name} pending download. Loading can be delayed if WiFi only"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exception is not correct in this case. Developer needs to be notified when download is completed.
The correct behavior is waiting for the download.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- If the language is not supported at all in Supportedondevicelanguages, it makes no sense to do anything, so I suffered :
throw new NotSupportedException($"Culture '{options.Culture.Name}' is not supported");
- The download can be delayed for an indefinite period or not at all if there is no connection by WiFi. For example, in my case (Android 33), the download occurred only at night when connecting to wifi in home. This should be reported immediately, and not wait indefinite period.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to notify the user and ask to download using mobile data? Like store does when you try to download some app?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to notify the user and ask to download using mobile data? Like store does when you try to download some app?
I did not find such an API to switch to mobile data. I also did not find an API, which method (WiFi or mobile) is now configured. If a solution is in the future, it will be possible to reconsider the logic of loading packages.
Android 34 has an extended TriggerModelDownload with ModelDownloadListener(OnProgress, OnScheduled) is better than nothing, but this is not an answer to your question - https://developer.android.com/reference/android/speech/ModelDownloadListener
|
||
var downloadLanguageTask = new TaskCompletionSource(); | ||
speechRecognizer.TriggerModelDownload(recognizerIntent, new Executor(), new ModelDownloadListener(downloadLanguageTask)); | ||
await downloadLanguageTask.Task.WaitAsync(token); | ||
} | ||
|
||
speechRecognizer.SetRecognitionListener(listener); | ||
speechRecognizer.StartListening(recognizerIntent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not start recognition if language is not installed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I thought about it, it would be possible to do so:
else if (OperatingSystem.IsAndroidVersionAtLeast(33))
{
TryDownloadOfflineRecognizer33(recognizerIntent);
throw new Exception($"Speech Recognition {options.Culture.Name} pending download. Loading can be delayed if WiFi only");
}
but there is a chance that the package will load before the recognition launch.
I decided not to complicate the code now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have concerns about user behavior with Android 33. Recognition starts before language is downloaded. Getting infinite exception in case language is pending download (as there is no way to notify user when it is finished), more code with checks for different API versions.
All these issues are resolved in Android 34 (just one version up), so I am voting for closing this PR and keeping minimum version = 34.
I don't understand your concerns.
Look carefully again, someone third may judge us. We can add your corrections. I am for the discussion. Another one reason to Android 33 - no matter how interesting it, but I can’t help you, I do not have device with android 34 and above ;-) |
How do you plan to use the API? do
{
try
{
await speechRecognizer.StartListening(...);
}
catch
{
}
}
while (speechRecognizer.State != State.Listening) Android 34 displays the popup and shows a download progress in the notification. |
You can use it like that:
I want to make voice control in my application. The prototype of API using is not yet reached. In theory, yes, a continuous listening is needed. my Android 33(S20+) keep silent when loading |
…SpeechToTextImplementation.android.cs Co-authored-by: Copilot <[email protected]>
… be scheduled on WiFi
I don't like this API, is error prone and not intuitive at all. I advocate to rethink it or add some way to extend what we've today, then devs can implement how they want to handle this feature in older versions |
my PR - not about the API and not about use. This PR about the fact that if it is impossible to immediately start recognition for any reason, then you need to give out exception, +android 33. |
Nothing complicated, just returned the support of Android 33.
Corrected check placement: "Culture ... is not supported".
Added check, that the language is pending downloading (including delayed through Wi-Fi)
Added check, that avoids endless expectation if the load will be scheduled on WiFi
Description of Change
Linked Issues
#2463 (comment)
PR Checklist
approved
(bug) orChampioned
(feature/proposal)main
at time of PRAdditional information