Skip to content

Commit

Permalink
integrate ggml's excellent and amazing whisper.cpp to kantv ---- step5
Browse files Browse the repository at this point in the history
refine whispercpp's JNI code and native code

finish whispercpp inference benchmark

refine the ASRFragment.java(more make sense with UI status)

I successfully integrated FFmpeg into whisper.cpp for the first time
  • Loading branch information
zhouwg committed Mar 8, 2024
1 parent 2d7febb commit 93397b7
Show file tree
Hide file tree
Showing 178 changed files with 36,702 additions and 655 deletions.
1 change: 1 addition & 0 deletions build/public.sh
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ function dump_global_envs()
if [ "${BUILD_TARGET}" = "android" ]; then
echo -e "\n"
echo -e "ANDROID_NDK: ${ANDROID_NDK}"
echo -e "LOCAL_WHISPERCPP_PATH: ${LOCAL_WHISPERCPP_PATH}"
echo -e "UPSTREAM_WHISPERCPP_PATH: ${UPSTREAM_WHISPERCPP_PATH}"
echo -e "\n"
fi
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -812,7 +812,7 @@ public static String getDataPath() {
CDELog.j(TAG, "sdcard free size:" + mKANTVDRM.ANDROID_JNI_GetDiskFreeSize(sdcardPath.getAbsolutePath()));
String dataDirectoryPath = null;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
dataDirectoryPath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "kantv";
dataDirectoryPath = Environment.getExternalStorageDirectory().getAbsolutePath() + File.separator + "kantv" + File.separator;
} else {
dataDirectoryPath = Environment.getExternalStorageDirectory().getAbsolutePath() +
File.separator + "Android" + File.separator + "data" + File.separator + "com.cdeos.kantv" + File.separator + "files" + File.separator + "kantv";
Expand Down Expand Up @@ -2217,7 +2217,7 @@ public static String formatedDurationMilli(long duration) {
}
}

public static String formatedSize(long bytes) {
public static String formattedSize(long bytes) {

if (bytes <= 0) {
return "0 Bytes";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class KANTVBenchmarkType
public static final int BENCHMARK_SVT_AV1 = 4;


//borrow from FFmpeg
public static final int AV_PIX_FMT_YUV420P = 0; ///< planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
public static final int AV_PIX_FMT_YUYV422 = 1; ///< packed YUV 4:2:2, 16bpp, Y0 Cb Y1 Cr
public static final int AV_PIX_FMT_RGB24 = 2; ///< packed RGB 8:8:8, 24bpp, RGBRGB...
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@ final public class KANTVEvent {
public final static int KANTV_INFO_STATUS = 14;

public final static int KANTV_INFO_ASR_INIT = 15;
public final static int KANTV_INFO_ASR_FINALiZE = 16;
public final static int KANTV_INFO_ASR_FINALIZE = 16;

public final static int KANTV_INFO_ASR_START = 17;
public final static int KANTV_INFO_ASR_STOP = 18;
public final static int KANTV_INFO_GGML_INTERNAL = 19;
public final static int KANTV_INFO_WHISPERCPP_INTERNAL = 20;
public final static int KANTV_INFO_ASR_GGML_INTERNAL = 19;
public final static int KANTV_INFO_ASR_WHISPERCPP_INTERNAL = 20;
public final static int KANTV_INFO_ASR_RESULT = 21;

public final static int KANTV_ERROR_PREVIEW_START = 0;
public final static int KANTV_ERROR_PREVIEW_STOP = 1;
Expand All @@ -60,8 +61,9 @@ final public class KANTVEvent {
public final static int KANTV_ERROR_ASR_FINALiZE = 12;
public final static int KANTV_ERROR_ASR_START = 13;
public final static int KANTV_ERROR_ASR_STOP = 14;
public final static int KANTV_ERROR_GGML_INTERNAL = 15;
public final static int KANTV_ERROR_WHISPERCPP_INTERNAL = 16;
public final static int KANTV_ERROR_ASR_GGML_INTERNAL = 15;
public final static int KANTV_ERROR_ASR_WHISPERCPP_INTERNAL = 16;
public final static int KANTV_ERROR_ASR_RESULT = 17;

public static native int kantv_anti_tamper();
}
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public void handleMessage(Message msg)
}
catch (Exception e)
{
CDELog.j(TAG, "exception occured in event handler");
CDELog.j(TAG, "exception occurred in event handler");
}
}
}
Expand Down Expand Up @@ -235,6 +235,7 @@ public void close()
catch (Exception e)
{
e.printStackTrace();
CDELog.j(TAG, "failed to initialize KANTVMgr: " + e.toString());
}
}

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
//TODO: re-write entire whispercpp.java with standard Android JNI specification
// interaction between KANTVMgr.java and whispercpp.java

package org.ggml.whispercpp;

public class whispercpp {
private static final String TAG = whispercpp.class.getName();

public static native String getSystemInfo();

public static native String benchMemcpy(int nThreadCounts);

public static native String benchMulMat(int nThreadCounts);

public static native void set_mulmat_benchmark_status(int bExitBenchmark);

public static native String transcribe_from_file(String modelPath, String audioFile, int nThreadCounts);
}
Loading

5 comments on commit 93397b7

@zhouwg
Copy link
Owner Author

@zhouwg zhouwg commented on 93397b7 Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forget to send KANTV_INFO_ASR_RESULT from native layer(in whisper.cpp) so playback of jfk.wav will be launched when ASR result is displayed in UI

https://github.com/cdeos/kantv/blob/kantv-poc-with-whispercpp/external/whispercpp/whisper.cpp#L6961

if (eventType.getValue() == KANTVEvent.KANTV_INFO_ASR_RESULT) {
       
     playAudioFile();
}

@zhouwg
Copy link
Owner Author

@zhouwg zhouwg commented on 93397b7 Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhouwg
Copy link
Owner Author

@zhouwg zhouwg commented on 93397b7 Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zhouwg
Copy link
Owner Author

@zhouwg zhouwg commented on 93397b7 Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this line should be removed because I replace the original method(what I did this morning) which caller should be responsible for release memory and take care of potential memory leak.

https://github.com/cdeos/kantv/blob/kantv-poc-with-whispercpp/external/whispercpp/whisper.cpp#L6878

@zhouwg
Copy link
Owner Author

@zhouwg zhouwg commented on 93397b7 Mar 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add code to handle corner case: whispercpp 's inference failure

https://github.com/cdeos/kantv/blob/kantv-poc-with-whispercpp/external/whispercpp/whisper.cpp#L6981

Please sign in to comment.