flutter_tts
flutter_tts copied to clipboard
Run text to speech service, when we receive certain key from notifications
💬 Questions and Help
I'm currently working on implementing a feature where the app should read the notification text when specific keys are present in the notification data. This functionality needs to work seamlessly in the foreground, background, and even when the app is closed. However, despite my efforts, I haven't been able to get it to work reliably.
Below is a snippet of the code I've been working on:
FirebaseMessaging.onMessage.listen((RemoteMessage message) async {
await showNotification(message);
});
Future<void> showNotification(RemoteMessage message) async {
if (message.data.containsKey("moe_channel_id") ||
message.data.containsKey("moe_inapp")) {
if (message.data.containsKey("voice") && message.data['voice'] == "true") {
playSound(text: message.data['gcm_title'] ?? "");
}
}
// Additional code...
}
void playSound({required String text}) {
try {
FlutterTts flutterTts = FlutterTts();
flutterTts.speak(text);
} catch(e) {
// Error Handling
}
}
I would greatly appreciate any insights or assistance from fellow developers on how to ensure this feature works reliably across different app states. Thank you in advance for your help!
@mishraaditya595 Is something not working related specifically to this plugin here?
Yes, as mentioned, I am trying to trigger the speak() method when I receive a certain notification. But it is not working then.