#pragma once #include "engine/framework/core/execution_context.h" #include "engine/framework/runtime/session.h" #include "engine/community_models/parakeet_tdt/assets.h" #include "engine/community_models/parakeet_tdt/encoder.h" #include "engine/community_models/parakeet_tdt/weights.h" #include "engine/community_models/parakeet_tdt/hotwords.h" #include #include #include #include #include #include namespace engine::community_models::parakeet_tdt { struct ParakeetDecodeOptions { int64_t max_tokens = 0; bool keep_language_tags = false; int64_t audio_end_sample = -1; std::shared_ptr hotwords; }; struct ParakeetDecodedText { std::string text; std::vector token_ids; std::vector token_frame_indices; std::vector durations; std::vector word_timestamps; }; class ParakeetTDTDecoderRuntime { public: ParakeetTDTDecoderRuntime( std::shared_ptr assets, std::shared_ptr weights, engine::core::ExecutionContext & execution_context, size_t graph_arena_bytes); ~ParakeetTDTDecoderRuntime(); void prepare(); ParakeetDecodedText decode( const ParakeetEncodedAudio & encoded, const ParakeetDecodeOptions & options); void reset_state(); ParakeetDecodedText decode_incremental( const ParakeetEncodedAudio & encoded, const ParakeetDecodeOptions & options, int64_t frame_offset = 0); ParakeetDecodedText format_tokens( std::vector token_ids, std::vector token_frame_indices, std::vector durations, const ParakeetDecodeOptions & options, int64_t audio_end_frame) const; int32_t run_step(int32_t input_token, const float * encoder_frame, bool decoder_cache_valid, int32_t * out_dur_id = nullptr); int32_t run_joint_step(const float * encoder_frame, int32_t * out_dur_id = nullptr); private: struct StepGraph; struct JointGraph; std::shared_ptr assets_; std::shared_ptr weights_; engine::core::ExecutionContext * execution_context_ = nullptr; size_t graph_arena_bytes_ = 0; std::array state_widths_{}; std::unique_ptr step_graph_; std::unique_ptr joint_graph_; std::vector logits_scratch_; std::vector hidden_scratch_; std::vector cell_scratch_; std::vector decoder_cache_scratch_; std::vector hidden_read_scratch_; std::vector cell_read_scratch_; int32_t pending_input_token_ = 0; bool predictor_cache_valid_ = false; bool state_initialized_ = false; std::shared_ptr hotwords_; int32_t hotword_state_ = 0; int32_t select_token(); void ensure_step_graph(); void ensure_joint_graph(); std::string decode_text(const std::vector & token_ids, bool keep_language_tags) const; std::vector build_word_timestamps( const std::vector & token_ids, const std::vector & token_frame_indices, const std::vector & durations, int64_t audio_end_frame, int64_t audio_end_sample) const; }; } // namespace engine::community_models::parakeet_tdt