Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing crash on linux filter add #28

Merged
merged 7 commits into from
Sep 28, 2023
Merged
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
1 change: 1 addition & 0 deletions .github/scripts/.Aptfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ package 'git'
package 'jq'
package 'ninja-build', bin: 'ninja'
package 'pkg-config'
package 'libopenblas-dev'
11 changes: 6 additions & 5 deletions cmake/BuildWhispercpp.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ endif()
# On linux add the `-fPIC` flag to the compiler
if(UNIX AND NOT APPLE)
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 on Windows - download OpenBLAS prebuilt binaries
if(WIN32)
if(LOCALVOCAL_WITH_CUDA)
# Build with CUDA Check that CUDA_TOOLKIT_ROOT_DIR is set
Expand All @@ -24,7 +25,7 @@ if(WIN32)

set(WHISPER_ADDITIONAL_ENV "CUDAToolkit_ROOT=${CUDA_TOOLKIT_ROOT_DIR}")
set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_CUBLAS=ON -DCMAKE_GENERATOR_TOOLSET=cuda=${CUDA_TOOLKIT_ROOT_DIR})
else(LOCALVOCAL_WITH_CUDA)
else()
# Build with OpenBLAS
set(OpenBLAS_URL "https://github.com/xianyi/OpenBLAS/releases/download/v0.3.24/OpenBLAS-0.3.24-x64.zip")
set(OpenBLAS_SHA256 "6335128ee7117ea2dd2f5f96f76dafc17256c85992637189a2d5f6da0c608163")
Expand All @@ -40,7 +41,7 @@ if(WIN32)
set(OpenBLAS_DIR ${INSTALL_DIR})
set(WHISPER_ADDITIONAL_ENV "OPENBLAS_PATH=${OpenBLAS_DIR}")
set(WHISPER_ADDITIONAL_CMAKE_ARGS -DWHISPER_BLAS=ON -DWHISPER_CUBLAS=OFF)
endif(LOCALVOCAL_WITH_CUDA)
endif()

ExternalProject_Add(
Whispercpp_Build
Expand Down Expand Up @@ -78,12 +79,12 @@ else()
CMAKE_GENERATOR ${CMAKE_GENERATOR}
INSTALL_COMMAND ${CMAKE_COMMAND} --install <BINARY_DIR> --config ${Whispercpp_BUILD_TYPE}
CONFIGURE_COMMAND
${CMAKE_COMMAND} -E env OPENBLAS_PATH=${OpenBLAS_DIR} ${CMAKE_COMMAND} <SOURCE_DIR> -B <BINARY_DIR> -G
${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}
-DCMAKE_GENERATOR_PLATFORM=${CMAKE_GENERATOR_PLATFORM} -DCMAKE_OSX_DEPLOYMENT_TARGET=10.13
-DCMAKE_OSX_ARCHITECTURES=${CMAKE_OSX_ARCHITECTURES_} -DCMAKE_CXX_FLAGS=${WHISPER_EXTRA_CXX_FLAGS}
-DCMAKE_C_FLAGS=${WHISPER_EXTRA_CXX_FLAGS} -DBUILD_SHARED_LIBS=OFF -DWHISPER_BUILD_TESTS=OFF
-DWHISPER_BUILD_EXAMPLES=OFF -DWHISPER_BLAS=OFF)
-DWHISPER_BUILD_EXAMPLES=OFF ${WHISPER_ADDITIONAL_CMAKE_ARGS})
endif(WIN32)

ExternalProject_Get_Property(Whispercpp_Build INSTALL_DIR)
Expand Down
2 changes: 1 addition & 1 deletion src/transcription-filter-data.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct transcription_filter_data {
audio_resampler_t *resampler = nullptr;

/* whisper */
std::string whisper_model_path;
char *whisper_model_path = nullptr;
struct whisper_context *whisper_context = nullptr;
whisper_full_params whisper_params;

Expand Down
14 changes: 8 additions & 6 deletions src/transcription-filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,12 +311,15 @@ void transcription_filter_update(void *data, obs_data_t *s)
// update the whisper model path
std::string new_model_path = obs_data_get_string(s, "whisper_model_path");

if (new_model_path != gf->whisper_model_path) {
if (gf->whisper_model_path == nullptr ||
strcmp(new_model_path.c_str(), gf->whisper_model_path) != 0) {
// model path changed, reload the model
obs_log(LOG_INFO, "model path changed, reloading model");
shutdown_whisper_thread(gf);

gf->whisper_model_path = new_model_path;
if (gf->whisper_model_path != nullptr) {
bfree(gf->whisper_model_path);
}
gf->whisper_model_path = bstrdup(new_model_path.c_str());

// check if the new model is external file
if (new_model_path.find("!!!external!!!") == std::string::npos) {
Expand Down Expand Up @@ -395,8 +398,7 @@ void transcription_filter_update(void *data, obs_data_t *s)

void *transcription_filter_create(obs_data_t *settings, obs_source_t *filter)
{
void *p = bzalloc(sizeof(struct transcription_filter_data));
struct transcription_filter_data *gf = new (p) transcription_filter_data;
struct transcription_filter_data *gf = new transcription_filter_data;

// Get the number of channels for the input source
gf->channels = audio_output_get_channels(obs_get_audio());
Expand All @@ -421,7 +423,7 @@ void *transcription_filter_create(obs_data_t *settings, obs_source_t *filter)
}

gf->context = filter;
gf->whisper_model_path = ""; // The update function will set the model path
gf->whisper_model_path = nullptr; // The update function will set the model path

gf->overlap_ms = OVERLAP_SIZE_MSEC;
gf->overlap_frames = (size_t)((float)gf->sample_rate / (1000.0f / (float)gf->overlap_ms));
Expand Down