say method

SpeechHandle say(
  1. String text
)

Speak text now, outside the turn loop, returning immediately with a handle to the in-flight utterance.

Throws SDKException when the session is closed.

Implementation

SpeechHandle say(String text) {
  if (_closed) {
    throw SDKException.invalidState('Voice session is closed');
  }
  _events.add(const VoiceAgentStateChanged(AgentState.speaking));
  final handle = _tts.speak(text);
  unawaited(
    handle.waitForPlayout().then((_) {
      if (!_events.isClosed) {
        _events.add(const VoiceAgentStateChanged(AgentState.listening));
      }
    }),
  );
  return handle;
}