Skip to main content

API Reference

DubbingEngine​

prepare​

Prepares the resources required by the engine and performs authentication. The first time it is called, it downloads the voice model files, which takes a longer time.

getVoiceList​

Gets the list of available voice tones. The list of available voice tones will only be returned after the engine is prepared.

Return value: ArrayList <DubbingVoice>, the list may be empty.

getCurrentVoice​

Gets the currently set voice. Return value: Voice id, may be null.

clearModelFiles​

Deletes the voice model files. After executing this method, the files will be re-downloaded the next time prepare() is called.

Return value: int, the number of files deleted. Note: The engine automatically cleans up unnecessary files. Developers should not store other files in the engine's file directory.

start​

Starts the voice conversion.

stop​

Stops the voice conversion, but does not exit the voice conversion thread. After executing this method, the data in the thread is cleared, and the thread goes to sleep.

getEngineStatus​

Gets the current status of the engine.

setVoice(voiceId: Int)​

When calling this method, it first checks if the model required for the voice tone has been loaded. If not, it loads the model into memory.

Sets the voice. This operation is asynchronous, and the result is returned in the DubbingCallback callback.

Note: It can only be set successfully after the engine is prepared. It can be set whether voice conversion is currently active or not. For example, if voice conversion is active, the sound will immediately change to the new voice tone upon successful setting.

releaseEngine​

Releases the engine resources and terminates the thread.

transform(originData: ByteArray): ByteArray?​

Converts the audio data. Input: originData: ByteArray. Returns: ByteArray? (converted data).

transform(buffer: ByteBuffer): ByteArray?​

Converts the audio data. Input: buffer: ByteBuffer. Returns: ByteArray? (converted data).

transform(originalData: FloatArray): FloatArray?​

Converts the audio data. Input: originalData: FloatArray. Returns: FloatArray? (converted data).

checkResources​

Checks if required resource files need to be downloaded.

setMode​

Sets the engine's processing mode (e.g., Pro mode).

setMode(mode: DubbingMode, intonation: Float, pitch: Float)
Parameter NameParameter TypeDescription
mode[DubbingMode]Mode enumeration
intonationfloatEmotional fluctuation / Intonation
pitchfloatPitch

getSupportIntonation​

Checks if the current voice supports intonation adjustment.

getSupportPitch​

Checks if the current voice supports pitch adjustment.

getMode​

Gets the current engine mode setting.

getIntonation​

Gets the current intonation value.

getPitch​

Gets the current pitch value.

proCalibration​

Performs calibration for Pro mode.

getDelayMillis(): Int​

Gets the processing delay (latency) in milliseconds. Returns: Int.

DubbingEngine Default Values Description​

Parameter NameParameter TypeDefault ValueDescription
callbackDubbingCallbacknullEngine event callback
sampleRateInt48000Sample Rate
samplesPerCallIntSample size for each audio data callback. Default calculated by the engine: samplesPerCall = sampleRate / 100 * 16 * format.bytes * channel. 16 stands for 160 milliseconds.
mTokenStringnullAuthentication token, obtained by the developer.
debugHelperTransformDebugHelpernullCalculation utility class, can statistical performance data during voice transformation. Only takes effect when transformDebug is true.
muteOnFailBooleantrueWhether to mute when voice transformation fails.
debugBooleanfalseWhether to print engine operation Log
transformDebugBooleanfalseWhether to print engine voice transformation process Log. Enabling this will greatly increase the Log output volume.
resourcePathStringdubbing_resourceThe default value is obtained via the following code: "${context?.filesDir}/dubbing_resource".
channelInt1Default channel count.
formatAudioSampleFormatAUDIO_PCM_S16Default audio format.
isSyncBooleanfalseWhether to perform synchronous transform.

DubbingEngine.EngineConfig​

EngineConfig(context: Context)​

Constructor.

enableLog (Optional)​

Enables Log printing, which only prints process information during engine operation.

enableTransformLog (Optional)​

Enables voice transformation Log. Voice transformation is a high-frequency operation, and enabling this will cause the Log information to refresh quickly.

enableTransformLog(TransformDebugHelper) (Optional)​

Effect is the same as transformLog(), and the helper will record various time data of the voice transformation.

token​

Authentication token, issued by the server.

sampleRate​

Sample Rate. The default value is 48000. Common optional values include 16000, 24000, and 48000.

engineCallback(callback)​

Engine Callback.

Parameter NameParameter TypeDescription
callbackDubbingCallback Interface/** Downloads progress * @param percent Current download file progress, integer from 0-100, 100 means current file download is complete * @param index The index of the current file being downloaded, starting from 1 * @param count The total number of files to be downloaded */ fun onDownload(percent: Int , index: Int, count: Int)
/** Event change * @param action Event * @param code Event result * @param msg Message */ fun onActionResult(action: DubbingAction, code: DubbingEngineCode, msg: String? = null )

buildEngine​

Builds the DubbingEngine instance.

muteOnFail​

Whether to mute when voice transformation fails.

sync​

Set synchronous transform enable.

channel​

Number of audio channels.

format​

Set audio format.

samplesPerCall​

Sample size for each audio data callback. The length of each frame needs to be a multiple of 10 milliseconds. If you require 10 milliseconds of data, 16 bits, single channel, and sample rate 48000.

val bytes = 2
val channel = 1
samplesPerCall = 48000 / 100 * bytes * channel

DubbingCallback​

onDownload(percent: Int, index: Int, count: Int)​

Parameter NameParameter TypeDescription
percentintCurrent file download progress, ranging from 0 to 100. 100 means 100%.
indexintThe index of the current file being downloaded, starting from 1.
countintThe total number of files to be downloaded.

onActionResult(action: DubbingAction, code: DubbingEngineCode, msg: String?)​

Parameter NameParameter TypeDescription
actionDubbingAction EnumEvent type.
codeDubbingEngineCode EnumEvent result.
msgStringEvent message, may be null.

DubbingAction​

Enum ValueDescription
SET_VOICESet voice.
AUTHAuth action.
PREPAREPrepare engine.
CHECK_RESOURCESCheck file.
PRO_CALIBRATIONPro mode calibration.

DubbingEngineCode​

Enum ValueDescription
SUCCESSSuccess.
UNKNOWN_ERRORUnknown error.
NET_REQUEST_ERRORNetwork Error.
NET_AUTH_ERRORAuthentication failed.
LIC_ERRORAuthentication failed.
ENGINE_STATUS_ERRORThe current engine status does not support this operation.
RESOURCE_MISSING_FILESMissing files.
VOICE_SETTINGA voice already in the process of being set.
VOICE_NOT_SETVoice not set.

DubbingEngineStatus​

Enum ValueDescription
IDLEInstance successfully created.
PREPARINGEngine resources are being prepared.
PREPAREDEngine resources are ready.
STARTEDVoice transformation started.
STOPPEDVoice transformation stopped.
RELEASEDEngine has been released.
ERROREngine error.
CHECKINGResource files are being checked.
CALIBRATINGAuto calibration is in progress.

DubbingVoice​

Member VariableDescription
idVoice ID.
nameVoice name.

DubbingMode​

Enum ValueDescription
NORMAL_MODENormal mode.
PRO_MODEPro mode.