diff --git a/samples/CommunityToolkit.Maui.Sample.sln b/samples/CommunityToolkit.Maui.Sample.sln
index 94bec1c258..b94d7142c8 100644
--- a/samples/CommunityToolkit.Maui.Sample.sln
+++ b/samples/CommunityToolkit.Maui.Sample.sln
@@ -14,7 +14,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
..\.editorconfig = ..\.editorconfig
..\Directory.Build.props = ..\Directory.Build.props
..\Directory.Build.targets = ..\Directory.Build.targets
- ..\global.json = ..\global.json
EndProjectSection
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Maui.Core", "..\src\CommunityToolkit.Maui.Core\CommunityToolkit.Maui.Core.csproj", "{6B572EAD-1581-46BE-A08B-1C7F2246BA2E}"
@@ -51,7 +50,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Maui.Camer
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Benchmarks", "Benchmarks", "{ED5A9C0B-D270-442D-BABE-F4FF622926C8}"
EndProject
-Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Maui.Analyzers.Benchmarks.csproj", "..\src\CommunityToolkit.Maui.Analyzers.Benchmarks\CommunityToolkit.Maui.Analyzers.Benchmarks.csproj", "{B80F59B7-276C-4A55-A8DD-54587C8BC3D2}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Maui.Analyzers.Benchmarks", "..\src\CommunityToolkit.Maui.Analyzers.Benchmarks\CommunityToolkit.Maui.Analyzers.Benchmarks.csproj", "{B80F59B7-276C-4A55-A8DD-54587C8BC3D2}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
diff --git a/samples/CommunityToolkit.Maui.Sample/Pages/Essentials/OfflineSpeechToTextPage.xaml b/samples/CommunityToolkit.Maui.Sample/Pages/Essentials/OfflineSpeechToTextPage.xaml
index 1fec0cb133..e2821e21bd 100644
--- a/samples/CommunityToolkit.Maui.Sample/Pages/Essentials/OfflineSpeechToTextPage.xaml
+++ b/samples/CommunityToolkit.Maui.Sample/Pages/Essentials/OfflineSpeechToTextPage.xaml
@@ -9,28 +9,15 @@
x:DataType="vm:OfflineSpeechToTextViewModel"
Title="OfflineSpeechToText">
-
-
-
-
-
-
-
-
@@ -53,11 +40,6 @@
HorizontalTextAlignment="Center"
MinimumHeightRequest="100" />
-
-
speechToText.CurrentState;
[ObservableProperty]
string? recognitionText = "Welcome to .NET MAUI Community Toolkit!";
- [ObservableProperty, NotifyCanExecuteChangedFor(nameof(StartListenCommand))]
- bool canStartListenExecute = true;
-
- [ObservableProperty, NotifyCanExecuteChangedFor(nameof(StopListenCommand))]
- bool canStopListenExecute;
-
- public OfflineSpeechToTextViewModel(ITextToSpeech textToSpeech)
+ public OfflineSpeechToTextViewModel()
{
- this.textToSpeech = textToSpeech;
// For demo purposes. You can resolve dependency from the DI container,
- this.speechToText = OfflineSpeechToText.Default;
-
- Locales.CollectionChanged += HandleLocalesCollectionChanged;
- this.speechToText.StateChanged += HandleSpeechToTextStateChanged;
- this.speechToText.RecognitionResultCompleted += HandleRecognitionResultCompleted;
- }
-
- public ObservableCollection Locales { get; } = [];
-
- [RelayCommand]
- async Task SetLocales(CancellationToken token)
- {
- Locales.Clear();
-
- var locales = await textToSpeech.GetLocalesAsync().WaitAsync(token);
-
- foreach (var locale in locales.OrderBy(x => x.Language).ThenBy(x => x.Name))
- {
- Locales.Add(locale);
- }
+ speechToText = OfflineSpeechToText.Default;
- CurrentLocale = Locales.FirstOrDefault(x => x.Language is defaultLanguage or defaultLanguageAndroid or defaultLanguageTizen) ?? Locales.FirstOrDefault();
+ speechToText.StateChanged += HandleSpeechToTextStateChanged;
+ speechToText.RecognitionResultCompleted += HandleRecognitionResultCompleted;
}
[RelayCommand]
- async Task Play(CancellationToken cancellationToken)
- {
- var timeoutCancellationTokenSource = new CancellationTokenSource(TimeSpan.FromSeconds(5));
-
- try
- {
- await textToSpeech.SpeakAsync(RecognitionText ?? "Welcome to .NET MAUI Community Toolkit!", new()
- {
- Locale = CurrentLocale,
- Pitch = 1,
- Volume = 1
- }, cancellationToken).WaitAsync(timeoutCancellationTokenSource.Token);
- }
- catch (TaskCanceledException)
- {
- await Toast.Make("Playback automatically stopped after 5 seconds").Show(cancellationToken);
-#if IOS
- await Toast.Make("If you did not hear playback, test again on a physical iOS device").Show(cancellationToken);
-#endif
- }
- }
-
- [RelayCommand(CanExecute = nameof(CanStartListenExecute))]
async Task StartListen()
{
- CanStartListenExecute = false;
-
var isGranted = await speechToText.RequestPermissions(CancellationToken.None);
if (!isGranted)
{
@@ -100,9 +40,9 @@ async Task StartListen()
speechToText.RecognitionResultUpdated += HandleRecognitionResultUpdated;
- await speechToText.StartListenAsync(new SpeechToTextOptions()
+ await speechToText.StartListenAsync(new SpeechToTextOptions
{
- Culture = CultureInfo.GetCultureInfo(CurrentLocale?.Language ?? defaultLanguage),
+ Culture = CultureInfo.CurrentCulture,
ShouldReportPartialResults = true
}, CancellationToken.None);
@@ -112,12 +52,9 @@ await speechToText.StartListenAsync(new SpeechToTextOptions()
}
}
- [RelayCommand(CanExecute = nameof(CanStopListenExecute))]
+ [RelayCommand]
Task StopListen()
{
- CanStartListenExecute = true;
- CanStopListenExecute = false;
-
speechToText.RecognitionResultUpdated -= HandleRecognitionResultUpdated;
return speechToText.StopListenAsync(CancellationToken.None);
@@ -137,9 +74,4 @@ void HandleSpeechToTextStateChanged(object? sender, SpeechToTextStateChangedEven
{
OnPropertyChanged(nameof(State));
}
-
- void HandleLocalesCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
- {
- OnPropertyChanged(nameof(CurrentLocale));
- }
}
\ No newline at end of file
diff --git a/src/CommunityToolkit.Maui.Core/Essentials/SpeechToText/OfflineSpeechToTextImplementation.android.cs b/src/CommunityToolkit.Maui.Core/Essentials/SpeechToText/OfflineSpeechToTextImplementation.android.cs
index 071e9b8e71..ee0449d724 100644
--- a/src/CommunityToolkit.Maui.Core/Essentials/SpeechToText/OfflineSpeechToTextImplementation.android.cs
+++ b/src/CommunityToolkit.Maui.Core/Essentials/SpeechToText/OfflineSpeechToTextImplementation.android.cs
@@ -70,7 +70,6 @@ void InternalStartListening(SpeechToTextOptions options)
speechRecognizer = SpeechRecognizer.CreateOnDeviceSpeechRecognizer(Application.Context);
speechRecognizer.TriggerModelDownload(recognizerIntent);
-
listener = new SpeechRecognitionListener(this)
{
Error = HandleListenerError,