Skip to content

Commit 836ee20

Browse files
authored
Update VoiceChat.razor.cs
1 parent dad84e4 commit 836ee20

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

app/SharedWebComponents/Pages/VoiceChat.razor.cs

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,26 @@ private void OnSendPrompt()
8080
};
8181
}
8282

83-
SpeechSynthesis.Speak(utterance);
84-
85-
_isReadingResponse = false;
86-
StateHasChanged();
83+
try
84+
{
85+
SpeechSynthesis.Speak(utterance, duration =>
86+
{
87+
_isReadingResponse = false;
88+
StateHasChanged();
89+
});
90+
}
91+
catch
92+
{
93+
// TODO: Find a better way to do this
94+
// The Blazor.SpeechSynthesis.WebAssembly API supports the callback,
95+
// however the underlying code does not do this using a DI-friendly way.
96+
// The code assumes the concrete implementation for the ISpeechSynthesisService
97+
// service is the concrete Web Assembly type which is not valid. However, the
98+
// alternate API is something MAUI can implement.
99+
SpeechSynthesis.Speak(utterance);
100+
_isReadingResponse = false;
101+
StateHasChanged();
102+
}
87103
}
88104
}
89105

0 commit comments

Comments
 (0)