$reactions.ttsWithVariables
The method configures the audio and text template to use for speech synthesis with variables via Yandex SpeechKit Brand Voice Adaptive.
Syntax
The method accepts an object containing the audioTemplate and textTemplate properties.
audioTemplate
audioTemplate describes the audio where the variable part should be inserted. It contains three properties:
audio— the template audio URL.
-
textTemplatedescribes the audio transcription:templateis the template text, with variable parts replaced with variable names in curly braces.textVariablesis an array of objects describing each variable used. Every object contains two properties:nameis the variable name.valueis the transcription of the audio segment replaced with the variable.
-
audioVariablesis an array of objects describing the placement of variables in the recording. Every object contains three properties:nameis the variable name.startMsis the time from the audio start to the beginning of the variable part, in milliseconds.lengthMsis the length of the variable part playback, in milliseconds.
textTemplate
textTemplate describes the text to be synthesized by the bot. It contains two properties:
templateis the template text, with variable parts replaced with variable names in curly braces.textVariablesis an array of objects describing the variables to be inserted into the template. Every object contains two properties:nameis the variable name.valueis the text to be synthesized.
audioTemplate and textTemplate follows the specification of AudioTemplate and TextTemplate
as described in the Yandex SpeechKit documentation.How to use
This is an example call to the method from the script:
$reactions.ttsWithVariables({
"audioTemplate": {
"audio": "https://mybucket.s3-ap-southeast-1.amazonaws.com/myfilename.wav",
"textTemplate": {
"template": "You have been approved a loan of {limit} dollars. Would you like to proceed?",
"textVariables": [
{
"name": "limit",
"value": "thirty two thousand"
}
]
},
"audioVariables": [
{
"name": "limit",
"startMs": 1850,
"lengthMs": 1400
}
]
},
"textTemplate": {
"template": "You have been approved a loan of {limit} dollars. Would you like to proceed?",
"textVariables": [
{
"name": "limit",
"value": "sixty seven thousand"
}
]
}
});
The audio file for this example has thirty two thousand mentioned as the loan amount.
audioTemplate specifies the audio file URL and the variable placement in the recording.
textTemplate describes the phrase synthesized by the bot in the state where this method is called.
Here, the limit variable will be replaced with sixty seven thousand.
In a real script, the actual variable values will be different based on the dialog context.