You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.2 KiB
74 lines
2.2 KiB
2 years ago
|
// Copyright (c) 2022 PaddlePaddle Authors. All Rights Reserved.
|
||
|
//
|
||
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
||
|
// you may not use this file except in compliance with the License.
|
||
|
// You may obtain a copy of the License at
|
||
|
//
|
||
|
// http://www.apache.org/licenses/LICENSE-2.0
|
||
|
//
|
||
|
// Unless required by applicable law or agreed to in writing, software
|
||
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||
|
// See the License for the specific language governing permissions and
|
||
|
// limitations under the License.
|
||
|
|
||
|
#pragma once
|
||
|
|
||
|
#include "base/common.h"
|
||
2 years ago
|
#include "fst/symbol-table.h"
|
||
2 years ago
|
#include "kaldi/decoder/decodable-itf.h"
|
||
|
|
||
|
namespace ppspeech {
|
||
|
|
||
2 years ago
|
enum SearchType {
|
||
|
kPrefixBeamSearch = 0,
|
||
|
kWfstBeamSearch = 1,
|
||
|
};
|
||
2 years ago
|
class DecoderInterface {
|
||
|
public:
|
||
|
virtual ~DecoderInterface() {}
|
||
|
|
||
|
virtual void InitDecoder() = 0;
|
||
|
|
||
|
virtual void Reset() = 0;
|
||
|
|
||
2 years ago
|
// call AdvanceDecoding
|
||
2 years ago
|
virtual void AdvanceDecode(
|
||
|
const std::shared_ptr<kaldi::DecodableInterface>& decodable) = 0;
|
||
|
|
||
2 years ago
|
// call GetBestPath
|
||
2 years ago
|
virtual std::string GetFinalBestPath() = 0;
|
||
|
|
||
|
virtual std::string GetPartialResult() = 0;
|
||
|
|
||
2 years ago
|
virtual const std::shared_ptr<fst::SymbolTable> WordSymbolTable() const = 0;
|
||
|
virtual void FinalizeSearch() = 0;
|
||
|
|
||
|
virtual const std::vector<std::vector<int>>& Inputs() const = 0;
|
||
|
virtual const std::vector<std::vector<int>>& Outputs() const = 0;
|
||
|
virtual const std::vector<float>& Likelihood() const = 0;
|
||
|
virtual const std::vector<std::vector<int>>& Times() const = 0;
|
||
|
|
||
2 years ago
|
protected:
|
||
|
// virtual void AdvanceDecoding(kaldi::DecodableInterface* decodable) = 0;
|
||
2 years ago
|
|
||
2 years ago
|
// virtual void Decode() = 0;
|
||
2 years ago
|
|
||
2 years ago
|
virtual std::string GetBestPath() = 0;
|
||
2 years ago
|
|
||
2 years ago
|
virtual std::vector<std::pair<double, std::string>> GetNBestPath() = 0;
|
||
2 years ago
|
|
||
2 years ago
|
virtual std::vector<std::pair<double, std::string>> GetNBestPath(int n) = 0;
|
||
2 years ago
|
};
|
||
2 years ago
|
|
||
2 years ago
|
class DecoderBase : public DecoderInterface {
|
||
|
protected:
|
||
2 years ago
|
// start from one
|
||
|
int NumFrameDecoded() { return num_frame_decoded_ + 1; }
|
||
|
|
||
|
protected:
|
||
|
// current decoding frame number, abs_time_step_
|
||
2 years ago
|
int32 num_frame_decoded_;
|
||
|
};
|
||
|
|
||
|
} // namespace ppspeech
|