Skip to content

Commit

Permalink
ui:fix minior issue
Browse files Browse the repository at this point in the history
  • Loading branch information
zhouwg committed Mar 31, 2024
1 parent 9090935 commit eb02b54
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,11 @@ public void initGlobal() {
CDEUtils.copyAssetFile(mContext, "res/png1.png", CDEUtils.getDataPath(mContext) + "png1.png");
CDEUtils.copyAssetFile(mContext, "res/png2.png", CDEUtils.getDataPath(mContext) + "png2.png");
CDEUtils.copyAssetFile(mContext, "res/simhei.ttf", CDEUtils.getDataPath(mContext) + "simhei.ttf");
String ggmlModelFileName = "ggml-tiny.en-q8_0.bin";//42M, ggml-tiny.en-q8_0.bin is preferred
String ggmlSampleFileName = "jfk.wav";
CDEAssetLoader.copyAssetFile(mContext, ggmlModelFileName, CDEUtils.getDataPath() + ggmlModelFileName);
CDEAssetLoader.copyAssetFile(mContext, ggmlSampleFileName, CDEUtils.getDataPath() + ggmlSampleFileName);

CDEAssetLoader.copyAssetFile(mContext, "config.json", CDEAssetLoader.getDataPath(mContext) + "config.json");
String configString = CDEAssetLoader.readTextFromFile(CDEAssetLoader.getDataPath(mContext) + "config.json");
JSONObject jsonObject = JSON.parseObject(configString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
package com.cdeos.kantv.ui.fragment;




import static cdeos.media.player.KANTVEvent.KANTV_INFO_ASR_FINALIZE;
import static cdeos.media.player.KANTVEvent.KANTV_INFO_ASR_STOP;

Expand Down Expand Up @@ -96,7 +94,7 @@ public class ASRResearchFragment extends BaseMvpFragment<ASRResearchPresenter> i
private int nThreadCounts = 1;
private int benchmarkIndex = 0;
private String strModeName = "tiny.en-q8_0";
private String strBackend = "cpu";
private String strBackend = "cpu";
private int backendIndex = 0; //CPU

private long beginTime = 0;
Expand All @@ -111,7 +109,7 @@ public class ASRResearchFragment extends BaseMvpFragment<ASRResearchPresenter> i
private ProgressDialog mProgressDialog;

//private String ggmlModelFileName = "ggml-tiny-q5_1.bin"; //31M
String ggmlModelFileName = "ggml-tiny.en-q8_0.bin";//42M, ggml-tiny.en-q8_0.bin is preferred
private String ggmlModelFileName = "ggml-tiny.en-q8_0.bin";//42M, ggml-tiny.en-q8_0.bin is preferred
private String ggmlSampleFileName = "jfk.wav";

private Context mContext;
Expand Down Expand Up @@ -326,11 +324,15 @@ else if (isQNNModel)
return;
}

selectModelFilePath = CDEUtils.getDataPath() + selectModeFileName;
if (!isQNNModel)
selectModelFilePath = CDEUtils.getDataPath() + selectModeFileName;
else
selectModelFilePath = CDEUtils.getDataPath(mContext) + selectModeFileName;

CDELog.j(TAG, "selectModelFilePath:" + selectModelFilePath);
selectModeFile = new File(selectModelFilePath);

displayFileStatus(CDEUtils.getDataPath() + ggmlSampleFileName, selectModelFilePath);

if (!selectModeFile.exists()) {
CDELog.j(TAG, "model file not exist:" + selectModeFile.getAbsolutePath());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public String getApiGatewayServerUrl() {

public boolean getDevMode() {
String key = mAppContext.getString(R.string.pref_key_dev_mode);
return mSharedPreferences.getBoolean(key, true);
return mSharedPreferences.getBoolean(key, false);
}

public int getDumpMode() {
Expand Down
9 changes: 5 additions & 4 deletions external/ggml/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ option(GGML_JNI_QNN "kantv-ggml-jni: use QNN(Qualcomm Neural Network) SDK"

#03-05-2024, PoC#64: English realtime subtitle for English on-line TV by whisper.cpp
set(WHISPERCPP_SRC_DIR ${CMAKE_SOURCE_DIR}/whispercpp/)
set(PREBUILT_LIB_PATH ${CMAKE_SOURCE_DIR}/../../cdeosplayer/kantv/src/main/jniLibs/${ANDROID_ABI}/)
set(PREBUILT_INC_PATH ${CMAKE_SOURCE_DIR}/../../prebuilts/include/)
set(PREBUILT_LIB_PATH ${CMAKE_SOURCE_DIR}/../../cdeosplayer/kantv/src/main/jniLibs/${ANDROID_ABI}/)
set(PREBUILT_INC_PATH ${CMAKE_SOURCE_DIR}/../../prebuilts/include/)
set(KANTV_GGMLJNI_SRC_DIR ${CMAKE_SOURCE_DIR}/jni)
set(GGML_SRC_DIR ${CMAKE_SOURCE_DIR}/)

Expand All @@ -27,6 +27,7 @@ set(LLAMACPP_SRC_DIR ${CMAKE_SOURCE_DIR}/llamacpp/)
set(QNN_INC_PATH ${CMAKE_SOURCE_DIR}/../../prebuilts/include/QNN)
set(QNN_LIB_PATH ${CMAKE_SOURCE_DIR}/../../prebuilts/lib/)
set(QNN_SRC_DIR ${CMAKE_SOURCE_DIR}/qnnsample/)

include_directories(${QNN_INC_PATH}/)
include_directories(${QNN_SRC_DIR}/)
include_directories(${QNN_SRC_DIR}/Utils)
Expand Down Expand Up @@ -75,8 +76,8 @@ set(SOURCE_FILES


message("WHISPERCPP_SRC_DIR : ${WHISPERCPP_SRC_DIR}")
message("PREBUILT_INC_PATH : ${PREBUILT_INC_PATH}")
message("PREBUILT_LIB_PATH : ${PREBUILT_LIB_PATH}")
message("PREBUILT_INC_PATH : ${PREBUILT_INC_PATH}")
message("PREBUILT_LIB_PATH : ${PREBUILT_LIB_PATH}")
message("PROJECT_ROOT_PATH : ${PROJECT_ROOT_PATH}")
message("target name : ${TARGET_NAME}")
message("build target : ${BUILD_TARGET}")
Expand Down
12 changes: 10 additions & 2 deletions external/ggml/jni/ggml-jni-impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -854,10 +854,11 @@ void ggml_jni_bench(const char * sz_model_path, const char *sz_audio_path, int n
"--model", const_cast<char *>(sz_model_path),
"--input_list", "/sdcard/kantv/raw_list.txt",
"--output_dir", "/sdcard/kantv/qnn/",
"--log_level", "info"
"--log_level", "debug"
};
//TODO:
// backend CPU works fine on Xiaomi14
// problem occurs when switching back and forth between cpu backend and gpu backend
// dsp backend not work
qnn_sample_main(argc, argv); //works on Xiaomi 14 on 03-30-2024,18:09 at the first time
}
break;
Expand Down Expand Up @@ -1428,6 +1429,7 @@ int whisper_asr_init(const char * sz_model_path, int n_threads, int n_asrmode) {
if (NULL == p_asr_ctx) {
p_asr_ctx = (whisper_asr_context *) malloc(sizeof(whisper_asr_context));
if (NULL == p_asr_ctx) {
LOGGW("initialize failure\n");
return 3;
}
}
Expand All @@ -1437,24 +1439,28 @@ int whisper_asr_init(const char * sz_model_path, int n_threads, int n_asrmode) {
result = pthread_mutex_init(&p_asr_ctx->mutex, NULL);
if (result != 0) {
result = 4;
LOGGW("initialize failure\n");
goto failure;
}

p_asr_ctx->asr_fifo = fifo_new("asr_fifo", 1200, 1024 * 8 * 20);
if (NULL == p_asr_ctx->asr_fifo) {
result = 5;
LOGGW("initialize failure\n");
goto failure;
}

p_asr_ctx->p_asr = new (std::nothrow)whisper_asr(); // attention memory leak
if (NULL == p_asr_ctx->p_asr) {
result = 6;
LOGGW("initialize failure\n");
goto failure;
}

p_asr_ctx->swr_ctx = swr_alloc(); // attention memory leak
if (NULL == p_asr_ctx->swr_ctx) {
result = 7;
LOGGW("initialize failure\n");
goto failure;
}

Expand All @@ -1465,13 +1471,15 @@ int whisper_asr_init(const char * sz_model_path, int n_threads, int n_asrmode) {
p_asr_ctx->p_context = whisper_init_from_file(sz_model_path);
if (nullptr == p_asr_ctx->p_context) {
result = 8;
LOGGW("initialize failure\n");
goto failure;
}
LOGGD("after calling whisper_init_from_file");

p_asr_ctx->p_params = (struct whisper_full_params *)malloc(sizeof(struct whisper_full_params));
if (NULL == p_asr_ctx->p_params) {
result = 9;
LOGGW("initialize failure\n");
goto failure;
}

Expand Down

0 comments on commit eb02b54

Please sign in to comment.