Skip to content

Commit 1223b5b

Browse files
authored
Merge pull request #148 from githubnemo/feature/token-bytes
Implement `whisper_token_to_bytes`
2 parents 50461e3 + 82c8ab7 commit 1223b5b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

src/main.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ const char * whisper_token_to_str_wrapper(struct whisper_context_wrapper * ctx_w
133133
return whisper_token_to_str(ctx_w->ptr, token);
134134
};
135135

136+
py::bytes whisper_token_to_bytes_wrapper(struct whisper_context_wrapper * ctx_w, whisper_token token){
137+
const char* str = whisper_token_to_str(ctx_w->ptr, token);
138+
size_t l = strlen(str);
139+
return py::bytes(str, l);
140+
}
141+
136142
whisper_token whisper_token_eot_wrapper(struct whisper_context_wrapper * ctx_w){
137143
return whisper_token_eot(ctx_w->ptr);
138144
}
@@ -494,6 +500,7 @@ PYBIND11_MODULE(_pywhispercpp, m) {
494500

495501

496502
m.def("whisper_token_to_str", &whisper_token_to_str_wrapper, "whisper_token_to_str");
503+
m.def("whisper_token_to_bytes", &whisper_token_to_bytes_wrapper, "whisper_token_to_bytes");
497504
m.def("whisper_token_eot", &whisper_token_eot_wrapper, "whisper_token_eot");
498505
m.def("whisper_token_sot", &whisper_token_sot_wrapper, "whisper_token_sot");
499506
m.def("whisper_token_prev", &whisper_token_prev_wrapper);

0 commit comments

Comments
 (0)