loadTtsModel method
Load a TTS model.
Implementation
void loadTtsModel(
String modelPath, {
String modelType = 'vits',
Map<String, dynamic>? config,
}) {
_ensureBackendType('onnx');
final pathPtr = modelPath.toNativeUtf8();
final handlePtr = calloc<RacHandle>();
final configPtr = calloc<RacTtsOnnxConfigStruct>();
// Set config defaults
configPtr.ref.numThreads = 0; // Auto
configPtr.ref.useCoreml = RAC_TRUE;
configPtr.ref.sampleRate = 22050;
try {
final create =
_lib.lookupFunction<RacTtsOnnxCreateNative, RacTtsOnnxCreateDart>(
'rac_tts_onnx_create');
final result = create(pathPtr, configPtr.cast(), handlePtr);
if (result != RAC_SUCCESS) {
throw NativeBackendException(
'Failed to load TTS model: ${RacCore.getErrorMessage(result)}',
code: result,
);
}
_handle = handlePtr.value;
_currentModel = modelPath;
} finally {
calloc.free(pathPtr);
calloc.free(handlePtr);
calloc.free(configPtr);
}
}