Voice Package Download

Last Updated on : 2024-06-26 09:44:21download

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.

Query a list of voice packages

API description

void getFileList(final IThingResultCallback<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 sample voice package.
officialUrl String The URL for downloading the complete voice package.
imgUrl String The URL of the voice package icon.
region List<String> The country or region code.

Example

IThingSweeperKitSdk iThingSweeperKitSdk = ThingOptimusSdk.getManager(IThingSweeperKitSdk.class);

IThingSweeperFileDownload iThingSweeperFileDownload = iThingSweeperKitSdk.newFileDownloadInstance(devId);

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

    }

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

    }
});

Query a list of voice files on pages

API description

void getFileList(int offset, int limit, IThingResultCallback<SweeperFileListPageBean> callback);

Parameters

Parameter Description
offset The offset of returned data to display data on pages.
limit The maximum number of entries to be returned in each call.
callback Trigger a data callback

Data structure of SweeperFileListPageBean

Field Type Description
datas List<SweeperFileListInfoBean> List of SweeperFileListInfoBean
totalCount int The total number of entries.

Example

IThingSweeperKitSdk iThingSweeperKitSdk = ThingOptimusSdk.getManager(IThingSweeperKitSdk.class);

IThingSweeperFileDownload iThingSweeperFileDownload = iThingSweeperKitSdk.newFileDownloadInstance(devId);

iThingSweeperFileDownload.getFileList(0, 10, new IThingResultCallback<SweeperFileListPageBean>() {
    @Override
    public void onSuccess(SweeperFileListPageBean result) {

    }

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

    }
});

Register and unregister a listener

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

IThingSweeperKitSdk iThingSweeperKitSdk = ThingOptimusSdk.getManager(IThingSweeperKitSdk.class);

IThingSweeperFileDownload iThingSweeperFileDownload = iThingSweeperKitSdk.newFileDownloadInstance(devId);

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

    }

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

    }
});
iThingSweeperFileDownload.unRegisterDownloadListener();

Confirm voice package downloading

API description

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

Example

IThingSweeperKitSdk iThingSweeperKitSdk = ThingOptimusSdk.getManager(IThingSweeperKitSdk.class);

IThingSweeperFileDownload iThingSweeperFileDownload = iThingSweeperKitSdk.newFileDownloadInstance(devId);

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

    }

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

    }
});

Query file download progress

API description

Returns the current download progress.

void queryProgress(final IThingResultCallback<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

IThingSweeperKitSdk iThingSweeperKitSdk = ThingOptimusSdk.getManager(IThingSweeperKitSdk.class);

IThingSweeperFileDownload iThingSweeperFileDownload = iThingSweeperKitSdk.newFileDownloadInstance(devId);

iThingSweeperFileDownload.queryProgress(new IThingResultCallback<SweeperProgressbean>() {
    @Override
    public void onSuccess(SweeperProgressbean result) {

    }

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

    }
});

Finish voice package download

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

API description

void onDestroy();