模型:
NeuML/ljspeech-jets-onnx
imdanboy/jets 以ONNX格式导出。该模型是使用 espnet_onnx 库的ONNX导出。
txtai具有内置的文本转语音(TTS)流程,使用此模型非常简单。
import soundfile as sf
from txtai.pipeline import TextToSpeech
# Build pipeline
tts = TextToSpeech("NeuML/ljspeech-jets-onnx")
# Generate speech
speech = tts("Say something here")
# Write to file
sf.write("out.wav", speech, 22050)
对于ONNX,可以直接运行此模型,前提是输入文本已被分词。分词可以使用 ttstokenizer 完成。
请注意,txtai流程还具有其他功能,例如批处理大型输入,这些功能需要使用此方法复制。
import onnxruntime
import soundfile as sf
import yaml
from ttstokenizer import TTSTokenizer
# This example assumes the files have been downloaded locally
with open("ljspeech-jets-onnx/config.yaml", "r", encoding="utf-8") as f:
config = yaml.safe_load(f)
# Create model
model = onnxruntime.InferenceSession(
"ljspeech-jets-onnx/model.onnx",
providers=["CPUExecutionProvider"]
)
# Create tokenizer
tokenizer = TTSTokenizer(config["token"]["list"])
# Tokenize inputs
inputs = tokenizer("Say something here")
# Generate speech
outputs = model.run(None, {"text": inputs})
# Write to file
sf.write("out.wav", outputs[0], 22050)
如何将ESPnet模型导出到ONNX的更多信息可以在此处找到。