Spaces:
Running
Running
whisper : add version function (#3289)
Browse files* 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
CMakeLists.txt
CHANGED
|
@@ -178,6 +178,10 @@ get_directory_property(WHISPER_TRANSIENT_DEFINES COMPILE_DEFINITIONS)
|
|
| 178 |
set_target_properties(whisper PROPERTIES PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/include/whisper.h)
|
| 179 |
install(TARGETS whisper LIBRARY PUBLIC_HEADER)
|
| 180 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
configure_package_config_file(
|
| 182 |
${CMAKE_CURRENT_SOURCE_DIR}/cmake/whisper-config.cmake.in
|
| 183 |
${CMAKE_CURRENT_BINARY_DIR}/whisper-config.cmake
|
|
|
|
| 178 |
set_target_properties(whisper PROPERTIES PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/include/whisper.h)
|
| 179 |
install(TARGETS whisper LIBRARY PUBLIC_HEADER)
|
| 180 |
|
| 181 |
+
target_compile_definitions(whisper PRIVATE
|
| 182 |
+
WHISPER_VERSION="${PROJECT_VERSION}"
|
| 183 |
+
)
|
| 184 |
+
|
| 185 |
configure_package_config_file(
|
| 186 |
${CMAKE_CURRENT_SOURCE_DIR}/cmake/whisper-config.cmake.in
|
| 187 |
${CMAKE_CURRENT_BINARY_DIR}/whisper-config.cmake
|
examples/whisper.android.java/app/src/main/jni/whisper/CMakeLists.txt
CHANGED
|
@@ -5,6 +5,17 @@ project(whisper.cpp)
|
|
| 5 |
set(CMAKE_CXX_STANDARD 17)
|
| 6 |
set(WHISPER_LIB_DIR ${CMAKE_SOURCE_DIR}/../../../../../../../)
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
set(SOURCE_FILES
|
| 9 |
${WHISPER_LIB_DIR}/src/whisper.cpp
|
| 10 |
${CMAKE_SOURCE_DIR}/jni.c
|
|
@@ -26,6 +37,7 @@ function(build_library target_name)
|
|
| 26 |
|
| 27 |
target_link_libraries(${target_name} ${LOG_LIB} android ggml)
|
| 28 |
target_compile_definitions(${target_name} PUBLIC GGML_USE_CPU)
|
|
|
|
| 29 |
|
| 30 |
if (${target_name} STREQUAL "whisper_v8fp16_va")
|
| 31 |
target_compile_options(${target_name} PRIVATE -march=armv8.2-a+fp16)
|
|
|
|
| 5 |
set(CMAKE_CXX_STANDARD 17)
|
| 6 |
set(WHISPER_LIB_DIR ${CMAKE_SOURCE_DIR}/../../../../../../../)
|
| 7 |
|
| 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 |
+
|
| 19 |
set(SOURCE_FILES
|
| 20 |
${WHISPER_LIB_DIR}/src/whisper.cpp
|
| 21 |
${CMAKE_SOURCE_DIR}/jni.c
|
|
|
|
| 37 |
|
| 38 |
target_link_libraries(${target_name} ${LOG_LIB} android ggml)
|
| 39 |
target_compile_definitions(${target_name} PUBLIC GGML_USE_CPU)
|
| 40 |
+
target_compile_definitions(${target_name} PRIVATE WHISPER_VERSION="${WHISPER_VERSION}")
|
| 41 |
|
| 42 |
if (${target_name} STREQUAL "whisper_v8fp16_va")
|
| 43 |
target_compile_options(${target_name} PRIVATE -march=armv8.2-a+fp16)
|
examples/whisper.android/lib/src/main/jni/whisper/CMakeLists.txt
CHANGED
|
@@ -5,6 +5,17 @@ project(whisper.cpp)
|
|
| 5 |
set(CMAKE_CXX_STANDARD 17)
|
| 6 |
set(WHISPER_LIB_DIR ${CMAKE_SOURCE_DIR}/../../../../../../..)
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
# Path to external GGML, otherwise uses the copy in whisper.cpp.
|
| 9 |
option(GGML_HOME "whisper: Path to external GGML source" OFF)
|
| 10 |
|
|
@@ -26,6 +37,7 @@ function(build_library target_name)
|
|
| 26 |
)
|
| 27 |
|
| 28 |
target_compile_definitions(${target_name} PUBLIC GGML_USE_CPU)
|
|
|
|
| 29 |
|
| 30 |
if (${target_name} STREQUAL "whisper_v8fp16_va")
|
| 31 |
target_compile_options(${target_name} PRIVATE -march=armv8.2-a+fp16)
|
|
|
|
| 5 |
set(CMAKE_CXX_STANDARD 17)
|
| 6 |
set(WHISPER_LIB_DIR ${CMAKE_SOURCE_DIR}/../../../../../../..)
|
| 7 |
|
| 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 |
+
|
| 19 |
# Path to external GGML, otherwise uses the copy in whisper.cpp.
|
| 20 |
option(GGML_HOME "whisper: Path to external GGML source" OFF)
|
| 21 |
|
|
|
|
| 37 |
)
|
| 38 |
|
| 39 |
target_compile_definitions(${target_name} PUBLIC GGML_USE_CPU)
|
| 40 |
+
target_compile_definitions(${target_name} PRIVATE WHISPER_VERSION="${WHISPER_VERSION}")
|
| 41 |
|
| 42 |
if (${target_name} STREQUAL "whisper_v8fp16_va")
|
| 43 |
target_compile_options(${target_name} PRIVATE -march=armv8.2-a+fp16)
|
include/whisper.h
CHANGED
|
@@ -198,6 +198,8 @@ extern "C" {
|
|
| 198 |
float samples_overlap; // Overlap in seconds when copying audio samples from speech segment.
|
| 199 |
} whisper_vad_params;
|
| 200 |
|
|
|
|
|
|
|
| 201 |
// Various functions for loading a ggml whisper model.
|
| 202 |
// Allocate (almost) all memory needed for the model.
|
| 203 |
// Return NULL on failure
|
|
|
|
| 198 |
float samples_overlap; // Overlap in seconds when copying audio samples from speech segment.
|
| 199 |
} whisper_vad_params;
|
| 200 |
|
| 201 |
+
WHISPER_API const char * whisper_version(void);
|
| 202 |
+
|
| 203 |
// Various functions for loading a ggml whisper model.
|
| 204 |
// Allocate (almost) all memory needed for the model.
|
| 205 |
// Return NULL on failure
|
src/whisper.cpp
CHANGED
|
@@ -8938,6 +8938,10 @@ void whisper_log_set(ggml_log_callback log_callback, void * user_data) {
|
|
| 8938 |
ggml_log_set(g_state.log_callback, g_state.log_callback_user_data);
|
| 8939 |
}
|
| 8940 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8941 |
GGML_ATTRIBUTE_FORMAT(2, 3)
|
| 8942 |
static void whisper_log_internal(ggml_log_level level, const char * format, ...) {
|
| 8943 |
va_list args;
|
|
|
|
| 8938 |
ggml_log_set(g_state.log_callback, g_state.log_callback_user_data);
|
| 8939 |
}
|
| 8940 |
|
| 8941 |
+
const char * whisper_version(void) {
|
| 8942 |
+
return WHISPER_VERSION;
|
| 8943 |
+
}
|
| 8944 |
+
|
| 8945 |
GGML_ATTRIBUTE_FORMAT(2, 3)
|
| 8946 |
static void whisper_log_internal(ggml_log_level level, const char * format, ...) {
|
| 8947 |
va_list args;
|