Last active
June 3, 2025 18:46
-
-
Save pdaug/56b2d172484cf7e3edfbde4a8c8b34b5 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require(Modules.Avatar); | |
VoxEngine.addEventListener(AppEvents.Started, function () { | |
const data = JSON.parse(VoxEngine.customData() || "{}"); | |
const call = VoxEngine.callPSTN(data.leadPhone, data.userPhone); | |
const language = VoiceList.Microsoft.Neural?.[data?.voice]; | |
// Ligação conectada | |
call.addEventListener(CallEvents.Connected, function (event) { | |
Logger.write("call connected"); | |
if (data?.avatarId) { | |
const avatarConfig = { | |
avatarId: "8dfffadf-93b7-4cf9-8a1a-568d53ba1b87", | |
extended: false, | |
}; | |
const asrParameters = { | |
model: ASRModelList.Google, | |
profile: ASRProfileList.Google.pt_PT, | |
phraseHints: [], | |
singleUtterance: true, | |
interimResults: true, | |
}; | |
const ttsPlayerOptions = { language }; | |
const voiceAvatar = VoximplantAvatar.createVoiceAvatar({ | |
call, | |
asrEndOfPhraseDetectorTimeout: 1000, | |
onErrorCallback: function () { | |
Logger.write("ERROR!"); | |
call.hangup(); | |
}, | |
onFinishCallback: function (ev) { | |
Logger.write(ev); | |
call.hangup(); | |
}, | |
avatarConfig, | |
asrParameters, | |
ttsPlayerOptions, | |
}); | |
return; | |
} | |
if (data?.text) { | |
event.call.startEarlyMedia(); | |
event.call.say(data.text, language); | |
event.call.addEventListener(CallEvents.PlaybackFinished, function () { | |
VoxEngine.terminate(); | |
return; | |
}); | |
return; | |
} | |
VoxEngine.terminate(); | |
return; | |
}); | |
// Ligação desconectada | |
call.addEventListener(CallEvents.Disconnected, function () { | |
Logger.write("call disconnected"); | |
VoxEngine.terminate(); | |
return; | |
}); | |
// Ligação falhou | |
call.addEventListener(CallEvents.Failed, function () { | |
Logger.write("call failed"); | |
VoxEngine.terminate(); | |
return; | |
}); | |
}); | |
VoxEngine.addEventListener(AppEvents.CallAlerting, function (event) { }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment