#pragma once #include "engine/community_models/kroko_asr/assets.h" #include #include #include #include namespace engine::models::kroko_asr { struct KrokoDecodedTokens { std::vector ids; std::vector frame_indices; }; enum class KrokoDecodingMethod { GreedySearch, ModifiedBeamSearch, }; struct KrokoDecoderOptions { KrokoDecodingMethod method = KrokoDecodingMethod::GreedySearch; int32_t max_active_paths = 4; float blank_penalty = 0.0F; float hotwords_score = 1.5F; std::vector> hotwords; }; class KrokoTransducerDecoder { public: explicit KrokoTransducerDecoder(std::shared_ptr assets); ~KrokoTransducerDecoder(); void configure(KrokoDecoderOptions options); void reset(int64_t frame_offset = 0); void reset_segment(int64_t frame_offset); const KrokoDecodedTokens & append( const std::vector & encoder_output, int64_t frames, int64_t hidden_size); const KrokoDecodedTokens & decoded() const noexcept; int64_t decoded_frames() const noexcept; int64_t trailing_blank_frames() const noexcept; KrokoDecodedTokens decode( const std::vector & encoder_output, int64_t frames, int64_t hidden_size); private: struct Impl; std::array predictor(const std::array & context) const; void join_scores( const float * encoder_frame, const std::array & decoder_output, std::vector & scores) const; void append_greedy( const std::vector & encoder_output, int64_t frames, int64_t hidden_size); void append_modified_beam( const std::vector & encoder_output, int64_t frames, int64_t hidden_size); std::shared_ptr assets_; std::vector embedding_; std::vector conv_; std::vector decoder_projection_; std::vector decoder_bias_; std::vector joiner_projection_; std::vector joiner_bias_; mutable std::vector joiner_scores_; std::array context_{}; std::array decoder_output_{}; KrokoDecodedTokens decoded_; int64_t decoded_frames_ = 0; int64_t trailing_blank_frames_ = 0; KrokoDecoderOptions options_; std::unique_ptr impl_; }; } // namespace engine::models::kroko_asr