- Add RNNoise neural network audio denoising (16kHz↔48kHz resampling) - Add transient suppressor to filter claps/clicks/pops before RNNoise - VAD now works on FILTERED audio (not raw) to avoid false triggers - Real-time denoised audio level display in UI - Save denoised audio previews in Opus format (.ogg) - Add extensive Whisper hallucination filter (Tingting, music, etc.) - Add "Clear" button to reset accumulated translations - Double VAD thresholds (0.02/0.08) for less sensitivity - Update Claude prompt to handle offensive content gracefully 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
246 lines
6.5 KiB
CMake
246 lines
6.5 KiB
CMake
cmake_minimum_required(VERSION 3.20)
|
|
project(SecondVoice VERSION 0.1.0 LANGUAGES C CXX)
|
|
|
|
set(CMAKE_CXX_STANDARD 17)
|
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
|
|
|
# FetchContent for downloading ImGui from source
|
|
include(FetchContent)
|
|
|
|
# Force static linking for MinGW
|
|
if(MINGW)
|
|
set(BUILD_SHARED_LIBS OFF)
|
|
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libgcc -static-libstdc++")
|
|
endif()
|
|
|
|
# Fetch ImGui from GitHub (like WarFactory does!)
|
|
FetchContent_Declare(
|
|
imgui
|
|
GIT_REPOSITORY https://github.com/ocornut/imgui.git
|
|
GIT_TAG v1.90.1
|
|
)
|
|
|
|
FetchContent_MakeAvailable(imgui)
|
|
|
|
# Fetch Ogg and Opus for audio encoding
|
|
FetchContent_Declare(
|
|
ogg
|
|
GIT_REPOSITORY https://github.com/xiph/ogg.git
|
|
GIT_TAG v1.3.6
|
|
)
|
|
|
|
FetchContent_Declare(
|
|
opus
|
|
GIT_REPOSITORY https://github.com/xiph/opus.git
|
|
GIT_TAG v1.5.2
|
|
)
|
|
|
|
FetchContent_MakeAvailable(ogg opus)
|
|
|
|
# Fetch RNNoise for noise reduction (using older stable version)
|
|
FetchContent_Declare(
|
|
rnnoise
|
|
GIT_REPOSITORY https://github.com/xiph/rnnoise.git
|
|
GIT_TAG v0.1.1
|
|
)
|
|
|
|
FetchContent_MakeAvailable(rnnoise)
|
|
|
|
# Build RNNoise as a static library (v0.1.1 structure)
|
|
add_library(rnnoise STATIC
|
|
${rnnoise_SOURCE_DIR}/src/denoise.c
|
|
${rnnoise_SOURCE_DIR}/src/rnn.c
|
|
${rnnoise_SOURCE_DIR}/src/rnn_data.c
|
|
${rnnoise_SOURCE_DIR}/src/pitch.c
|
|
${rnnoise_SOURCE_DIR}/src/kiss_fft.c
|
|
${rnnoise_SOURCE_DIR}/src/celt_lpc.c
|
|
)
|
|
|
|
target_include_directories(rnnoise PUBLIC
|
|
${rnnoise_SOURCE_DIR}/include
|
|
${rnnoise_SOURCE_DIR}/src
|
|
)
|
|
|
|
# RNNoise needs math library
|
|
if(UNIX)
|
|
target_link_libraries(rnnoise PRIVATE m)
|
|
endif()
|
|
|
|
# Create ImGui library with OpenGL/GLFW backends
|
|
add_library(imgui_backends
|
|
${imgui_SOURCE_DIR}/imgui.cpp
|
|
${imgui_SOURCE_DIR}/imgui_demo.cpp
|
|
${imgui_SOURCE_DIR}/imgui_draw.cpp
|
|
${imgui_SOURCE_DIR}/imgui_tables.cpp
|
|
${imgui_SOURCE_DIR}/imgui_widgets.cpp
|
|
${imgui_SOURCE_DIR}/backends/imgui_impl_glfw.cpp
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/imgui_opengl3_glad.cpp # Our wrapper with GLAD
|
|
)
|
|
|
|
target_include_directories(imgui_backends PUBLIC
|
|
${imgui_SOURCE_DIR}
|
|
${imgui_SOURCE_DIR}/backends
|
|
)
|
|
|
|
# Find packages (no more vcpkg imgui!)
|
|
find_package(portaudio CONFIG REQUIRED)
|
|
find_package(nlohmann_json CONFIG REQUIRED)
|
|
find_package(glfw3 CONFIG REQUIRED)
|
|
find_package(glad CONFIG REQUIRED)
|
|
find_package(OpenGL REQUIRED)
|
|
|
|
# Link imgui_backends with glfw and OpenGL
|
|
target_link_libraries(imgui_backends PUBLIC glfw OpenGL::GL glad::glad)
|
|
|
|
# Source files for UI version
|
|
set(SOURCES_UI
|
|
src/main.cpp
|
|
# Audio module
|
|
src/audio/AudioCapture.cpp
|
|
src/audio/AudioBuffer.cpp
|
|
src/audio/NoiseReducer.cpp
|
|
# API clients
|
|
src/api/WhisperClient.cpp
|
|
src/api/ClaudeClient.cpp
|
|
src/api/WinHttpClient.cpp
|
|
# UI
|
|
src/ui/TranslationUI.cpp
|
|
# Utils
|
|
src/utils/Config.cpp
|
|
# Core
|
|
src/core/Pipeline.cpp
|
|
)
|
|
|
|
# Source files for Console version (NO UI, NO Pipeline)
|
|
set(SOURCES_CONSOLE
|
|
src/main_console.cpp
|
|
# Audio module
|
|
src/audio/AudioCapture.cpp
|
|
src/audio/AudioBuffer.cpp
|
|
src/audio/NoiseReducer.cpp
|
|
# API clients
|
|
src/api/WhisperClient.cpp
|
|
src/api/ClaudeClient.cpp
|
|
src/api/WinHttpClient.cpp
|
|
# Utils
|
|
src/utils/Config.cpp
|
|
# Core - WAIT, Pipeline uses UI!
|
|
# src/core/Pipeline.cpp
|
|
)
|
|
|
|
# UI Executable
|
|
add_executable(${PROJECT_NAME} ${SOURCES_UI})
|
|
|
|
# Console Executable (NO UI)
|
|
add_executable(${PROJECT_NAME}_Console ${SOURCES_CONSOLE})
|
|
|
|
# Include directories
|
|
target_include_directories(${PROJECT_NAME} PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
${rnnoise_SOURCE_DIR}/include
|
|
)
|
|
target_include_directories(${PROJECT_NAME}_Console PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
${rnnoise_SOURCE_DIR}/include
|
|
)
|
|
|
|
# Link libraries
|
|
if(MINGW AND NOT BUILD_SHARED_LIBS)
|
|
# Static linking for MinGW - need to add Windows system libs for portaudio
|
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
|
${CMAKE_CURRENT_BINARY_DIR}/vcpkg_installed/x64-mingw-static/lib/libportaudio.a
|
|
nlohmann_json::nlohmann_json
|
|
imgui_backends
|
|
${CMAKE_CURRENT_BINARY_DIR}/vcpkg_installed/x64-mingw-static/lib/libglfw3.a
|
|
glad::glad
|
|
OpenGL::GL
|
|
opus
|
|
ogg
|
|
rnnoise
|
|
# Windows system libraries
|
|
winmm
|
|
setupapi
|
|
ws2_32
|
|
winhttp
|
|
)
|
|
# Console version - NO UI libs
|
|
target_link_libraries(${PROJECT_NAME}_Console PRIVATE
|
|
${CMAKE_CURRENT_BINARY_DIR}/vcpkg_installed/x64-mingw-static/lib/libportaudio.a
|
|
nlohmann_json::nlohmann_json
|
|
opus
|
|
ogg
|
|
rnnoise
|
|
# Windows system libraries
|
|
winmm
|
|
setupapi
|
|
ws2_32
|
|
winhttp
|
|
)
|
|
else()
|
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
|
portaudio_static
|
|
nlohmann_json::nlohmann_json
|
|
imgui_backends
|
|
glfw
|
|
glad::glad
|
|
OpenGL::GL
|
|
opus
|
|
ogg
|
|
rnnoise
|
|
)
|
|
# Console version - NO UI libs
|
|
target_link_libraries(${PROJECT_NAME}_Console PRIVATE
|
|
portaudio_static
|
|
nlohmann_json::nlohmann_json
|
|
opus
|
|
ogg
|
|
rnnoise
|
|
)
|
|
endif()
|
|
|
|
# Compiler options
|
|
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
|
|
target_compile_options(${PROJECT_NAME} PRIVATE
|
|
-Wall
|
|
-Wextra
|
|
-Wpedantic
|
|
)
|
|
target_compile_options(${PROJECT_NAME}_Console PRIVATE
|
|
-Wall
|
|
-Wextra
|
|
-Wpedantic
|
|
)
|
|
|
|
# MinGW: cpp-httplib's GetAddrInfoExCancel is not available
|
|
# Don't treat warnings as errors for MinGW due to httplib incompatibilities
|
|
if(NOT MINGW)
|
|
target_compile_options(${PROJECT_NAME} PRIVATE -Werror)
|
|
target_compile_options(${PROJECT_NAME}_Console PRIVATE -Werror)
|
|
else()
|
|
# Force console subsystem on Windows (not GUI subsystem)
|
|
target_link_options(${PROJECT_NAME} PRIVATE -mconsole)
|
|
target_link_options(${PROJECT_NAME}_Console PRIVATE -mconsole)
|
|
|
|
# FORCE GPU exports using .def file (like games do!)
|
|
target_link_options(${PROJECT_NAME} PRIVATE
|
|
-Wl,--export-all-symbols
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src/gpu_exports.def
|
|
)
|
|
endif()
|
|
endif()
|
|
|
|
# Copy config files to build directory
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.json
|
|
${CMAKE_CURRENT_BINARY_DIR}/config.json COPYONLY)
|
|
|
|
# Copy .env file if it exists
|
|
if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/.env)
|
|
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/.env
|
|
${CMAKE_CURRENT_BINARY_DIR}/.env COPYONLY)
|
|
endif()
|
|
|
|
# Install target
|
|
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
|
|
install(FILES config.json DESTINATION bin)
|