Voice Package Download

Last Updated on : 2024-11-18 11:33:15download

Sweeper SDK can be integrated to implement multiple capabilities. For example, download a voice package and listen for the download progress.

The Tuya Developer Platform currently does not support configurations of voice packages. You can ask Tuya’s account manager to help with the configurations.

Access the feature

The legacy and new SDK versions are accessed in different ways. For more information, see Changelog.

  • The legacy versions earlier than SDK v0.1.0 are accessed with ITuyaSweeper:

    ITuyaSweeper  iTuyaSweeper = TuyaHomeSdk.getSweeperInstance()
    
  • SDK v0.1.0 and later are accessed with ITuyaSweeperKit:

    ITuyaSweeperKitSdk iTuyaSweeperKitSdk = TuyaOptimusSdk.getManager(ITuyaSweeperKitSdk.class);
    
    ITuyaSweeperFileDownload iTuyaSweeperFileDownload = iTuyaSweeperKitSdk.newFileDownloadInstance(devId);
    

Query a list of voice packages

  • Versions earlier than SDK v0.1.0: not supported
  • SDK v0.1.0 and later: supported

API description

void getFileList(final ITuyaResultCallback<ArrayList<SweeperFileListInfoBean>> callback);

Data structure of SweeperFileListInfoBean

Field Type Description
id long The voice package ID.
name String The name of the voice package.
desc String The description of the voice package.
auditionUrl String The URL for downloading the audition version of the voice package.
officialUrl String The URL for downloading the official version of the voice package.
imgUrl String The URL of the voice package icon.
region List The country or region code.

Example

ITuyaSweeperKitSdk iTuyaSweeperKitSdk = TuyaOptimusSdk.getManager(ITuyaSweeperKitSdk.class);

ITuyaSweeperFileDownload iTuyaSweeperFileDownload = iTuyaSweeperKitSdk.newFileDownloadInstance(devId);

iTuyaSweeperFileDownload.getFileList(new ITuyaResultCallback<ArrayList<SweeperFileListInfoBean>>() {
	@Override
	public void onSuccess(ArrayList<SweeperFileListInfoBean> result) {

	}

	@Override
	public void onError(String errorCode, String errorMessage) {

	}
});

Register and unregister a listener

  • Versions earlier than SDK v0.1.0: not supported
  • SDK v0.1.0 and later: supported

API description

void registerDownloadListener(final ISweeperFileDownloadListener listener)

void unRegisterDownloadListener();

Data structure of ISweeperFileDownloadListener

/**
 *
 * @param type The type of file. A voice package is represented by `DOWNLOAD_VOICE`.
 * @param fileDownloadEnum The Enum values of the download status. For example, a file can be downloaded or failed to be downloaded.
 */
void onResultStatus(String type, SweeperFileDownloadEnum fileDownloadEnum);

/**
 *
 * @param type
 * @param progress The download progress.
 */
void onProgress(String type, int progress);

Example

ITuyaSweeperKitSdk iTuyaSweeperKitSdk = TuyaOptimusSdk.getManager(ITuyaSweeperKitSdk.class);

ITuyaSweeperFileDownload iTuyaSweeperFileDownload = iTuyaSweeperKitSdk.newFileDownloadInstance(devId);

iTuyaSweeperFileDownload.registerDownloadListener(new ISweeperFileDownloadListener() {
	@Override
	public void onResultStatus(String type, SweeperFileDownloadEnum fileDownloadEnum) {

	}

	@Override
	public void onProgress(String type, int progress) {

	}
});
iTuyaSweeperFileDownload.unRegisterDownloadListener();

Confirm voice package downloading

  • Versions earlier than SDK v0.1.0: not supported
  • SDK v0.1.0 and later: supported

API description

/**
 *
 * @param fileId The voice package ID.
 * @param callback
 */
void confirmDownload(long fileId, final ITuyaResultCallback<Integer> callback);

Example

ITuyaSweeperKitSdk iTuyaSweeperKitSdk = TuyaOptimusSdk.getManager(ITuyaSweeperKitSdk.class);

ITuyaSweeperFileDownload iTuyaSweeperFileDownload = iTuyaSweeperKitSdk.newFileDownloadInstance(devId);

iTuyaSweeperFileDownload.confirmDownload(1000, new ITuyaResultCallback<Integer>() {
	@Override
	public void onSuccess(Integer result) {

	}

	@Override
	public void onError(String errorCode, String errorMessage) {

	}
});

Query file download progress

  • Versions earlier than SDK v0.1.0: not supported
  • SDK v0.1.0 and later: supported

API description

void queryProgress(final ITuyaResultCallback<SweeperProgressbean> callback);

Data structure of SweeperProgressbean

Field Type Description
id long The voice package ID.
rate int The download progress.
status int The download status. Valid values:
  • 0: not downloaded
  • 1: downloading

Example

ITuyaSweeperKitSdk iTuyaSweeperKitSdk = TuyaOptimusSdk.getManager(ITuyaSweeperKitSdk.class);

ITuyaSweeperFileDownload iTuyaSweeperFileDownload = iTuyaSweeperKitSdk.newFileDownloadInstance(devId);

iTuyaSweeperFileDownload.queryProgress(new ITuyaResultCallback<SweeperProgressbean>() {
	@Override
	public void onSuccess(SweeperProgressbean result) {

	}

	@Override
	public void onError(String errorCode, String errorMessage) {

	}
});

Finish voice package download

  • Versions earlier than SDK v0.1.0: not supported
  • SDK v0.1.0 and later: supported

Finishes and exits the downloading process to avoid the excessive use of process resources.

API description

void onDestroy();