Replace WAV with Opus encoding for Whisper API uploads: - Add libopus & libogg via FetchContent (no vcpkg dependency) - Implement AudioBuffer::saveToOpus() with Ogg container - Configure Opus encoder for voice (VOIP mode, 32kbps VBR) - Update WhisperClient to use Opus format (audio/ogg) - Fix Windows temp file path compatibility Benefits: - 46x smaller files (37KB vs 1.7MB for 10s audio) - Reduced API costs and bandwidth - Faster uploads for real-time translation - Whisper API fully supports Opus/Ogg format 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
202 lines
5.4 KiB
CMake
202 lines
5.4 KiB
CMake
cmake_minimum_required(VERSION 3.20)
|
|
project(SecondVoice VERSION 0.1.0 LANGUAGES 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)
|
|
|
|
# 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(httplib 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
|
|
# API clients
|
|
src/api/WhisperClient.cpp
|
|
src/api/ClaudeClient.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
|
|
# API clients
|
|
src/api/WhisperClient.cpp
|
|
src/api/ClaudeClient.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
|
|
)
|
|
target_include_directories(${PROJECT_NAME}_Console PRIVATE
|
|
${CMAKE_CURRENT_SOURCE_DIR}/src
|
|
)
|
|
|
|
# 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
|
|
httplib::httplib
|
|
nlohmann_json::nlohmann_json
|
|
imgui_backends
|
|
${CMAKE_CURRENT_BINARY_DIR}/vcpkg_installed/x64-mingw-static/lib/libglfw3.a
|
|
glad::glad
|
|
OpenGL::GL
|
|
opus
|
|
ogg
|
|
# Windows system libraries for portaudio
|
|
winmm
|
|
setupapi
|
|
)
|
|
# Console version - NO UI libs
|
|
target_link_libraries(${PROJECT_NAME}_Console PRIVATE
|
|
${CMAKE_CURRENT_BINARY_DIR}/vcpkg_installed/x64-mingw-static/lib/libportaudio.a
|
|
httplib::httplib
|
|
nlohmann_json::nlohmann_json
|
|
opus
|
|
ogg
|
|
# Windows system libraries for portaudio
|
|
winmm
|
|
setupapi
|
|
)
|
|
else()
|
|
target_link_libraries(${PROJECT_NAME} PRIVATE
|
|
portaudio
|
|
httplib::httplib
|
|
nlohmann_json::nlohmann_json
|
|
imgui_backends
|
|
glfw
|
|
glad::glad
|
|
OpenGL::GL
|
|
opus
|
|
ogg
|
|
)
|
|
# Console version - NO UI libs
|
|
target_link_libraries(${PROJECT_NAME}_Console PRIVATE
|
|
portaudio
|
|
httplib::httplib
|
|
nlohmann_json::nlohmann_json
|
|
opus
|
|
ogg
|
|
)
|
|
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)
|
|
|
|
# Install target
|
|
install(TARGETS ${PROJECT_NAME} DESTINATION bin)
|
|
install(FILES config.json DESTINATION bin)
|