Skip to content

Commit

Permalink
Add speaker C demo
Browse files Browse the repository at this point in the history
  • Loading branch information
nshmyrev committed Aug 14, 2020
1 parent 6ef9d13 commit de94ef5
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
5 changes: 5 additions & 0 deletions c/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,14 @@ LIBS= \
$(KALDI_ROOT)/tools/openfst/lib/libfst.a \
$(KALDI_ROOT)/tools/openfst/lib/libfstngram.a

all: test_vosk test_vosk_speaker

test_vosk: test_vosk.o libvosk.a
g++ $^ -o $@ $(LIBS) -lgfortran -lpthread

test_vosk_speaker: test_vosk_speaker.o libvosk.a
g++ $^ -o $@ $(LIBS) -lgfortran -lpthread

libvosk.a: $(VOSK_SOURCES:.cc=.o)
ar rcs $@ $^

Expand Down
30 changes: 30 additions & 0 deletions c/test_vosk_speaker.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include <vosk_api.h>
#include <stdio.h>

int main() {
FILE *wavin;
char buf[3200];
int nread, final;

VoskModel *model = vosk_model_new("model");
VoskSpkModel *spk_model = vosk_spk_model_new("spk-model");
VoskRecognizer *recognizer = vosk_recognizer_new_spk(model, spk_model, 16000.0);

wavin = fopen("test.wav", "rb");
fseek(wavin, 44, SEEK_SET);
while (!feof(wavin)) {
nread = fread(buf, 1, sizeof(buf), wavin);
final = vosk_recognizer_accept_waveform(recognizer, buf, nread);
if (final) {
printf("%s\n", vosk_recognizer_result(recognizer));
} else {
printf("%s\n", vosk_recognizer_partial_result(recognizer));
}
}
printf("%s\n", vosk_recognizer_final_result(recognizer));

vosk_recognizer_free(recognizer);
vosk_spk_model_free(spk_model);
vosk_model_free(model);
return 0;
}

0 comments on commit de94ef5

Please sign in to comment.