Talk Commands
Control persona output using talk commands
Basic Usage
Sometimes during a persona session, you may wish to force a response from the persona. For example, when the user interacts with an element on the page or when you have disabled the Anam LLM to use your own. To do this, use the talk
method:
This will force the persona to respond with the given text.
To learn more about how to use the talk
method to enable your own custom intelligence, see our Custom Brains guide.
Streaming Talk Input
For more advanced use cases, you can stream messages to the persona in multiple chunks. This is particularly useful when streaming output from a custom LLM to reduce latency.
One talkMessageStream represents one “turn” in the conversation. Once that turn is over, the stream can no longer be used and you must create a new TalkMessageStream
.
End of Speech and Interruptions
A conversation “turn” can end in one of two ways:
- End of speech: When
streamMessageChunk
is called withendOfSpeech: true
or theendMessage()
method is called - User interruption: When the user speaks during the stream, triggering an
AnamEvent.TALK_STREAM_INTERRUPTED
event
In both cases, the TalkMessageStream
object is closed and no longer usable. You can check if a stream is still active using:
Correlation IDs
For tracking purposes, you can attach a correlation ID to your talk streams by passing the optional correlationId
parameter to the createTalkMessageStream
method:
The correlationId
should be unique for every TalkMessageStream
instance. When a talk stream is interrupted, this ID will be included in the AnamEvent.TALK_STREAM_INTERRUPTED
event.
Next Steps
Audio Control
Learn how to control Audio Input in your Anam sessions
Was this page helpful?