whisper-feature.h (2046B)
1 /** 2 * Copyright (c) 2023 Xiaomi Corporation (authors: Fangjun Kuang) 3 * 4 * See LICENSE for clarification regarding multiple authors 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 #ifndef KALDI_NATIVE_FBANK_CSRC_WHISPER_FEATURE_H_ 20 #define KALDI_NATIVE_FBANK_CSRC_WHISPER_FEATURE_H_ 21 22 #include <cstdint> 23 #include <memory> 24 #include <vector> 25 26 #include "kaldi-native-fbank/csrc/feature-window.h" 27 #include "kaldi-native-fbank/csrc/mel-computations.h" 28 29 namespace knf { 30 31 struct WhisperFeatureOptions { 32 WhisperFeatureOptions(const FrameExtractionOptions &frame_opts = {}, 33 int32_t dim = 80) 34 : frame_opts(frame_opts), dim(dim) {} 35 36 FrameExtractionOptions frame_opts; 37 int32_t dim = 80; 38 39 std::string ToString() const; 40 }; 41 42 class WhisperFeatureComputer { 43 public: 44 // note: opts.frame_opts is ignored and we reset it inside 45 explicit WhisperFeatureComputer(const WhisperFeatureOptions &opts = {}); 46 47 int32_t Dim() const { return opts_.dim; } 48 49 const FrameExtractionOptions &GetFrameOptions() const { 50 return opts_.frame_opts; 51 } 52 53 void Compute(float /*signal_raw_log_energy*/, float /*vtln_warp*/, 54 std::vector<float> *signal_frame, float *feature); 55 56 // if true, compute log_energy_pre_window but after dithering and dc removal 57 bool NeedRawLogEnergy() const { return false; } 58 59 using Options = WhisperFeatureOptions; 60 61 private: 62 std::unique_ptr<MelBanks> mel_banks_; 63 WhisperFeatureOptions opts_; 64 }; 65 66 } // namespace knf 67 68 #endif // KALDI_NATIVE_FBANK_CSRC_WHISPER_FEATURE_H_