Skip to content

Commit afd06fa

Browse files
author
litongjava
committed
add whisper_server_base_on_uwebsockets.cpp
1 parent 35048fd commit afd06fa

File tree

3 files changed

+53
-3
lines changed

3 files changed

+53
-3
lines changed

CMakeLists.txt

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,17 @@
11
cmake_minimum_required(VERSION 3.23)
22
project(whisper_cpp_server)
33

4-
set(CMAKE_CXX_STANDARD 14)
4+
set(CMAKE_CXX_STANDARD 17)
5+
# 查找 uWebSockets 的头文件路径
6+
find_path(UWEBSOCKETS_INCLUDE_DIRS "uwebsockets/App.h")
7+
# 查找 zlib 库
8+
find_package(ZLIB REQUIRED)
9+
10+
# 查找 libuv 库
11+
find_package(libuv CONFIG REQUIRED)
12+
# 查找 uSockets 库
13+
find_library(USOCKETS_LIBRARY uSockets)
14+
515
# find SDL2 library
616
find_package(SDL2 CONFIG REQUIRED)
717
message(STATUS "SDL2 include directories: ${SDL2_INCLUDE_DIRS}")
@@ -37,9 +47,28 @@ target_link_libraries(simplest whisper)
3747
add_executable(stream_local common.cpp common-sdl.cpp stream_local.cpp
3848
stream_components_service.cpp stream_components_audio.cpp
3949
stream_components_output.cpp
40-
)
50+
whisper_server_base_on_uwebsockets.cpp
51+
)
4152
target_link_libraries(stream_local whisper ${SDL2_LIBRARIES})
4253

4354
add_executable(whisper_http_server_base_httplib whisper_http_server_base_httplib.cpp common.cpp httplib.h json.hpp inference_handler.cpp whisper_params.cpp)
44-
target_link_libraries(server whisper)
55+
target_link_libraries(whisper_http_server_base_httplib whisper)
56+
57+
# 链接 uWebSockets、zlib、libuv 和 uSockets 库
58+
add_executable(whisper_server_base_on_uwebsockets whisper_server_base_on_uwebsockets.cpp)
59+
#添加头文件
60+
target_include_directories(whisper_server_base_on_uwebsockets PRIVATE ${UWEBSOCKETS_INCLUDE_DIRS})
61+
# 链接 uWebSockets、zlib、libuv 和 uSockets 库
62+
# 检测操作系统
63+
if(WIN32)
64+
# 如果是 Windows
65+
target_link_libraries(whisper_server_base_on_uwebsockets PRIVATE whisper ZLIB::ZLIB libuv::uv ${USOCKETS_LIBRARY})
66+
elseif(APPLE)
67+
# 如果是 MacOS
68+
target_link_libraries(whisper_server_base_on_uwebsockets PRIVATE whisper ZLIB::ZLIB libuv::uv_a ${USOCKETS_LIBRARY})
69+
else()
70+
# 对于其他系统,比如 Linux
71+
target_link_libraries(whisper_server_base_on_uwebsockets PRIVATE whisper ZLIB::ZLIB libuv::uv ${USOCKETS_LIBRARY})
72+
endif()
73+
4574

vcpkg.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@
99
}, {
1010
"name" : "websocketpp",
1111
"version>=" : "0.8.2#3"
12+
}, {
13+
"name" : "uwebsockets",
14+
"version>=" : "20.47.0"
1215
} ]
1316
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include <uwebsockets/App.h>
2+
#include <iostream>
3+
4+
int main(int argc, char **argv) {
5+
auto hello_action = [](auto *res, auto *req) {
6+
res->end("Hello World!");
7+
};
8+
9+
auto started_handler = [](auto *token) {
10+
if (token) {
11+
std::cout << "Server started on port 3000" << std::endl;
12+
} else {
13+
std::cerr << "Failed to start server" << std::endl;
14+
}
15+
};
16+
17+
uWS::App().get("/hello", hello_action).listen(3000, started_handler).run();
18+
}

0 commit comments

Comments
 (0)