Use piper-phonemize to convert text to token IDs (#453)
This commit is contained in:
41
sherpa-onnx/csrc/piper-phonemize-lexicon.h
Normal file
41
sherpa-onnx/csrc/piper-phonemize-lexicon.h
Normal file
@@ -0,0 +1,41 @@
|
||||
// sherpa-onnx/csrc/piper-phonemize-lexicon.h
|
||||
//
|
||||
// Copyright (c) 2022-2023 Xiaomi Corporation
|
||||
|
||||
#ifndef SHERPA_ONNX_CSRC_PIPER_PHONEMIZE_LEXICON_H_
|
||||
#define SHERPA_ONNX_CSRC_PIPER_PHONEMIZE_LEXICON_H_
|
||||
|
||||
#include <string>
|
||||
#include <unordered_map>
|
||||
#include <vector>
|
||||
|
||||
#if __ANDROID_API__ >= 9
|
||||
#include "android/asset_manager.h"
|
||||
#include "android/asset_manager_jni.h"
|
||||
#endif
|
||||
|
||||
#include "sherpa-onnx/csrc/offline-tts-frontend.h"
|
||||
|
||||
namespace sherpa_onnx {
|
||||
|
||||
class PiperPhonemizeLexicon : public OfflineTtsFrontend {
|
||||
public:
|
||||
PiperPhonemizeLexicon(const std::string &tokens, const std::string &data_dir);
|
||||
|
||||
#if __ANDROID_API__ >= 9
|
||||
PiperPhonemizeLexicon(AAssetManager *mgr, const std::string &tokens,
|
||||
const std::string &data_dir);
|
||||
#endif
|
||||
|
||||
std::vector<std::vector<int64_t>> ConvertTextToTokenIds(
|
||||
const std::string &text, const std::string &voice = "") const override;
|
||||
|
||||
private:
|
||||
std::string data_dir_;
|
||||
// map unicode codepoint to an integer ID
|
||||
std::unordered_map<char32_t, int32_t> token2id_;
|
||||
};
|
||||
|
||||
} // namespace sherpa_onnx
|
||||
|
||||
#endif // SHERPA_ONNX_CSRC_PIPER_PHONEMIZE_LEXICON_H_
|
||||
Reference in New Issue
Block a user