whisper.cpp/examples/whisper.android
Neuman Vong 19f8048139
whisper.android : how to build with CLBlast (#1809)
* FetchContent

* OpenCL

* Documentation and make optional

* Specify GGML build options in build.gradle

* Use gradle properties

* @ggerganov

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>

* @gpokat

---------

Co-authored-by: Georgi Gerganov <ggerganov@gmail.com>
2024-02-09 17:39:05 +02:00
..
.idea examples : add whisper.android.java for compatibility with older Android versions using Java (#1382) 2023-11-12 18:31:58 +02:00
app android : decouple example into a library and app module (#1445) 2023-11-07 14:27:33 +02:00
gradle/wrapper whisper.android : bump gradle plugin and dependencies + a lint pass (#1255) 2023-09-07 12:15:59 +03:00
lib whisper.android : how to build with CLBlast (#1809) 2024-02-09 17:39:05 +02:00
.gitignore Add Android sample (#277) 2022-12-16 19:20:13 +02:00
build.gradle whisper.android : bump gradle plugin and dependencies + a lint pass (#1255) 2023-09-07 12:15:59 +03:00
gradle.properties Add Android sample (#277) 2022-12-16 19:20:13 +02:00
gradlew Add Android sample (#277) 2022-12-16 19:20:13 +02:00
gradlew.bat Add Android sample (#277) 2022-12-16 19:20:13 +02:00
README.md whisper.android : how to build with CLBlast (#1809) 2024-02-09 17:39:05 +02:00
settings.gradle android : decouple example into a library and app module (#1445) 2023-11-07 14:27:33 +02:00

A sample Android app using whisper.cpp to do voice-to-text transcriptions.

To use:

  1. Select a model from the whisper.cpp repository.1
  2. Copy the model to the "app/src/main/assets/models" folder.
  3. Select a sample audio file (for example, jfk.wav).
  4. Copy the sample to the "app/src/main/assets/samples" folder.
  5. Select the "release" active build variant, and use Android Studio to run and deploy to your device.

(PS: Do not move this android project folder individually to other folders, because this android project folder depends on the files of the whole project.)

image

CLBlast

Note

  • OpenCL does not have the same level of support as CUDA or Metal.
  • Turning on CLBlast may degrade OpenCL performance if your device isn't already tuned. See tuning.md for a list of devices that are already tuned and what to do if yours is missing.

Build CLBlast.

# In path/to/CLBlast (we assume OpenCL-Headers relative location)
$ANDROID_SDK_PATH/cmake/3.22.1/bin/cmake .. \
    -DCMAKE_SYSTEM_NAME=Android \
    -DCMAKE_SYSTEM_VERSION=33 \
    -DCMAKE_ANDROID_ARCH_ABI=arm64-v8a \
    -DCMAKE_ANDROID_NDK=$ANDROID_NDK_PATH \
    -DCMAKE_ANDROID_STL_TYPE=c++_static \
    -DOPENCL_ROOT=$(readlink -f ../../OpenCL-Headers) \
    -DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=BOTH \
    -DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=BOTH

# Build libclblast.so
make -j4

Pull libGLES_mali.so to libOpenCL.so.

# In path/to/whisper.android
mkdir lib/src/main/jniLibs/arm64-v8a
adb pull /system/vendor/lib64/egl/libGLES_mali.so lib/src/main/jniLibs/arm64-v8a/libOpenCL.so

In gradle.properties, set GGML_HOME to the location of GGML, as well as required options for turning on CLBlast.

GGML_HOME=/path/to/ggml
GGML_CLBLAST=ON
CLBLAST_HOME=/path/to/CLBlast
OPENCL_LIB=/path/to/libOpenCL.so
OPENCL_ROOT=/path/to/OpenCL-Headers

  1. I recommend the tiny or base models for running on an Android device. ↩︎