From 65408db097ffa7796a725fe24bf6c2ecd06339ee Mon Sep 17 00:00:00 2001 From: Roy Shilkrot Date: Tue, 1 Oct 2024 13:41:47 -0400 Subject: [PATCH] refactor: Add filter-replace-utils for serializing and deserializing (#170) - Add filter-replace-utils for serializing and deserializing in the src/ui directory. - Update CMakeLists.txt to include the new files in the target_sources. - Update FindLibAvObs.cmake to read buildspec.json from the CMAKE_SOURCE_DIR. - Update model-infos.cpp to include two new Whisper models. - Add a new CMakeLists.txt file in the src/tests directory. - Add localvocal-offline-test.cpp in the src/tests directory. - Add clear_current_caption function in localvocal-offline-test.cpp. --- CMakeLists.txt | 29 +-------------------------- cmake/FindLibAvObs.cmake | 4 ++-- src/model-utils/model-infos.cpp | 16 +++++++++++++-- src/tests/CMakeLists.txt | 29 +++++++++++++++++++++++++++ src/tests/localvocal-offline-test.cpp | 15 ++++++++++++++ 5 files changed, 61 insertions(+), 32 deletions(-) create mode 100644 src/tests/CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 9233158..cea698e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -130,32 +130,5 @@ target_sources( set_target_properties_plugin(${CMAKE_PROJECT_NAME} PROPERTIES OUTPUT_NAME ${_name}) if(ENABLE_TESTS) - add_executable(${CMAKE_PROJECT_NAME}-tests) - - include(cmake/FindLibAvObs.cmake) - - target_sources( - ${CMAKE_PROJECT_NAME}-tests - PRIVATE src/tests/localvocal-offline-test.cpp - src/tests/audio-file-utils.cpp - src/transcription-utils.cpp - src/model-utils/model-infos.cpp - src/model-utils/model-find-utils.cpp - src/whisper-utils/whisper-processing.cpp - src/whisper-utils/whisper-utils.cpp - src/whisper-utils/silero-vad-onnx.cpp - src/whisper-utils/token-buffer-thread.cpp - src/whisper-utils/vad-processing.cpp - src/translation/language_codes.cpp - src/translation/translation.cpp - src/ui/filter-replace-utils.cpp - src/translation/translation-language-utils.cpp) - - find_libav(${CMAKE_PROJECT_NAME}-tests) - - target_link_libraries(${CMAKE_PROJECT_NAME}-tests PRIVATE ct2 sentencepiece Whispercpp Ort OBS::libobs ICU) - target_include_directories(${CMAKE_PROJECT_NAME}-tests PRIVATE src) - - # install the tests to the release/test directory - install(TARGETS ${CMAKE_PROJECT_NAME}-tests DESTINATION test) + add_subdirectory(src/tests) endif() diff --git a/cmake/FindLibAvObs.cmake b/cmake/FindLibAvObs.cmake index 188d221..5490bad 100644 --- a/cmake/FindLibAvObs.cmake +++ b/cmake/FindLibAvObs.cmake @@ -20,7 +20,7 @@ function(find_libav TARGET) endif() if(NOT buildspec) - file(READ "${CMAKE_CURRENT_SOURCE_DIR}/buildspec.json" buildspec) + file(READ "${CMAKE_SOURCE_DIR}/buildspec.json" buildspec) endif() string( JSON @@ -36,7 +36,7 @@ function(find_libav TARGET) elseif(APPLE) set(arch universal) endif() - set(deps_root "${CMAKE_CURRENT_SOURCE_DIR}/.deps/obs-deps-${version}-${arch}") + set(deps_root "${CMAKE_SOURCE_DIR}/.deps/obs-deps-${version}-${arch}") target_include_directories(${TARGET} PRIVATE "${deps_root}/include") target_link_libraries( diff --git a/src/model-utils/model-infos.cpp b/src/model-utils/model-infos.cpp index e978002..1cf4ad9 100644 --- a/src/model-utils/model-infos.cpp +++ b/src/model-utils/model-infos.cpp @@ -221,14 +221,26 @@ std::map models_info = {{ "7d99f41a10525d0206bddadd86760181fa920438b6b33237e3118ff6c83bb53d"}}}}, {"Whisper Medium English (1.5Gb)", {"Whisper Medium English", - "ggml-meduim-en", + "ggml-medium-en", MODEL_TYPE_TRANSCRIPTION, {{"https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-medium.en.bin", "cc37e93478338ec7700281a7ac30a10128929eb8f427dda2e865faa8f6da4356"}}}}, {"Whisper Medium (1.5Gb)", {"Whisper Medium", - "ggml-meduim", + "ggml-medium", MODEL_TYPE_TRANSCRIPTION, {{"https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-medium.bin", "6c14d5adee5f86394037b4e4e8b59f1673b6cee10e3cf0b11bbdbee79c156208"}}}}, + {"Whisper Large v3 Turbo (1.62Gb)", + {"Whisper Large v3 Turbo", + "ggml-large-v3-turbo", + MODEL_TYPE_TRANSCRIPTION, + {{"https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-large-v3-turbo.bin", + "1FC70F774D38EB169993AC391EEA357EF47C88757EF72EE5943879B7E8E2BC69"}}}}, + {"Whisper Large v3 Turbo q5 (574Mb)", + {"Whisper Large v3 Turbo q5", + "ggml-large-v3-turbo-q5_0", + MODEL_TYPE_TRANSCRIPTION, + {{"https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-large-v3-turbo-q5_0.bin", + "394221709CD5AD1F40C46E6031CA61BCE88931E6E088C188294C6D5A55FFA7E2"}}}}, }}; diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt new file mode 100644 index 0000000..51cde2d --- /dev/null +++ b/src/tests/CMakeLists.txt @@ -0,0 +1,29 @@ +set(TEST_EXEC_NAME ${CMAKE_PROJECT_NAME}-tests) + +add_executable(${TEST_EXEC_NAME}) + +target_sources( + ${TEST_EXEC_NAME} + PRIVATE ${CMAKE_SOURCE_DIR}/src/tests/localvocal-offline-test.cpp + ${CMAKE_SOURCE_DIR}/src/tests/audio-file-utils.cpp + ${CMAKE_SOURCE_DIR}/src/transcription-utils.cpp + ${CMAKE_SOURCE_DIR}/src/model-utils/model-infos.cpp + ${CMAKE_SOURCE_DIR}/src/model-utils/model-find-utils.cpp + ${CMAKE_SOURCE_DIR}/src/whisper-utils/whisper-processing.cpp + ${CMAKE_SOURCE_DIR}/src/whisper-utils/whisper-utils.cpp + ${CMAKE_SOURCE_DIR}/src/whisper-utils/silero-vad-onnx.cpp + ${CMAKE_SOURCE_DIR}/src/whisper-utils/token-buffer-thread.cpp + ${CMAKE_SOURCE_DIR}/src/whisper-utils/vad-processing.cpp + ${CMAKE_SOURCE_DIR}/src/translation/language_codes.cpp + ${CMAKE_SOURCE_DIR}/src/translation/translation.cpp + ${CMAKE_SOURCE_DIR}/src/ui/filter-replace-utils.cpp + ${CMAKE_SOURCE_DIR}/src/translation/translation-language-utils.cpp) + +include(${CMAKE_SOURCE_DIR}/cmake/FindLibAvObs.cmake) +find_libav(${TEST_EXEC_NAME}) + +target_link_libraries(${TEST_EXEC_NAME} PRIVATE ct2 sentencepiece Whispercpp Ort OBS::libobs ICU) +target_include_directories(${TEST_EXEC_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/src) + +# install the tests to the release/test directory +install(TARGETS ${TEST_EXEC_NAME} DESTINATION test) diff --git a/src/tests/localvocal-offline-test.cpp b/src/tests/localvocal-offline-test.cpp index 3c0f4a4..bfb6bfa 100644 --- a/src/tests/localvocal-offline-test.cpp +++ b/src/tests/localvocal-offline-test.cpp @@ -276,6 +276,21 @@ void json_segments_saver_thread_function() } } +void clear_current_caption(transcription_filter_data *gf_) +{ + if (gf_->captions_monitor.isEnabled()) { + gf_->captions_monitor.clear(); + gf_->translation_monitor.clear(); + } + // reset translation context + gf_->last_text_for_translation = ""; + gf_->last_text_translation = ""; + gf_->translation_ctx.last_input_tokens.clear(); + gf_->translation_ctx.last_translation_tokens.clear(); + gf_->last_transcription_sentence.clear(); + gf_->cleared_last_sub = true; +} + void set_text_callback(struct transcription_filter_data *gf, const DetectionResultWithText &resultIn) {