Skip to content

Commit

Permalink
Fix ffmpeg c api example (#1185)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj authored Jul 29, 2024
1 parent 646f99c commit b1711ec
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 12 deletions.
18 changes: 18 additions & 0 deletions .github/workflows/c-api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ on:
- 'sherpa-onnx/csrc/*'
- 'sherpa-onnx/c-api/*'
- 'c-api-examples/**'
- 'ffmpeg-examples/**'
pull_request:
branches:
- master
Expand All @@ -23,6 +24,7 @@ on:
- 'sherpa-onnx/csrc/*'
- 'sherpa-onnx/c-api/*'
- 'c-api-examples/**'
- 'ffmpeg-examples/**'

workflow_dispatch:

Expand Down Expand Up @@ -81,6 +83,22 @@ jobs:
otool -L ./install/lib/libsherpa-onnx-c-api.dylib
fi
- name: Test ffmpeg
if: matrix.os == 'macos-latest'
shell: bash
run: |
brew install ffmpeg
cd ffmpeg-examples
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
tar xvf sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
rm sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20.tar.bz2
make
ls -lh
./run.sh
rm -rf sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20
- name: Test sense-voice
shell: bash
run: |
Expand Down
7 changes: 3 additions & 4 deletions ffmpeg-examples/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,18 @@ ifeq ($(GDB), TRUE)
OPTFLAG += -g
endif

# CFLAGS := $(shell pkg-config --cflags $(SHARED_LIBS)) -I.. -Wall -std=c++11 -fopenmp ${OPTFLAG}
CFLAGS := $(shell pkg-config --cflags $(SHARED_LIBS)) -I.. -Wall -std=c++11 ${OPTFLAG}
# CFLAGS := $(shell pkg-config --cflags $(SHARED_LIBS)) -I.. -Wall -std=c++17 -fopenmp ${OPTFLAG}
CFLAGS := $(shell pkg-config --cflags $(SHARED_LIBS)) -I.. -Wall -std=c++17 ${OPTFLAG}
LDLIBS := $(shell pkg-config --libs $(SHARED_LIBS))

CUR_DIR :=$(shell pwd)

LDLIBS += -L ../build/lib
LDLIBS += -L ../build/_deps/onnxruntime-src/lib
LDLIBS += -lsherpa-onnx-c-api -lsherpa-onnx-core -lonnxruntime -lkaldi-native-fbank-core
LDLIBS += -lsherpa-onnx-c-api -lonnxruntime
LDLIBS += -Wl,-rpath,${CUR_DIR}/../build/lib
LDLIBS += -Wl,-rpath,${CUR_DIR}/../build/_deps/onnxruntime-src/lib


#Get libavutil version and extract major, minor and micro
LIBAVUTIL_VERSION := $(shell pkg-config --modversion libavutil)
LIBAVUTIL_MAJOR := $(shell echo "$(LIBAVUTIL_VERSION)" | awk -F. '{print $$1}')
Expand Down
2 changes: 1 addition & 1 deletion ffmpeg-examples/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,4 @@ echo "Decoding a URL"
./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/encoder-epoch-99-avg-1.onnx \
./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/decoder-epoch-99-avg-1.onnx \
./sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/joiner-epoch-99-avg-1.onnx \
https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/resolve/main/test_wavs/4.wav
https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-bilingual-zh-en-2023-02-20/resolve/main/test_wavs/3.wav
15 changes: 8 additions & 7 deletions ffmpeg-examples/sherpa-onnx-ffmpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ static int init_filters(const char *filters_descr) {
static void sherpa_decode_frame(const AVFrame *frame,
SherpaOnnxOnlineRecognizer *recognizer,
SherpaOnnxOnlineStream *stream,
SherpaOnnxDisplay *display,
const SherpaOnnxDisplay *display,
int32_t *segment_id) {
#define N 3200 // 100s. Sample rate is fixed to 16 kHz
static float samples[N];
Expand All @@ -229,7 +229,7 @@ static void sherpa_decode_frame(const AVFrame *frame,
SherpaOnnxDecodeOnlineStream(recognizer, stream);
}

SherpaOnnxOnlineRecognizerResult *r =
const SherpaOnnxOnlineRecognizerResult *r =
SherpaOnnxGetOnlineStreamResult(recognizer, stream);
if (strlen(r->text)) {
SherpaOnnxPrint(display, *segment_id, r->text);
Expand Down Expand Up @@ -290,10 +290,11 @@ int main(int argc, char **argv) {
}

SherpaOnnxOnlineRecognizerConfig config;
memset(&config, 0, sizeof(config));
config.model_config.tokens = argv[1];
config.model_config.encoder = argv[2];
config.model_config.decoder = argv[3];
config.model_config.joiner = argv[4];
config.model_config.transducer.encoder = argv[2];
config.model_config.transducer.decoder = argv[3];
config.model_config.transducer.joiner = argv[4];

if (argc == 7 && atoi(argv[6]) > 0) {
num_threads = atoi(argv[6]);
Expand All @@ -320,7 +321,7 @@ int main(int argc, char **argv) {
SherpaOnnxOnlineRecognizer *recognizer =
SherpaOnnxCreateOnlineRecognizer(&config);
SherpaOnnxOnlineStream *stream = SherpaOnnxCreateOnlineStream(recognizer);
SherpaOnnxDisplay *display = SherpaOnnxCreateDisplay(50);
const SherpaOnnxDisplay *display = SherpaOnnxCreateDisplay(50);
int32_t segment_id = 0;

if ((ret = open_input_file(argv[5])) < 0) exit(1);
Expand Down Expand Up @@ -383,7 +384,7 @@ int main(int argc, char **argv) {
SherpaOnnxDecodeOnlineStream(recognizer, stream);
}

SherpaOnnxOnlineRecognizerResult *r =
const SherpaOnnxOnlineRecognizerResult *r =
SherpaOnnxGetOnlineStreamResult(recognizer, stream);
if (strlen(r->text)) {
SherpaOnnxPrint(display, segment_id, r->text);
Expand Down

0 comments on commit b1711ec

Please sign in to comment.