-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathmain.c
More file actions
65 lines (54 loc) · 1.82 KB
/
Copy pathmain.c
File metadata and controls
65 lines (54 loc) · 1.82 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* Pure C99 usage of parakeet.cpp via the C FFI
*
* Usage: example-c-api <model.safetensors> <vocab.txt> <audio.wav>
*/
#include <parakeet/api/parakeet_c.h>
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
if (argc != 4) {
fprintf(stderr,
"Usage: %s <model.safetensors> <vocab.txt> <audio.wav>\n",
argv[0]);
return 1;
}
const char *weights = argv[1];
const char *vocab = argv[2];
const char *audio_path = argv[3];
printf("parakeet.cpp %s (C API)\n\n", parakeet_version());
/* Create transcriber */
parakeet_transcriber_t t =
parakeet_transcriber_create(weights, vocab, NULL);
if (!t) {
fprintf(stderr, "Error creating transcriber: %s\n",
parakeet_last_error());
return 1;
}
/* Basic transcription */
parakeet_result_t r =
parakeet_transcriber_transcribe_file(t, audio_path, NULL);
if (!r) {
fprintf(stderr, "Error transcribing: %s\n", parakeet_last_error());
parakeet_transcriber_free(t);
return 1;
}
printf("Text: %s\n\n", parakeet_result_text(r));
parakeet_result_free(r);
/* Transcribe with timestamps */
parakeet_options_t opts = parakeet_options_create();
parakeet_options_set_timestamps(opts, 1);
r = parakeet_transcriber_transcribe_file(t, audio_path, opts);
if (r) {
printf("Word timestamps:\n");
size_t n = parakeet_result_word_count(r);
for (size_t i = 0; i < n; i++) {
parakeet_word_timestamp_t w = parakeet_result_word_at(r, i);
printf(" [%.2fs - %.2fs] (%.2f) %s\n", w.start, w.end,
w.confidence, w.word);
}
parakeet_result_free(r);
}
parakeet_options_free(opts);
parakeet_transcriber_free(t);
return 0;
}