Skip to main content

Sherpa TTS Node

SherpaTTS node is responsible for converting text into natural-sounding speech using advanced text-to-speech algorithms.


Configuration​

text (Optional)​

Type: String

Initial text to synthesize.


Properties​

Inherits properties from its parent, SingleBusAudioSourceNode.


Actions​

Inherits actions from its parent, SingleBusAudioSourceNode.

loadModel​

Loads a Sherpa model from the provided paths.

Parameters​

NameTypeDescription
modelPathStringPath to the sherpa model file.
tokensPathStringPath to the sherpa tokens.
dataPathStringPath to the sherpa data folder.

Return Value​

None.

synthesize​

Queues the text for rendering and returns immediately. The node renders on its own thread, emits synthesisStarted when rendering begins and finished when playback of the result ends, so calling synthesize from an event handler (for example a finished → counter → synthesize loop) never blocks the audio thread.

Parameters​

NameTypeDescription
textStringThe text to synthesize.

Return Value​

None.


Events​

Inherits events from its parent, SingleBusAudioSourceNode.


Example

This example generates speech audio and renders it in real-time on the device's speaker.

{
"type": "Realtime",
"config": {
"graph": {
"config": {
"sampleRate": 16000,
"bufferSize": 512
},
"nodes": [
{
"id": "ttsNode",
"type": "Sherpa.TTS"
},
{
"id": "monoToMultiChannelNode",
"type": "MonoToMultiChannel"
}
],
"connections": [
{
"sourceNode": "ttsNode",
"destinationNode": "monoToMultiChannelNode"
},
{
"sourceNode": "monoToMultiChannelNode",
"destinationNode": "outputNode"
}
]
}
}
}

To generate speech with the TTS node, call the synthesize action and provide the desired text as a parameter.

auto result = Switchboard::callAction("ttsNode", "synthesize", { { "text", text } });