getTtsVoices method

List<String> getTtsVoices()

Get available TTS voices.

Implementation

List<String> getTtsVoices() {
  if (_handle == null || _backendType != 'onnx') return [];

  try {
    final getVoices = _lib.lookupFunction<RacTtsOnnxGetVoicesNative,
        RacTtsOnnxGetVoicesDart>('rac_tts_onnx_get_voices');

    final voicesPtr = calloc<Pointer<Pointer<Utf8>>>();
    final countPtr = calloc<IntPtr>();

    try {
      final status = getVoices(_handle!, voicesPtr, countPtr);

      if (status != RAC_SUCCESS) {
        return [];
      }

      final count = countPtr.value;
      final voices = <String>[];

      if (count > 0 && voicesPtr.value != nullptr) {
        for (var i = 0; i < count; i++) {
          final voicePtr = voicesPtr.value[i];
          if (voicePtr != nullptr) {
            voices.add(voicePtr.toDartString());
          }
        }
      }

      return voices;
    } finally {
      calloc.free(voicesPtr);
      calloc.free(countPtr);
    }
  } catch (_) {
    return [];
  }
}