Skip to content

Commit

Permalink
Bump whispercpp, fix mac build (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
royshil authored Nov 15, 2023
1 parent ba8bd4d commit 1d80602
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 8 deletions.
21 changes: 15 additions & 6 deletions cmake/BuildWhispercpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,24 @@ include(ExternalProject)

set(CMAKE_OSX_ARCHITECTURES_ "arm64$<SEMICOLON>x86_64")

set(Whispercpp_Build_GIT_TAG "ccc85b4ff8d250d0f25ebcac2be0e4a23401c885")

if(${CMAKE_BUILD_TYPE} STREQUAL Release OR ${CMAKE_BUILD_TYPE} STREQUAL RelWithDebInfo)
set(Whispercpp_BUILD_TYPE Release)
else()
set(Whispercpp_BUILD_TYPE Debug)
endif()

# On linux add the `-fPIC` flag to the compiler
if(UNIX AND NOT APPLE)
# On linux add the `-fPIC` flag to the compiler
set(WHISPER_EXTRA_CXX_FLAGS "-fPIC")
set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_BLAS=OFF -DWHISPER_CUBLAS=OFF -DWHISPER_OPENBLAS=OFF -DWHISPER_NO_AVX=ON
-DWHISPER_NO_AVX2=ON)
endif()
if(APPLE)
# disable Metal on MacOS as it hurts performance right now
set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_METAL=OFF)
endif()

if(WIN32)
if(LOCALVOCAL_WITH_CUDA)
Expand Down Expand Up @@ -47,15 +53,17 @@ if(WIN32)
Whispercpp_Build
DOWNLOAD_EXTRACT_TIMESTAMP true
GIT_REPOSITORY https://github.com/ggerganov/whisper.cpp.git
GIT_TAG f96e1c5b7865e01fece99f69286d922d949a260d
GIT_TAG ${Whispercpp_Build_GIT_TAG}
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config ${Whispercpp_BUILD_TYPE}
BUILD_BYPRODUCTS
<INSTALL_DIR>/lib/static/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX}
<INSTALL_DIR>/bin/${CMAKE_SHARED_LIBRARY_PREFIX}whisper${CMAKE_SHARED_LIBRARY_SUFFIX}
<INSTALL_DIR>/lib/${CMAKE_IMPORT_LIBRARY_PREFIX}whisper${CMAKE_IMPORT_LIBRARY_SUFFIX}
CMAKE_GENERATOR ${CMAKE_GENERATOR}
INSTALL_COMMAND ${CMAKE_COMMAND} --install <BINARY_DIR> --config ${Whispercpp_BUILD_TYPE} && ${CMAKE_COMMAND} -E
copy <BINARY_DIR>/${Whispercpp_BUILD_TYPE}/whisper.lib <INSTALL_DIR>/lib
INSTALL_COMMAND
${CMAKE_COMMAND} --install <BINARY_DIR> --config ${Whispercpp_BUILD_TYPE} && ${CMAKE_COMMAND} -E copy
<BINARY_DIR>/${Whispercpp_BUILD_TYPE}/whisper.lib <INSTALL_DIR>/lib && ${CMAKE_COMMAND} -E copy
<SOURCE_DIR>/ggml.h <INSTALL_DIR>/include
CONFIGURE_COMMAND
${CMAKE_COMMAND} -E env ${WHISPER_ADDITIONAL_ENV} ${CMAKE_COMMAND} <SOURCE_DIR> -B <BINARY_DIR> -G
${CMAKE_GENERATOR} -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_BUILD_TYPE=${Whispercpp_BUILD_TYPE}
Expand All @@ -73,11 +81,12 @@ else()
Whispercpp_Build
DOWNLOAD_EXTRACT_TIMESTAMP true
GIT_REPOSITORY https://github.com/ggerganov/whisper.cpp.git
GIT_TAG f96e1c5b7865e01fece99f69286d922d949a260d
GIT_TAG ${Whispercpp_Build_GIT_TAG}
BUILD_COMMAND ${CMAKE_COMMAND} --build <BINARY_DIR> --config ${Whispercpp_BUILD_TYPE}
BUILD_BYPRODUCTS <INSTALL_DIR>/lib/static/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX}
CMAKE_GENERATOR ${CMAKE_GENERATOR}
INSTALL_COMMAND ${CMAKE_COMMAND} --install <BINARY_DIR> --config ${Whispercpp_BUILD_TYPE}
INSTALL_COMMAND ${CMAKE_COMMAND} --install <BINARY_DIR> --config ${Whispercpp_BUILD_TYPE} && ${CMAKE_COMMAND} -E
copy <SOURCE_DIR>/ggml.h <INSTALL_DIR>/include
CONFIGURE_COMMAND
${CMAKE_COMMAND} -E env ${WHISPER_ADDITIONAL_ENV} ${CMAKE_COMMAND} <SOURCE_DIR> -B <BINARY_DIR> -G
${CMAKE_GENERATOR} -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_BUILD_TYPE=${Whispercpp_BUILD_TYPE}
Expand Down
12 changes: 10 additions & 2 deletions src/whisper-processing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ struct whisper_context *init_whisper_context(const std::string &model_path)
{
obs_log(LOG_INFO, "Loading whisper model from %s", model_path.c_str());

struct whisper_context_params cparams;

#ifdef _WIN32
// convert model path UTF8 to wstring (wchar_t) for whisper
int count = MultiByteToWideChar(CP_UTF8, 0, model_path.c_str(), (int)model_path.length(),
Expand All @@ -133,9 +135,11 @@ struct whisper_context *init_whisper_context(const std::string &model_path)
modelFile.close();

// Initialize whisper
struct whisper_context *ctx = whisper_init_from_buffer(modelBuffer.data(), modelFileSize);
struct whisper_context *ctx =
whisper_init_from_buffer_with_params(modelBuffer.data(), modelFileSize, cparams);
#else
struct whisper_context *ctx = whisper_init_from_file(model_path.c_str());
struct whisper_context *ctx =
whisper_init_from_file_with_params(model_path.c_str(), cparams);
#endif

if (ctx == nullptr) {
Expand Down Expand Up @@ -372,6 +376,10 @@ void whisper_loop(void *data)
// Thread main loop
while (true) {
{
if (gf->whisper_ctx_mutex == nullptr) {
obs_log(LOG_WARNING, "whisper_ctx_mutex is null, exiting thread");
break;
}
std::lock_guard<std::mutex> lock(*gf->whisper_ctx_mutex);
if (gf->whisper_context == nullptr) {
obs_log(LOG_WARNING, "Whisper context is null, exiting thread");
Expand Down

0 comments on commit 1d80602

Please sign in to comment.