synthesizeTextToSpeechBackend method

Future<BackendTextToSpeechResult> synthesizeTextToSpeechBackend(
  1. BackendTextToSpeechRequest request, {
  2. void onProgress(
    1. BackendTextToSpeechProgress progress
    )?,
})

Runs backend-native text-to-speech for TextToSpeechEngine.

Applications should prefer TextToSpeechEngine.synthesize, which adds validation, task ownership, cancellation, and typed completion handling.

Implementation

Future<BackendTextToSpeechResult> synthesizeTextToSpeechBackend(
  BackendTextToSpeechRequest request, {
  void Function(BackendTextToSpeechProgress progress)? onProgress,
}) {
  _ensureReady();
  final mmContextHandle = _mmContextHandle;
  if (mmContextHandle == null) {
    throw LlamaStateException(
      'Load a text-to-speech multimodal projector first.',
    );
  }
  final candidate = backend;
  if (candidate is! BackendTextToSpeech) {
    throw LlamaUnsupportedException(
      'The active backend does not expose dedicated text-to-speech.',
    );
  }
  final textToSpeechBackend = candidate as BackendTextToSpeech;
  return _contextCall(
    () => textToSpeechBackend.synthesizeTextToSpeech(
      _contextHandle!,
      mmContextHandle,
      request,
      onProgress: onProgress,
    ),
  );
}