Skip to content

Commit 32cf4e2

Browse files
authored
whisper : add version function (ggml-org#3289)
* whisper : add version function This commit adds a version function to the whisper API. The motivation for this is that it might be convenient to have a way to programmatically check the version. Example usage: ```c++ printf("Using whisper version: %s\n", whisper_version()); ``` Will output: ```console Using whisper version: 1.7.6 ``` * examples : add version to android example CMakeLists.txt
1 parent 35034c5 commit 32cf4e2

File tree

5 files changed

+34
-0
lines changed

5 files changed

+34
-0
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,10 @@ get_directory_property(WHISPER_TRANSIENT_DEFINES COMPILE_DEFINITIONS)
178178
set_target_properties(whisper PROPERTIES PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/include/whisper.h)
179179
install(TARGETS whisper LIBRARY PUBLIC_HEADER)
180180

181+
target_compile_definitions(whisper PRIVATE
182+
WHISPER_VERSION="${PROJECT_VERSION}"
183+
)
184+
181185
configure_package_config_file(
182186
${CMAKE_CURRENT_SOURCE_DIR}/cmake/whisper-config.cmake.in
183187
${CMAKE_CURRENT_BINARY_DIR}/whisper-config.cmake

examples/whisper.android.java/app/src/main/jni/whisper/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ project(whisper.cpp)
55
set(CMAKE_CXX_STANDARD 17)
66
set(WHISPER_LIB_DIR ${CMAKE_SOURCE_DIR}/../../../../../../../)
77

8+
# Get whisper.cpp version
9+
file(READ "${WHISPER_LIB_DIR}/CMakeLists.txt" MAIN_CMAKE_CONTENT)
10+
string(REGEX MATCH "project\\(\"whisper\\.cpp\" VERSION ([0-9]+\\.[0-9]+\\.[0-9]+)\\)" VERSION_MATCH "${MAIN_CMAKE_CONTENT}")
11+
if(CMAKE_MATCH_1)
12+
set(WHISPER_VERSION ${CMAKE_MATCH_1} PARENT_SCOPE)
13+
else()
14+
set(WHISPER_VERSION "unknown" PARENT_SCOPE)
15+
endif()
16+
17+
message(STATUS " Whisper version: ${WHISPER_VERSION}")
18+
819
set(SOURCE_FILES
920
${WHISPER_LIB_DIR}/src/whisper.cpp
1021
${CMAKE_SOURCE_DIR}/jni.c
@@ -26,6 +37,7 @@ function(build_library target_name)
2637

2738
target_link_libraries(${target_name} ${LOG_LIB} android ggml)
2839
target_compile_definitions(${target_name} PUBLIC GGML_USE_CPU)
40+
target_compile_definitions(${target_name} PRIVATE WHISPER_VERSION="${WHISPER_VERSION}")
2941

3042
if (${target_name} STREQUAL "whisper_v8fp16_va")
3143
target_compile_options(${target_name} PRIVATE -march=armv8.2-a+fp16)

examples/whisper.android/lib/src/main/jni/whisper/CMakeLists.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,17 @@ project(whisper.cpp)
55
set(CMAKE_CXX_STANDARD 17)
66
set(WHISPER_LIB_DIR ${CMAKE_SOURCE_DIR}/../../../../../../..)
77

8+
# Get whisper.cpp version
9+
file(READ "${WHISPER_LIB_DIR}/CMakeLists.txt" MAIN_CMAKE_CONTENT)
10+
string(REGEX MATCH "project\\(\"whisper\\.cpp\" VERSION ([0-9]+\\.[0-9]+\\.[0-9]+)\\)" VERSION_MATCH "${MAIN_CMAKE_CONTENT}")
11+
if(CMAKE_MATCH_1)
12+
set(WHISPER_VERSION ${CMAKE_MATCH_1} PARENT_SCOPE)
13+
else()
14+
set(WHISPER_VERSION "unknown" PARENT_SCOPE)
15+
endif()
16+
17+
message(STATUS " Whisper version: ${WHISPER_VERSION}")
18+
819
# Path to external GGML, otherwise uses the copy in whisper.cpp.
920
option(GGML_HOME "whisper: Path to external GGML source" OFF)
1021

@@ -26,6 +37,7 @@ function(build_library target_name)
2637
)
2738

2839
target_compile_definitions(${target_name} PUBLIC GGML_USE_CPU)
40+
target_compile_definitions(${target_name} PRIVATE WHISPER_VERSION="${WHISPER_VERSION}")
2941

3042
if (${target_name} STREQUAL "whisper_v8fp16_va")
3143
target_compile_options(${target_name} PRIVATE -march=armv8.2-a+fp16)

include/whisper.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ extern "C" {
198198
float samples_overlap; // Overlap in seconds when copying audio samples from speech segment.
199199
} whisper_vad_params;
200200

201+
WHISPER_API const char * whisper_version(void);
202+
201203
// Various functions for loading a ggml whisper model.
202204
// Allocate (almost) all memory needed for the model.
203205
// Return NULL on failure

src/whisper.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8938,6 +8938,10 @@ void whisper_log_set(ggml_log_callback log_callback, void * user_data) {
89388938
ggml_log_set(g_state.log_callback, g_state.log_callback_user_data);
89398939
}
89408940

8941+
const char * whisper_version(void) {
8942+
return WHISPER_VERSION;
8943+
}
8944+
89418945
GGML_ATTRIBUTE_FORMAT(2, 3)
89428946
static void whisper_log_internal(ggml_log_level level, const char * format, ...) {
89438947
va_list args;

0 commit comments

Comments
 (0)