Skip to content

Commit 3e2eedb

Browse files
author
litongjava
committed
rename to WhisperService
1 parent 68b7bc9 commit 3e2eedb

14 files changed

+99
-99
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ target_link_libraries(sdl_version ${SDL2_LIBRARIES})
3434
add_executable(simplest simplest.cpp common.cpp)
3535
target_link_libraries(simplest whisper)
3636

37-
add_executable(stream_components stream_components.cpp stream_components_audio.cpp stream_components_output.cpp stream_components_service.cpp)
37+
add_executable(stream_components stream_local.cpp stream_components_audio.cpp stream_components_output.cpp stream_components_service.cpp)
3838
target_link_libraries(stream_components ${SDL2_LIBRARIES})
3939

4040
add_executable(server server.cpp common.cpp httplib.h json.hpp inference_handler.cpp whisper_params.cpp)

README.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# whisper-cpp server
1+
# whisper-cpp service
22
## simplest
33
```shell
44
cmake-build-debug/simplest -m models/ggml-base.en.bin samples/jfk.wav
@@ -11,12 +11,12 @@ options:
1111
-m FNAME, --model FNAME [models/ggml-base.en.bin] model path
1212
-di, --diarize [false ] stereo audio diarization
1313
```
14-
## server
14+
## service
1515

16-
Simple http server. WAV Files are passed to the inference model via http requests.
16+
Simple http service. WAV Files are passed to the inference model via http requests.
1717

1818
```
19-
./cmake-build-debug/server -m models/ggml-base.en.bin
19+
./cmake-build-debug/service -m models/ggml-base.en.bin
2020
```
2121

2222
```shell
@@ -81,7 +81,7 @@ ggml_metal_add_buffer: allocated 'backend ' buffer, size = 4.05 MB,
8181
ggml_metal_add_buffer: allocated 'backend ' buffer, size = 3.08 MB, ( 203.67 / 11453.25)
8282
ggml_metal_add_buffer: allocated 'backend ' buffer, size = 94.78 MB, ( 298.45 / 11453.25)
8383

84-
whisper server listening at http://0.0.0.0:8080
84+
whisper service listening at http://0.0.0.0:8080
8585

8686
Received request: jfk.wav
8787
Successfully loaded jfk.wav
@@ -95,9 +95,9 @@ Running whisper.cpp inference on jfk.wav
9595
[00:00:00.000 --> 00:00:11.000] And so my fellow Americans, ask not what your country can do for you, ask what you can do for your country.
9696
```
9797
```
98-
./server -h
98+
./service -h
9999

100-
usage: ./bin/server [options]
100+
usage: ./bin/service [options]
101101

102102
options:
103103
-h, --help [default] show this help message and exit
@@ -128,8 +128,8 @@ options:
128128
--prompt PROMPT [ ] initial prompt
129129
-m FNAME, --model FNAME [models/ggml-base.en.bin] model path
130130
-oved D, --ov-e-device DNAME [CPU ] the OpenVINO device used for encode inference
131-
--host HOST, [127.0.0.1] Hostname/ip-adress for the server
132-
--port PORT, [8080 ] Port number for the server
131+
--host HOST, [127.0.0.1] Hostname/ip-adress for the service
132+
--port PORT, [8080 ] Port number for the service
133133
```
134134
135135
## request examples

httplib.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ namespace httplib {
468468
std::string local_addr;
469469
int local_port = -1;
470470

471-
// for server
471+
// for service
472472
std::string version;
473473
std::string target;
474474
Params params;
@@ -1895,7 +1895,7 @@ class SSLClient : public ClientImpl {
18951895
case Error::Canceled: return "Connection handling canceled";
18961896
case Error::SSLConnection: return "SSL connection failed";
18971897
case Error::SSLLoadingCerts: return "SSL certificate loading failed";
1898-
case Error::SSLServerVerification: return "SSL server verification failed";
1898+
case Error::SSLServerVerification: return "SSL service verification failed";
18991899
case Error::UnsupportedMultipartBoundaryChars:
19001900
return "Unsupported HTTP multipart boundary characters";
19011901
case Error::Compression: return "Compression failed";
@@ -5501,7 +5501,7 @@ namespace detail {
55015501

55025502
} // namespace detail
55035503

5504-
// HTTP server implementation
5504+
// HTTP service implementation
55055505
inline Server::Server()
55065506
: new_task_queue(
55075507
[] { return new ThreadPool(CPPHTTPLIB_THREAD_POOL_COUNT); }) {
@@ -6187,7 +6187,7 @@ inline bool Server::listen_internal() {
61876187
detail::close_socket(svr_sock_);
61886188
ret = false;
61896189
} else {
6190-
; // The server socket was closed by user.
6190+
; // The service socket was closed by user.
61916191
}
61926192
break;
61936193
}
@@ -8238,7 +8238,7 @@ static SSLInit sslinit_;
82388238

82398239
} // namespace detail
82408240

8241-
// SSL HTTP server implementation
8241+
// SSL HTTP service implementation
82428242
inline SSLServer::SSLServer(const char *cert_path, const char *private_key_path,
82438243
const char *client_ca_cert_file_path,
82448244
const char *client_ca_cert_dir_path,

inference_handler.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
using json = nlohmann::json;
88

99
struct whisper_print_user_data {
10-
const whisper_params *params;
10+
const whisper_local_stream_params *params;
1111

1212
const std::vector<std::vector<float>> *pcmf32s;
1313
int progress_prev;
@@ -149,7 +149,7 @@ void whisper_print_segment_callback(struct whisper_context *ctx, struct whisper_
149149
}
150150

151151
std::string
152-
output_str(struct whisper_context *ctx, const whisper_params &params, std::vector<std::vector<float>> pcmf32s) {
152+
output_str(struct whisper_context *ctx, const whisper_local_stream_params &params, std::vector<std::vector<float>> pcmf32s) {
153153
std::stringstream result;
154154
const int n_segments = whisper_full_n_segments(ctx);
155155
for (int i = 0; i < n_segments; ++i) {
@@ -178,7 +178,7 @@ void whisper_print_progress_callback(struct whisper_context * /*ctx*/, struct wh
178178
}
179179
}
180180

181-
void getReqParameters(const Request &req, whisper_params &params) {
181+
void getReqParameters(const Request &req, whisper_local_stream_params &params) {
182182
// user model configu.has_fileion
183183
if (req.has_file("offset-t")) {
184184
params.offset_t_ms = std::stoi(req.get_file_value("offset-t").content);
@@ -204,9 +204,9 @@ void getReqParameters(const Request &req, whisper_params &params) {
204204
}
205205

206206

207-
void getReqParameters(const Request &request, whisper_params &params);
207+
void getReqParameters(const Request &request, whisper_local_stream_params &params);
208208

209-
void handleInference(const Request &req, Response &res, std::mutex &whisper_mutex, whisper_params &params,
209+
void handleInference(const Request &req, Response &res, std::mutex &whisper_mutex, whisper_local_stream_params &params,
210210
whisper_context *ctx, char *arg_audio_file) {
211211
// aquire whisper model mutex lock
212212
whisper_mutex.lock();

inference_handler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
using namespace httplib;
77

8-
void handleInference(const Request &req, Response &res, std::mutex &whisper_mutex, whisper_params &params,
8+
void handleInference(const Request &req, Response &res, std::mutex &whisper_mutex, whisper_local_stream_params &params,
99
whisper_context *ctx, char *arg_audio_file);

server.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ bool is_file_exist(const char *fileName) {
1919
}
2020

2121
int main(int argc, char **argv) {
22-
whisper_params params;
22+
whisper_local_stream_params params;
2323
server_params sparams;
2424

2525
std::mutex whisper_mutex;
@@ -138,7 +138,7 @@ int main(int argc, char **argv) {
138138
svr.set_write_timeout(sparams.write_timeout);
139139

140140
if (!svr.bind_to_port(sparams.hostname, sparams.port)) {
141-
fprintf(stderr, "\ncouldn't bind to server socket: hostname=%s port=%d\n\n",
141+
fprintf(stderr, "\ncouldn't bind to service socket: hostname=%s port=%d\n\n",
142142
sparams.hostname.c_str(), sparams.port);
143143
return 1;
144144
}
@@ -147,7 +147,7 @@ int main(int argc, char **argv) {
147147
svr.set_base_dir(sparams.public_path);
148148

149149
// to make it ctrl+clickable:
150-
printf("\nwhisper server listening at http://%s:%d\n\n", sparams.hostname.c_str(), sparams.port);
150+
printf("\nwhisper service listening at http://%s:%d\n\n", sparams.hostname.c_str(), sparams.port);
151151

152152
if (!svr.listen_after_bind()) {
153153
return 1;

simplest.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void replace_all(std::string &s, const std::string &search, const std::string &r
5252
}
5353

5454
// command-line parameters
55-
struct whisper_params {
55+
struct whisper_local_stream_params {
5656
int32_t n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency());
5757
int32_t n_processors = 1;
5858
int32_t offset_t_ms = 0;
@@ -97,9 +97,9 @@ struct whisper_params {
9797
std::vector<std::string> fname_out = {};
9898
};
9999

100-
void whisper_print_usage(int argc, char **argv, const whisper_params &params);
100+
void whisper_print_usage(int argc, char **argv, const whisper_local_stream_params &params);
101101

102-
bool whisper_params_parse(int argc, char **argv, whisper_params &params) {
102+
bool whisper_params_parse(int argc, char **argv, whisper_local_stream_params &params) {
103103
for (int i = 1; i < argc; i++) {
104104
std::string arg = argv[i];
105105

@@ -128,7 +128,7 @@ bool whisper_params_parse(int argc, char **argv, whisper_params &params) {
128128
return true;
129129
}
130130

131-
void whisper_print_usage(int /*argc*/, char **argv, const whisper_params &params) {
131+
void whisper_print_usage(int /*argc*/, char **argv, const whisper_local_stream_params &params) {
132132
fprintf(stderr, "\n");
133133
fprintf(stderr, "usage: %s [options] file0.wav file1.wav ...\n", argv[0]);
134134
fprintf(stderr, "\n");
@@ -141,7 +141,7 @@ void whisper_print_usage(int /*argc*/, char **argv, const whisper_params &params
141141
}
142142

143143
struct whisper_print_user_data {
144-
const whisper_params *params;
144+
const whisper_local_stream_params *params;
145145

146146
const std::vector<std::vector<float>> *pcmf32s;
147147
int progress_prev;
@@ -298,7 +298,7 @@ char *escape_double_quotes_and_backslashes(const char *str) {
298298

299299
int main(int argc, char **argv) {
300300
printf("start\n");
301-
whisper_params params;
301+
whisper_local_stream_params params;
302302

303303
if (whisper_params_parse(argc, argv, params) == false) {
304304
whisper_print_usage(argc, argv, params);

stream_components_output.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,19 @@ void WhisperEncoderJSON::doindent() {
122122
}
123123

124124

125-
// -- WhisperOutput --
125+
// -- WhisperStreamOutput --
126126

127-
WhisperOutput::WhisperOutput(
127+
WhisperStreamOutput::WhisperStreamOutput(
128128
struct whisper_context *ctx,
129-
const server_params &params) :
129+
const service_params &params) :
130130
ctx(ctx),
131131
params(params) {
132132

133133
}
134134

135-
void WhisperOutput::encode_server(
135+
void WhisperStreamOutput::encode_server(
136136
WhisperEncoder &encoder,
137-
const server_params &params,
137+
const service_params &params,
138138
struct whisper_context *ctx) {
139139
encoder.reset();
140140

@@ -167,7 +167,7 @@ void WhisperOutput::encode_server(
167167
encoder.end_obj(true);
168168
}
169169

170-
void WhisperOutput::encode_transcription(WhisperEncoder &encoder) const {
170+
void WhisperStreamOutput::encode_transcription(WhisperEncoder &encoder) const {
171171
encoder.reset();
172172

173173
encoder.start_obj(nullptr);
@@ -223,12 +223,12 @@ void WhisperOutput::encode_transcription(WhisperEncoder &encoder) const {
223223
encoder.end_obj(true);
224224
}
225225

226-
void WhisperOutput::server_to_json(std::ostream &os, const server_params &params, struct whisper_context *ctx) {
226+
void WhisperStreamOutput::to_json(std::ostream &os, const service_params &params, struct whisper_context *ctx) {
227227
WhisperEncoderJSON encoder(os);
228-
WhisperOutput::encode_server(encoder, params, ctx);
228+
WhisperStreamOutput::encode_server(encoder, params, ctx);
229229
}
230230

231-
void WhisperOutput::transcription_to_json(std::ostream &os) const {
231+
void WhisperStreamOutput::transcription_to_json(std::ostream &os) const {
232232
WhisperEncoderJSON encoder(os);
233233
encode_transcription(encoder);
234234
}

stream_components_output.h

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
#include "stream_components_params.h"
88

99
/**
10-
* Classes that support componentization of the server.
11-
* These classes support encoding the server state and the transcription
10+
* Classes that support componentization of the service.
11+
* These classes support encoding the service state and the transcription
1212
* into JSON (and in the future, into other formats such as msgpack,
1313
* flexbuffers, etc.)
1414
*/
@@ -73,26 +73,26 @@ namespace stream_components {
7373
void doindent();
7474
};
7575

76-
class WhisperOutput {
76+
class WhisperStreamOutput {
7777
public:
78-
WhisperOutput(
78+
WhisperStreamOutput(
7979
struct whisper_context *ctx,
80-
const server_params &params);
80+
const service_params &params);
8181

82-
static void encode_server(WhisperEncoder &encoder, const server_params &params, struct whisper_context *ctx);
82+
static void encode_server(WhisperEncoder &encoder, const service_params &params, struct whisper_context *ctx);
8383

8484
void encode_transcription(WhisperEncoder &encoder) const;
8585

86-
static void server_to_json(std::ostream &os, const server_params &params, struct whisper_context *ctx);
86+
static void to_json(std::ostream &os, const service_params &params, struct whisper_context *ctx);
8787

8888
void transcription_to_json(std::ostream &os) const;
8989

9090
protected:
9191
struct whisper_context *ctx;
92-
const server_params params;
92+
const service_params params;
9393
};
9494

95-
using WhisperOutputPtr = std::shared_ptr<WhisperOutput>;
95+
using WhisperOutputPtr = std::shared_ptr<WhisperStreamOutput>;
9696

9797
} // namespace stream_components
9898

stream_components_params.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace stream_components {
3535
}
3636
};
3737

38-
struct server_params {
38+
struct service_params {
3939
int32_t n_threads = std::min(4, (int32_t) std::thread::hardware_concurrency());
4040
bool speed_up = false;
4141
bool translate = false;

0 commit comments

Comments
 (0)