Skip to content

Commit 1f978cf

Browse files
author
litongmacos
committed
add utils
1 parent ee16aac commit 1f978cf

File tree

4 files changed

+28
-16
lines changed

4 files changed

+28
-16
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ target_link_libraries(stream_local whisper ${SDL2_LIBRARIES})
5353
add_executable(whisper_http_server_base_httplib whisper_http_server_base_httplib.cpp common/common.cpp httplib/httplib.h nlohmann/json.hpp handler/inference_handler.cpp params/whisper_params.cpp)
5454
target_link_libraries(whisper_http_server_base_httplib whisper)
5555

56-
add_executable(whisper_server_base_on_uwebsockets whisper_server_base_on_uwebsockets.cpp stream/stream_components_service.cpp)
56+
add_executable(whisper_server_base_on_uwebsockets whisper_server_base_on_uwebsockets.cpp stream/stream_components_service.cpp utils/utils.cpp)
5757
#添加头文件
5858
target_include_directories(whisper_server_base_on_uwebsockets PRIVATE ${UWEBSOCKETS_INCLUDE_DIRS})
5959
# 链接 uWebSockets、zlib、libuv 和 uSockets 库

utils/utils.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// Created by Ping Lee on 2023/11/21.
3+
//
4+
5+
#include "utils.h"
6+
#include <string>
7+
#include <sstream>
8+
#include <iomanip>
9+
10+
std::string get_current_time() {
11+
auto now = std::chrono::system_clock::now();
12+
auto now_c = std::chrono::system_clock::to_time_t(now);
13+
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
14+
15+
std::stringstream current_time_ss;
16+
current_time_ss << std::put_time(std::localtime(&now_c), "%y-%m-%d %H:%M:%S")
17+
<< '.' << std::setfill('0') << std::setw(3) << milliseconds.count();
18+
19+
std::string current_time = current_time_ss.str();
20+
return current_time;
21+
}

utils/utils.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#pragma once
2+
3+
#include <iostream>
4+
5+
std::string get_current_time();

whisper_server_base_on_uwebsockets.cpp

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
#include "nlohmann/json.hpp"
2-
#include "stream/stream_components_params.h"
32
#include "stream/stream_components_service.h"
43
#include "stream/stream_components.h"
5-
4+
#include "utils/utils.h"
65
#include <uwebsockets/App.h>
76
#include <iostream>
87
#include <string>
@@ -11,19 +10,6 @@
1110

1211
using namespace stream_components;
1312

14-
std::string get_current_time() {
15-
auto now = std::chrono::system_clock::now();
16-
auto now_c = std::chrono::system_clock::to_time_t(now);
17-
auto milliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(now.time_since_epoch()) % 1000;
18-
19-
std::stringstream current_time_ss;
20-
current_time_ss << std::put_time(std::localtime(&now_c), "%y-%m-%d %H:%M:%S")
21-
<< '.' << std::setfill('0') << std::setw(3) << milliseconds.count();
22-
23-
std::string current_time = current_time_ss.str();
24-
return current_time;
25-
}
26-
2713
int main(int argc, char **argv) {
2814
// Read parameters...
2915
whisper_local_stream_params params;

0 commit comments

Comments
 (0)