diff --git a/cmake/BuildWhispercpp.cmake b/cmake/BuildWhispercpp.cmake index afa405c..f1ccf37 100644 --- a/cmake/BuildWhispercpp.cmake +++ b/cmake/BuildWhispercpp.cmake @@ -2,18 +2,24 @@ include(ExternalProject) set(CMAKE_OSX_ARCHITECTURES_ "arm64$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) @@ -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 --config ${Whispercpp_BUILD_TYPE} BUILD_BYPRODUCTS /lib/static/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX} /bin/${CMAKE_SHARED_LIBRARY_PREFIX}whisper${CMAKE_SHARED_LIBRARY_SUFFIX} /lib/${CMAKE_IMPORT_LIBRARY_PREFIX}whisper${CMAKE_IMPORT_LIBRARY_SUFFIX} CMAKE_GENERATOR ${CMAKE_GENERATOR} - INSTALL_COMMAND ${CMAKE_COMMAND} --install --config ${Whispercpp_BUILD_TYPE} && ${CMAKE_COMMAND} -E - copy /${Whispercpp_BUILD_TYPE}/whisper.lib /lib + INSTALL_COMMAND + ${CMAKE_COMMAND} --install --config ${Whispercpp_BUILD_TYPE} && ${CMAKE_COMMAND} -E copy + /${Whispercpp_BUILD_TYPE}/whisper.lib /lib && ${CMAKE_COMMAND} -E copy + /ggml.h /include CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env ${WHISPER_ADDITIONAL_ENV} ${CMAKE_COMMAND} -B -G ${CMAKE_GENERATOR} -DCMAKE_INSTALL_PREFIX= -DCMAKE_BUILD_TYPE=${Whispercpp_BUILD_TYPE} @@ -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 --config ${Whispercpp_BUILD_TYPE} BUILD_BYPRODUCTS /lib/static/${CMAKE_STATIC_LIBRARY_PREFIX}whisper${CMAKE_STATIC_LIBRARY_SUFFIX} CMAKE_GENERATOR ${CMAKE_GENERATOR} - INSTALL_COMMAND ${CMAKE_COMMAND} --install --config ${Whispercpp_BUILD_TYPE} + INSTALL_COMMAND ${CMAKE_COMMAND} --install --config ${Whispercpp_BUILD_TYPE} && ${CMAKE_COMMAND} -E + copy /ggml.h /include CONFIGURE_COMMAND ${CMAKE_COMMAND} -E env ${WHISPER_ADDITIONAL_ENV} ${CMAKE_COMMAND} -B -G ${CMAKE_GENERATOR} -DCMAKE_INSTALL_PREFIX= -DCMAKE_BUILD_TYPE=${Whispercpp_BUILD_TYPE} diff --git a/src/whisper-processing.cpp b/src/whisper-processing.cpp index 75be45c..be78d42 100644 --- a/src/whisper-processing.cpp +++ b/src/whisper-processing.cpp @@ -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(), @@ -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) { @@ -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 lock(*gf->whisper_ctx_mutex); if (gf->whisper_context == nullptr) { obs_log(LOG_WARNING, "Whisper context is null, exiting thread");