diff --git a/kaldifst/csrc/text-normalizer.cc b/kaldifst/csrc/text-normalizer.cc index bcbf8ab..8aa3820 100644 --- a/kaldifst/csrc/text-normalizer.cc +++ b/kaldifst/csrc/text-normalizer.cc @@ -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(CastOrConvertToConstFst(fst)); +} + TextNormalizer::TextNormalizer(std::unique_ptr rule) : rule_(std::move(rule)) {} diff --git a/kaldifst/csrc/text-normalizer.h b/kaldifst/csrc/text-normalizer.h index e304a95..f162829 100644 --- a/kaldifst/csrc/text-normalizer.h +++ b/kaldifst/csrc/text-normalizer.h @@ -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 rule);