Skip to content

Commit

Permalink
Support reading FST from stream in text normalizer (#57)
Browse files Browse the repository at this point in the history
  • Loading branch information
csukuangfj committed Nov 5, 2023
1 parent 1270c62 commit ed4259c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
9 changes: 9 additions & 0 deletions kaldifst/csrc/text-normalizer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,15 @@ TextNormalizer::TextNormalizer(const std::string &rule) {
CastOrConvertToConstFst(fst::ReadFstKaldiGeneric(rule)));
}

TextNormalizer::TextNormalizer(std::istream &is) {
fst::StdVectorFst *fst = new fst::StdVectorFst;
bool binary = true;
ReadFstKaldi(is, binary, fst);

// fst is released inside CastOrConvertToConstFst()
rule_ = std::unique_ptr<fst::StdConstFst>(CastOrConvertToConstFst(fst));
}

TextNormalizer::TextNormalizer(std::unique_ptr<fst::StdConstFst> rule)
: rule_(std::move(rule)) {}

Expand Down
1 change: 1 addition & 0 deletions kaldifst/csrc/text-normalizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class TextNormalizer {
public:
// Path to rule.fst
explicit TextNormalizer(const std::string &rule);
explicit TextNormalizer(std::istream &is);

explicit TextNormalizer(std::unique_ptr<fst::StdConstFst> rule);

Expand Down

0 comments on commit ed4259c

Please sign in to comment.