This repository has been archived on 2025-08-26. You can view files and clone it, but cannot push or open issues or pull requests.
Files
enginex-mr_series-sherpa-onnx/sherpa-onnx/csrc/features.h

71 lines
1.9 KiB
C
Raw Normal View History

2023-02-19 19:36:03 +08:00
// sherpa-onnx/csrc/features.h
2023-02-18 21:35:15 +08:00
//
// Copyright (c) 2023 Xiaomi Corporation
#ifndef SHERPA_ONNX_CSRC_FEATURES_H_
#define SHERPA_ONNX_CSRC_FEATURES_H_
#include <memory>
2023-02-19 12:45:38 +08:00
#include <string>
2023-02-18 21:35:15 +08:00
#include <vector>
namespace sherpa_onnx {
2023-02-19 10:39:07 +08:00
struct FeatureExtractorConfig {
2023-02-19 11:42:15 +08:00
float sampling_rate = 16000;
2023-02-19 10:39:07 +08:00
int32_t feature_dim = 80;
2023-02-19 12:45:38 +08:00
std::string ToString() const;
2023-02-19 10:39:07 +08:00
};
2023-02-18 21:35:15 +08:00
class FeatureExtractor {
public:
2023-02-19 10:39:07 +08:00
explicit FeatureExtractor(const FeatureExtractorConfig &config = {});
2023-02-19 09:57:56 +08:00
~FeatureExtractor();
2023-02-18 21:35:15 +08:00
/**
@param sampling_rate The sampling_rate of the input waveform. Should match
the one expected by the feature extractor.
@param waveform Pointer to a 1-D array of size n
@param n Number of entries in waveform
*/
void AcceptWaveform(float sampling_rate, const float *waveform, int32_t n);
2023-02-19 11:42:15 +08:00
/**
* InputFinished() tells the class you won't be providing any
* more waveform. This will help flush out the last frame or two
* of features, in the case where snip-edges == false; it also
* affects the return value of IsLastFrame().
*/
2023-02-18 21:35:15 +08:00
void InputFinished();
int32_t NumFramesReady() const;
2023-02-19 11:42:15 +08:00
/** Note: IsLastFrame() will only ever return true if you have called
* InputFinished() (and this frame is the last frame).
*/
2023-02-18 21:35:15 +08:00
bool IsLastFrame(int32_t frame) const;
/** Get n frames starting from the given frame index.
*
* @param frame_index The starting frame index
* @param n Number of frames to get.
* @return Return a 2-D tensor of shape (n, feature_dim).
* which is flattened into a 1-D vector (flattened in in row major)
*/
std::vector<float> GetFrames(int32_t frame_index, int32_t n) const;
void Reset();
2023-02-19 09:57:56 +08:00
/// Return feature dim of this extractor
int32_t FeatureDim() const;
2023-02-18 21:35:15 +08:00
private:
2023-02-19 09:57:56 +08:00
class Impl;
std::unique_ptr<Impl> impl_;
2023-02-18 21:35:15 +08:00
};
} // namespace sherpa_onnx
#endif // SHERPA_ONNX_CSRC_FEATURES_H_