快速开始 — Linux

speech-coreexamples/linux/ 下为嵌入式 Linux 平台(汽车、Yocto、边缘设备)提供了一个 C API。与驱动 Android 的是同一个 C++ 流水线引擎,目标平台为 ARM64 和 x86_64。ONNX Runtime 由 setup 脚本自动获取。

环境要求

配置

git clone https://github.com/soniqo/speech-core.git
cd speech-core
./examples/linux/setup_linux.sh

cmake -B build \
    -DCMAKE_BUILD_TYPE=Release \
    -DSPEECH_CORE_WITH_ONNX=ON \
    -DSPEECH_CORE_BUILD_EXAMPLES=ON \
    -DORT_DIR=ort-linux
cmake --build build

# 可选 — 使用真实模型运行集成测试
scripts/download_models.sh
SPEECH_MODEL_DIR=scripts/models ctest --test-dir build --output-on-failure

C API 示例

#include <speech.h>

void on_event(const speech_event_t* event, void* ctx) {
    if (event->type == SPEECH_EVENT_TRANSCRIPTION)
        printf("%s\n", event->text);
}

speech_config_t cfg = speech_config_default();
cfg.model_dir = "/opt/speech/models";
speech_pipeline_t p = speech_create(cfg, on_event, NULL);
speech_start(p);
speech_push_audio(p, samples, 512);
重要

进行 Yocto 交叉编译时,将 ORT_DIR 设置为 sysroot 中的 ONNX Runtime 安装路径,并使用相应的 CMake toolchain 文件。

源码:github.com/soniqo/speech-core/tree/main/examples/linux

下一步