Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ else()
endif()

option(WHISPER_PERF "whisper: enable perf timings" OFF)
option(WHISPER_LOGCAT "whisper: enable android logcat" OFF)

# sanitizers

Expand Down Expand Up @@ -408,6 +409,10 @@ if (WHISPER_PERF)
set(WHISPER_EXTRA_FLAGS ${WHISPER_EXTRA_FLAGS} -DGGML_PERF)
endif()

if (WHISPER_LOGCAT AND ANDROID)
set(WHISPER_EXTRA_FLAGS ${WHISPER_EXTRA_FLAGS} -DWHISPER_LOGCAT)
endif()

#
# whisper.coreml - Core ML support
#
Expand Down Expand Up @@ -497,6 +502,10 @@ else()
target_link_libraries(${TARGET} PRIVATE m ${WHISPER_EXTRA_LIBS} ${CMAKE_THREAD_LIBS_INIT})
endif()

if (WHISPER_LOGCAT)
target_link_libraries(${TARGET} PRIVATE android log)
endif ()

if (BUILD_SHARED_LIBS)
target_link_libraries(${TARGET} PUBLIC
${CMAKE_DL_LIBS}
Expand Down
11 changes: 11 additions & 0 deletions whisper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ static void byteswap_tensor(ggml_tensor * tensor) {
// logging
//

#ifdef WHISPER_LOGCAT
#include <android/log.h>
#endif
Comment on lines +121 to +123
Copy link
Collaborator

Choose a reason for hiding this comment

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

To be honest, I'm not convinced that including <android/log.h> in whisper.cpp is the best approach. It seems more practical to use a callback instead.

I'm also wondering why do we continue to use WHISPER_PRINT_DEBUG when we already have WHISPER_LOG? Couldn't we just create a function named WHISPER_LOG_DEBUG that offers both console output and callback functionality? @ggerganov

Copy link
Author

Choose a reason for hiding this comment

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

Well, I see the callback logic just now, I agree with you, it's the right way!

Copy link
Member

Choose a reason for hiding this comment

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

Yup, logcat is better to not be part of whisper.cpp - utilize the log callback

Regarding WHISPER_PRINT_DEBUG - it's used for debugging that I don't think will be really useful to the "outside world". But we could add WHISPER_LOG_DEBUG instead for consistency. Probably have to extend enum ggml_log_level with new GGML_LOG_LEVEL_DEBUG value

WHISPER_ATTRIBUTE_FORMAT(2, 3)
static void whisper_log_internal (ggml_log_level level, const char * format, ...);
static void whisper_log_callback_default(ggml_log_level level, const char * text, void * user_data);
Expand All @@ -140,7 +143,11 @@ static void whisper_log_callback_default(ggml_log_level level, const char * text
#if defined(WHISPER_DEBUG)
#define WHISPER_PRINT_DEBUG(...) \
do { \
#ifdef WHISPER_LOGCAT \
__android_log_print(ANDROID_LOG_DEBUG, "whisper", __VA_ARGS__); \
#else \
fprintf(stderr, __VA_ARGS__); \
#endif \
} while (0)
#else
#define WHISPER_PRINT_DEBUG(...)
Expand Down Expand Up @@ -6636,6 +6643,10 @@ static void whisper_log_internal(ggml_log_level level, const char * format, ...)
static void whisper_log_callback_default(ggml_log_level level, const char * text, void * user_data) {
(void) level;
(void) user_data;
#ifdef WHISPER_LOGCAT
__android_log_print(ANDROID_LOG_ERROR, "whisper", "%s", text);
#else
fputs(text, stderr);
fflush(stderr);
#endif
}