// // Copyright © 2020 Arm Ltd and Contributors. All rights reserved. // SPDX-License-Identifier: MIT // #pragma once #include "ArmnnNetworkExecutor.hpp" #include "Decoder.hpp" #include "MFCC.hpp" #include "DsCNNPreprocessor.hpp" namespace kws { /** * Generic Keyword Spotting pipeline with 3 steps: data pre-processing, inference execution and inference * result post-processing. * */ class KWSPipeline { public: /** * Creates speech recognition pipeline with given network executor and decoder. * @param executor - unique pointer to inference runner * @param decoder - unique pointer to inference results decoder */ KWSPipeline(std::unique_ptr> executor, std::unique_ptr decoder, std::unique_ptr preProcessor); /** * @brief Standard audio pre-processing implementation. * * Preprocesses and prepares the data for inference by * extracting the MFCC features. * @param[in] audio - the raw audio data */ std::vector PreProcessing(std::vector& audio); /** * @brief Executes inference * * Calls inference runner provided during instance construction. * * @param[in] preprocessedData - input inference data. Data type should be aligned with input tensor. * @param[out] result - raw inference results. */ void Inference(const std::vector& preprocessedData, common::InferenceResults& result); /** * @brief Standard inference results post-processing implementation. * * Decodes inference results using decoder provided during construction. * * @param[in] inferenceResult - inference results to be decoded. * @param[in] labels - the words we use for the model */ void PostProcessing(common::InferenceResults& inferenceResults, std::map& labels, const std::function& callback); /** * @brief Get the number of samples for the pipeline input * @return - number of samples for the pipeline */ int getInputSamplesSize(); protected: std::unique_ptr> m_executor; std::unique_ptr m_decoder; std::unique_ptr m_preProcessor; }; using IPipelinePtr = std::unique_ptr; /** * Constructs speech recognition pipeline based on configuration provided. * * @param[in] config - speech recognition pipeline configuration. * @param[in] labels - asr labels * * @return unique pointer to asr pipeline. */ IPipelinePtr CreatePipeline(common::PipelineOptions& config); };// namespace kws