diff --git a/sherpa-onnx/csrc/piper-phonemize-lexicon.cc b/sherpa-onnx/csrc/piper-phonemize-lexicon.cc index 476e872d5..e63352043 100644 --- a/sherpa-onnx/csrc/piper-phonemize-lexicon.cc +++ b/sherpa-onnx/csrc/piper-phonemize-lexicon.cc @@ -223,7 +223,14 @@ std::vector> PiperPhonemizeLexicon::ConvertTextToTokenIds( config.voice = voice; // e.g., voice is en-us std::vector> phonemes; - piper::phonemize_eSpeak(text, config, phonemes); + + static std::mutex espeak_mutex; + { + std::lock_guard lock(espeak_mutex); + + // keep multi threads from calling into piper::phonemize_eSpeak + piper::phonemize_eSpeak(text, config, phonemes); + } std::vector> ans;