-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathmain.cpp
More file actions
40 lines (32 loc) · 1.3 KB
/
Copy pathmain.cpp
File metadata and controls
40 lines (32 loc) · 1.3 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
39
40
// Streaming transcription with EOU (end-of-utterance) model
//
// Usage: example-stream <model.safetensors> <vocab.txt> <audio.wav>
//
// Simulates streaming by feeding the audio in fixed-size chunks.
#include <parakeet/parakeet.hpp>
#include <iostream>
int main(int argc, char *argv[]) {
if (argc != 4) {
std::cerr << "Usage: " << argv[0]
<< " <model.safetensors> <vocab.txt> <audio.wav>\n"
<< " Requires an EOU-120M model.\n";
return 1;
}
auto config = parakeet::make_eou_120m_config();
parakeet::StreamingTranscriber t(argv[1], argv[2], config);
auto audio = parakeet::read_audio(argv[3]);
const float *data = audio.samples.typed_data<float>();
int64_t total = audio.samples.shape()[0];
int64_t chunk_size = 8000; // 0.5s at 16kHz
std::cout << "Streaming " << (total / 16000.0) << "s of audio in "
<< chunk_size / 16000.0 << "s chunks...\n\n";
for (int64_t offset = 0; offset < total; offset += chunk_size) {
int64_t n = std::min(chunk_size, total - offset);
auto text = t.transcribe_chunk(data + offset, static_cast<size_t>(n));
if (!text.empty()) {
std::cout << text << std::flush;
}
}
std::cout << "\n\nFinal: " << t.get_text() << std::endl;
return 0;
}