Basic Usage
During a persona session, you can force a response from the persona using thetalk method. This is useful when the user interacts with a UI element or when you use your own LLM instead of Anam’s built-in models.
Both
talk() and createTalkMessageStream() require an active streaming session. Call stream() or streamToVideoElement() first.To learn more about using the
talk method with your own LLM, see the Custom LLMs guide.Streaming Talk Input
For lower latency, stream messages to the persona in chunks. This works well when streaming output from a custom LLM.Each
TalkMessageStream represents one conversation turn. Once the turn ends, create a new stream for the next turn.Available Methods
TheTalkMessageStream object provides these methods:
| Method | Description |
|---|---|
streamMessageChunk(content, endOfSpeech) | Send a text chunk. Set endOfSpeech: true on the final chunk. |
endMessage() | End the stream without sending more content. Alternative to endOfSpeech: true. |
isActive() | Returns true if the stream can still accept chunks. |
getState() | Returns the current state: UNSTARTED, STREAMING, INTERRUPTED, or ENDED. |
getCorrelationId() | Returns the correlation ID for this stream. |
Ending a Stream
End a conversation turn in one of two ways: Option 1: SetendOfSpeech on the last chunk
endMessage() separately
Handling Interruptions
When a user speaks during a stream, the SDK emitsAnamEvent.TALK_STREAM_INTERRUPTED and closes the stream:
Checking Stream State
Check whether a stream can still accept chunks:Error Handling
ThestreamMessageChunk method throws an error if the stream is not active:
Correlation IDs
Attach a correlation ID to track streams, especially useful for matching interruption events:Use unique correlation IDs for each
TalkMessageStream. The ID appears in TALK_STREAM_INTERRUPTED events, helping you identify which stream was interrupted.Next Steps
Audio Control
Learn how to control audio input in your Anam sessions

