Use text-to-speech for incoming messages
How to synthesize incoming text messages as speech.
Read time 1 minuteLast updated 2 days ago
To use text-to-speech (TTS) to read incoming messages, use the
Speak()TTSDestination::QueuedLocalPlayback- When a text message is received in a channel, the event is raised.
IChannelSession::EventTextMessageReceived - When a direct message is received in a channel, the event is raised.
ILoginSession::EventDirectedTextMessageReceived
MyChannelSession->EventTextMessageReceived.AddLambda([MyLoginSession](const IChannelTextMessage &Message){ // If the text message received is not from me... if (Message.Sender() != MyLoginSession->LoginSessionId()) { // Check if optional display name is set. FString DisplayName = Message.Sender().DisplayName(); if (DisplayName.IsEmpty()) { DisplayName = "Anonymous"; } // This queues the message and lets the user know who sent it. // NB: the colon (:) inserts a slight pause before subsequent text. FString Text = DisplayName + " says: " + Message.Message(); MyLoginSession->TTS().Speak(Text, TTSDestination::QueuedLocalPlayback); }});