package com.sinovoice.pathfinder.hcicloud.hwr;

import android.content.Context;
import android.util.Log;

import com.sinovoice.hcicloudsdk.api.hwr.HciCloudHwr;
import com.sinovoice.hcicloudsdk.common.hwr.HwrInitParam;
import com.sinovoice.pathfinder.hcicloud.sys.SysConfig;

public class HciCloudHwrHelper {
    private static final String TAG = HciCloudHwrHelper.class.getSimpleName();

    private static HciCloudHwrHelper mInstance;

    private HciCloudHwrHelper() {
    }

    public static HciCloudHwrHelper getInstance() {
        if (mInstance == null) {
            mInstance = new HciCloudHwrHelper();
        }
        return mInstance;
    }

    /**
     * HWRÊÖÐ´Ê¶±ðÄÜÁ¦³õÊ¼»¯£¬·µ»ØµÄ´íÎóÂë¿ÉÒÔÔÚAPIÖÐHciErrorCode²é¿´
     * 
     * @param context
     * @return ´íÎóÂë, return 0 ±íÊ¾³É¹¦
     */
    public int init(Context context) {
        int initResult = 0;

        // ¹¹ÔìHwr³õÊ¼»¯µÄ²ÎÊýÀàµÄÊµÀý
        HwrInitParam hwrInitParam = new HwrInitParam();

        // »ñÈ¡AppÓ¦ÓÃÖÐµÄlibµÄÂ·¾¶,Èç¹ûÊ¹ÓÃ/data/data/pkgName/libÏÂµÄ×ÊÔ´ÎÄ¼þ,ÐèÒªÌí¼Óandroid_soµÄ±ê¼Ç
        String hwrDirPath = context.getFilesDir().getAbsolutePath()
                .replace("files", "lib");
        hwrInitParam.addParam(HwrInitParam.PARAM_KEY_DATA_PATH, hwrDirPath);
        hwrInitParam.addParam(HwrInitParam.PARAM_KEY_FILE_FLAG, "android_so");
        hwrInitParam.addParam(HwrInitParam.PARAM_KEY_INIT_CAP_KEYS,
                SysConfig.CAPKEY_HWR);

        Log.d(TAG, "hwr init config: " + hwrInitParam.getStringConfig());

        // HWR ³õÊ¼»¯
        initResult = HciCloudHwr.hciHwrInit(hwrInitParam.getStringConfig());
        return initResult;
    }

    /**
     * HWRÊÖÐ´Ê¶±ðÄÜÁ¦·´³õÊ¼»¯£¬·µ»ØµÄ´íÎóÂë¿ÉÒÔÔÚAPIÖÐHciErrorCode²é¿´
     * 
     * @return ´íÎóÂë, return 0 ±íÊ¾³É¹¦
     */
    public int release() {
        int result = HciCloudHwr.hciHwrRelease();
        return result;
    }
}
