Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions tools/omnivoice/tests/ffi-parakeet-asr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,19 @@ int main() {
CHECK(count_words(fin) + 3 >= count_words(text) && count_words(fin) <= count_words(text) + 3,
"concurrent stream word count %zu far from batch %zu", count_words(fin), count_words(text));
std::printf("concurrent feed/partial: %d polls, %zu words\n", polls, count_words(fin));
// a tiny buffer: truncated, NUL-terminated, length < capacity
// Insufficient output space must not return a successful prefix.
char tiny[5];
rc = eliza_inference_asr_stream_partial(cs, tiny, sizeof(tiny), nullptr, nullptr, &err);
CHECK(rc >= 0 && rc < (int) sizeof(tiny) && tiny[rc] == '\0', "tiny buffer rc %d", rc);
CHECK(rc < 0, "tiny partial buffer must fail, got %d", rc);
eliza_inference_free_string(err);
err = nullptr;
rc = eliza_inference_asr_stream_finish(cs, tiny, sizeof(tiny), nullptr, nullptr, &err);
CHECK(rc < 0, "tiny final buffer must fail, got %d", rc);
eliza_inference_free_string(err);
err = nullptr;
char retry[4096];
rc = eliza_inference_asr_stream_finish(cs, retry, sizeof(retry), nullptr, nullptr, &err);
CHECK(rc > 0 && std::strcmp(fin, retry) == 0, "retry after small buffer lost transcript");
eliza_inference_asr_stream_close(cs);
}
}
Expand Down
3 changes: 2 additions & 1 deletion tools/parakeet/include/parakeet.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,8 @@ pk_stream * pk_stream_open(pk_model * model, pk_stream_params params);
int pk_stream_feed(pk_stream * st, const float * pcm16k, size_t n_samples);
/* Decode if at least min_hop_ms of new audio arrived since the last decode,
* then write committed + tentative text. Returns bytes written (excluding
* NUL) or a negative pk_status. */
* NUL) or a negative pk_status. An insufficient output buffer returns
* PK_E_INVALID without partial text; retry with more space. */
int pk_stream_partial(pk_stream * st, char * out, size_t cap, pk_cancel_cb cancel, void * cancel_user);
/* Decode the remaining audio with full right context and write the final
* transcript. */
Expand Down
13 changes: 6 additions & 7 deletions tools/parakeet/src/pk-stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -345,14 +345,13 @@ static int write_text(pk_stream * s, char * out, size_t cap) {
all.insert(all.end(), s->tentative.begin(), s->tentative.end());
const std::string t = detokenize(s->m, all.data(), all.size());
if (!out || cap == 0) return (int) t.size();
size_t n = std::min(t.size(), cap - 1);
// never cut a UTF-8 sequence: back off over continuation bytes
if (n < t.size()) {
while (n > 0 && ((unsigned char) t[n] & 0xC0) == 0x80) --n;
if (t.size() >= cap) {
out[0] = '\0';
return PK_E_INVALID;
}
std::memcpy(out, t.data(), n);
out[n] = '\0';
return (int) n;
std::memcpy(out, t.data(), t.size());
out[t.size()] = '\0';
return (int) t.size();
}

extern "C" int pk_stream_partial(pk_stream * s, char * out, size_t cap, pk_cancel_cb cancel, void * cu) {
Expand Down
Loading