Skip to content

Commit

Permalink
upgrade whisper.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
GiviMAD committed May 19, 2024
1 parent 7868f35 commit 70fb24d
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 27 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ install(
DESTINATION ${CMAKE_INSTALL_PREFIX}
USE_SOURCE_PERMISSIONS
FILES_MATCHING
PATTERN "*.so"
PATTERN "*.so.*"
PATTERN "*.dylib"
)

Expand Down
8 changes: 2 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ A JNI wrapper for [whisper.cpp](https://github.com/ggerganov/whisper.cpp), allow

This library aims to support the following platforms:

* Windows10 x86_64
* Windows10 x86_64 (included binary requires CPU features avx2, fma, f16c, avx)
* Linux GLIBC x86_64/arm64 (built with debian focal, GLIBC version 2.31)
* macOS x86_64/arm64 (built targeting v11.0)

The native binaries for those platforms are included in the distributed jar.

The library has been tested on all the supported platforms unless macOS arm64.

The included binaries have been built with some features enabled that I think are available in most modern devices,
please open an issue if you found it don't work on any of the supported platforms.
Please open an issue if you found it don't work on any of the supported platforms.

## Installation

Expand Down
4 changes: 2 additions & 2 deletions build_debian.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ build_lib() {
cmake -B build $CMAKE_ARGS -DCMAKE_C_FLAGS="$CMAKE_CFLAGS" -DCMAKE_INSTALL_PREFIX=$TMP_DIR
cmake --build build --config Release
cmake --install build
mv $TMP_DIR/libwhisper.so $TARGET_DIR/libwhisper$LIB_VARIANT.so
cp $TMP_DIR/libwhisper.so.1 $TARGET_DIR/libwhisper$LIB_VARIANT.so.1
if [ "$ADD_WRAPPER" = true ]; then
mv $TMP_DIR/libwhisper-jni.so $TARGET_DIR/libwhisper-jni.so
cp $TMP_DIR/libwhisper-jni.so $TARGET_DIR/libwhisper-jni.so
fi
rm -rf $TMP_DIR
rm -rf build
Expand Down
11 changes: 8 additions & 3 deletions build_macos.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ esac

INCLUDE_JAVA="-I $JAVA_HOME/include -I $JAVA_HOME/include/darwin"
TARGET=$AARCH-apple-macosx$TARGET_VERSION

cmake -Bbuild -DCMAKE_INSTALL_PREFIX=src/main/resources/macos-$AARCH_NAME -DCMAKE_OSX_DEPLOYMENT_TARGET=$TARGET_VERSION -DCMAKE_OSX_ARCHITECTURES=$AARCH
TARGET_DIR=src/main/resources/macos-$AARCH_NAME
TMP_DIR=src/main/resources/tmp-macos-$AARCH_NAME
mkdir -p $TMP_DIR
cmake -Bbuild -DCMAKE_INSTALL_PREFIX=$TMP_DIR -DCMAKE_OSX_DEPLOYMENT_TARGET=$TARGET_VERSION -DCMAKE_OSX_ARCHITECTURES=$AARCH
cmake --build build --config Release
cmake --install build
rm -rf build
rm -rf build
cp $TMP_DIR/libwhisper.1.dylib $TARGET_DIR
cp $TMP_DIR/libwhisper-jni.dylib $TARGET_DIR
rm -rf $TMP_DIR
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<artifactId>whisper-jni</artifactId>
<name>whisper-jni</name>
<url>https://github.com/GiviMAD/whisper-jni</url>
<version>1.5.4-0</version>
<version>1.6.0</version>
<description>A JNI wrapper for [whisper.cpp](https://github.com/ggerganov/whisper.cpp), allows to transcribe speech to text in Java</description>

<licenses>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,12 +141,12 @@ public static void loadLibrary(WhisperJNI.LoadOptions options) throws IOExceptio
options.logger.log("Compatible amd64 architecture detected.");
if(options.whisperLib == null) {
if(cpuInfo.contains("avx2") && cpuInfo.contains("fma") && cpuInfo.contains("f16c") && cpuInfo.contains("avx")) {
LibraryUtils.extractLibraryFromJar("/debian-amd64/libwhisper+mf16c+mfma+mavx+mavx2.so", "libwhisper.so", options.logger);
LibraryUtils.extractLibraryFromJar("/debian-amd64/libwhisper+mf16c+mfma+mavx+mavx2.so.1", "libwhisper.so.1", options.logger);
} else {
LibraryUtils.extractLibraryFromJar("/debian-amd64/libwhisper.so", "libwhisper.so", options.logger);
LibraryUtils.extractLibraryFromJar("/debian-amd64/libwhisper.so.1", "libwhisper.so.1", options.logger);
}
} else {
LibraryUtils.copyFromSystem(options.whisperLib, "libwhisper.so", options.logger);
LibraryUtils.copyFromSystem(options.whisperLib, "libwhisper.so.1", options.logger);
}
if(options.whisperJNILib == null){
LibraryUtils.extractLibraryFromJar("/debian-amd64/libwhisper-jni.so", "libwhisper-jni.so", options.logger);
Expand All @@ -157,12 +157,12 @@ public static void loadLibrary(WhisperJNI.LoadOptions options) throws IOExceptio
options.logger.log("Compatible arm64 architecture detected.");
if(options.whisperLib == null){
if(cpuInfo.contains("fphp")) {
LibraryUtils.extractLibraryFromJar("/debian-arm64/libwhisper+fp16.so", "libwhisper.so", options.logger);
LibraryUtils.extractLibraryFromJar("/debian-arm64/libwhisper+fp16.so.1", "libwhisper.so.1", options.logger);
} else if(cpuInfo.contains("crc32")) {
LibraryUtils.extractLibraryFromJar( "/debian-arm64/libwhisper+crc.so", "libwhisper.so", options.logger);
LibraryUtils.extractLibraryFromJar( "/debian-arm64/libwhisper+crc.so.1", "libwhisper.so.1", options.logger);
}
} else {
LibraryUtils.copyFromSystem(options.whisperLib, "libwhisper.so", options.logger);
LibraryUtils.copyFromSystem(options.whisperLib, "libwhisper.so.1", options.logger);
}
if(options.whisperJNILib == null){
LibraryUtils.extractLibraryFromJar("/debian-arm64/libwhisper-jni.so", "libwhisper-jni.so", options.logger);
Expand All @@ -173,12 +173,12 @@ public static void loadLibrary(WhisperJNI.LoadOptions options) throws IOExceptio
options.logger.log("Compatible arm architecture detected.");
if(options.whisperLib == null){
if(cpuInfo.contains("crc32")) {
LibraryUtils.extractLibraryFromJar("/debian-armv7l/libwhisper+crc.so", "libwhisper.so", options.logger);
LibraryUtils.extractLibraryFromJar("/debian-armv7l/libwhisper+crc.so.1", "libwhisper.so.1", options.logger);
} else {
LibraryUtils.extractLibraryFromJar("/debian-armv7l/libwhisper.so", "libwhisper.so", options.logger);
LibraryUtils.extractLibraryFromJar("/debian-armv7l/libwhisper.so.1", "libwhisper.so.1", options.logger);
}
} else {
LibraryUtils.copyFromSystem(options.whisperLib, "libwhisper.so", options.logger);
LibraryUtils.copyFromSystem(options.whisperLib, "libwhisper.so.1", options.logger);
}
if(options.whisperJNILib == null){
LibraryUtils.extractLibraryFromJar("/debian-armv7l/libwhisper-jni.so", "libwhisper-jni.so", options.logger);
Expand All @@ -194,9 +194,9 @@ public static void loadLibrary(WhisperJNI.LoadOptions options) throws IOExceptio
if(osArch.contains("amd64") || osArch.contains("x86_64")) {
options.logger.log("Compatible amd64 architecture detected.");
if(options.whisperLib == null){
LibraryUtils.extractLibraryFromJar( "/macos-amd64/libwhisper.dylib", "libwhisper.dylib", options.logger);
LibraryUtils.extractLibraryFromJar( "/macos-amd64/libwhisper.1.dylib", "libwhisper.1.dylib", options.logger);
} else {
LibraryUtils.copyFromSystem(options.whisperLib, "libwhisper.dylib", options.logger);
LibraryUtils.copyFromSystem(options.whisperLib, "libwhisper.1.dylib", options.logger);
}
if(options.whisperJNILib == null){
LibraryUtils.extractLibraryFromJar("/macos-amd64/libwhisper-jni.dylib", "libwhisper-jni.dylib", options.logger);
Expand All @@ -206,9 +206,9 @@ public static void loadLibrary(WhisperJNI.LoadOptions options) throws IOExceptio
} else if(osArch.contains("aarch64") || osArch.contains("arm64")) {
options.logger.log("Compatible arm64 architecture detected.");
if(options.whisperLib == null){
LibraryUtils.extractLibraryFromJar( "/macos-arm64/libwhisper.dylib", "libwhisper.dylib", options.logger);
LibraryUtils.extractLibraryFromJar( "/macos-arm64/libwhisper.1.dylib", "libwhisper.1.dylib", options.logger);
} else {
LibraryUtils.copyFromSystem(options.whisperLib, "libwhisper.dylib", options.logger);
LibraryUtils.copyFromSystem(options.whisperLib, "libwhisper.1.dylib", options.logger);
}
if(options.whisperJNILib == null){
LibraryUtils.extractLibraryFromJar("/macos-arm64/libwhisper-jni.dylib", "libwhisper-jni.dylib", options.logger);
Expand Down
2 changes: 1 addition & 1 deletion src/main/native/whisper
Submodule whisper updated 196 files

0 comments on commit 70fb24d

Please sign in to comment.