-
Notifications
You must be signed in to change notification settings - Fork 81
Expand file tree
/
Copy pathtest_capi_batch.cpp
More file actions
38 lines (35 loc) · 1.49 KB
/
Copy pathtest_capi_batch.cpp
File metadata and controls
38 lines (35 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include "model.hpp"
#include "audio_io.hpp"
#include <cstdlib>
#include <cstdio>
#include <string>
#include <vector>
// Batch-API B=1 equivalence smoke test.
//
// Loads the real-speech fixture, transcribes it single-clip, then runs it as a
// 2-clip batch of the same audio. Asserts both batch results equal the single
// result, proving the batch path is byte-identical to the single path. This is
// self-consistency (our own code on both sides), so it only needs
// PARAKEET_TEST_GGUF.
int main() {
const char* gguf = std::getenv("PARAKEET_TEST_GGUF");
if (!gguf) { std::fprintf(stderr, "env not set; skip\n"); return 77; }
auto model = pk::Model::load(gguf);
if (!model) { std::fprintf(stderr, "load failed\n"); return 1; }
pk::Audio audio;
if (!pk::load_audio_16k_mono("tests/fixtures/speech.wav", audio) || audio.samples.empty()) {
std::fprintf(stderr, "wav load failed\n");
return 1;
}
const std::vector<float>& pcm = audio.samples;
std::string single = model->transcribe_pcm(pcm, 16000);
auto batch = model->transcribe_pcm_batch({pcm, pcm}, 16000);
if (batch.size() != 2) { std::fprintf(stderr, "batch size %zu\n", batch.size()); return 1; }
if (batch[0] != single || batch[1] != single) {
std::fprintf(stderr, "MISMATCH single='%s' b0='%s' b1='%s'\n",
single.c_str(), batch[0].c_str(), batch[1].c_str());
return 1;
}
std::fprintf(stderr, "OK batch==single: '%s'\n", single.c_str());
return 0;
}