Views
No views yet
1import soundfile as sf
2
3from txtai.pipeline import TextToSpeech
4
5# Build pipeline
6tts = TextToSpeech("NeuML/ljspeech-vits-onnx")
7
8# Generate speech
9speech, rate = tts("Say something here")
10
11# Write to file
12sf.write("out.wav", speech, rate)1import onnxruntime
2import soundfile as sf
3import yaml
4
5from ttstokenizer import TTSTokenizer
6
7# This example assumes the files have been downloaded locally
8with open("ljspeech-vits-onnx/config.yaml", "r", encoding="utf-8") as f:
9 config = yaml.safe_load(f)
10
11# Create model
12model = onnxruntime.InferenceSession(
13 "ljspeech-vits-onnx/model.onnx",
14 providers=["CPUExecutionProvider"]
15)
16
17# Create tokenizer
18tokenizer = TTSTokenizer(config["token"]["list"])
19
20# Tokenize inputs
21inputs = tokenizer("Say something here")
22
23# Generate speech
24outputs = model.run(None, {"text": inputs})
25
26# Write to file
27sf.write("out.wav", outputs[0], 22050)