From d400541f365dd79fe9fcc65ef157c99153b9f939 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Fri, 15 Dec 2023 15:33:34 +0800 Subject: [PATCH] Keep multiple threads from calling into espeak-ng at the same time --- sherpa-onnx/csrc/piper-phonemize-lexicon.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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;