function talaSpeechSetup(offerId, useGenerativeAi, handler) { return talaSpeechSetupInternal(offerId, "", "", "", "", useGenerativeAi, handler); } function talaSpeechSetupCustomOffer( offerId, offerSerialized, voice, region, useGenerativeAi, handler ) { const locale = JSON.parse(offerSerialized).locale; return talaSpeechSetupInternal( offerId, offerSerialized, locale, voice, region, useGenerativeAi, handler ); } function talaSpeechSetupInternal( offerId, offerSerialized, locale, voice, region, useGenerativeAi, handler ) { try { console.log( `sending SETUP with offerId: "${offerId}" and locale "${locale}"` ); const urlLocale = locale ? locale : "en_US"; var endpoint = useGenerativeAi ? `https://${handler}.azurewebsites.net/interact/${offerId}?locale=${urlLocale}&ndg=unknown&style=a Teacher` : `https://${handler}.azurewebsites.net/interact/${offerId}?non_neural=1&locale=${urlLocale}&ndg=unknown&style=a Teacher`; window.TalaSpeech.send({ type: "SETUP", value: { deviceID: "talaspeech-devcube", // TODO: Should we send locale en_US here? It's en-US further down? Endpoint is probably for GPT generated content? // TODO: Should we send ndg=unknown? // TODO: Should we send style=a Teacher? endpoint: endpoint /** required, */, // This is an example offer id from vlad in Teams // endpoint: "https://production-handler.function.cloud.pratb.art/interact/498541a4-444a-470d-a50f-bf5bcdb0b324?locale=en_US&ndg=unknown&style=a Teacher", /** required, */ // Keys are used to fetch a token that is valid for 10 minutes // This gettoken.php is public and that's not really a good thing // This gettoken.php has the private key (backend on dreamhost) and serves a token // TODO: Implement logic to generate this key from the (new) backend, send the token to the client, use that key azureRegion: region, azureCredentials: region == "northeurope" ? "https://tala.pratb.art/gettoken.php" : "https://tala.pratb.art/gettoken-swedencentral.php" /** required, */, // azureCredentials: "https://backend.talkamatic.se/token/" // Example token JWT: "eyJhbGciOiJFUzI1NiIsImtpZCI6ImtleTEiLCJ0eXAiOiJKV1QifQ.eyJyZWdpb24iOiJub3J0aGV1cm9wZSIsInN1YnNjcmlwdGlvbi1pZCI6IjMzODY3Y2M3ZDNjZTQzYjlhMDQwZGMxNjIxMmEwMjVlIiwicHJvZHVjdC1pZCI6IlNwZWVjaFNlcnZpY2VzLlMwIiwiY29nbml0aXZlLXNlcnZpY2VzLWVuZHBvaW50IjoiaHR0cHM6Ly9hcGkuY29nbml0aXZlLm1pY3Jvc29mdC5jb20vaW50ZXJuYWwvdjEuMC8iLCJhenVyZS1yZXNvdXJjZS1pZCI6Ii9zdWJzY3JpcHRpb25zLzhhY2QxNGZlLWI3YmQtNGRjYi04MWM0LTUzOWI4N2Q3YzQ5YS9yZXNvdXJjZUdyb3Vwcy9UYWxhVFRTL3Byb3ZpZGVycy9NaWNyb3NvZnQuQ29nbml0aXZlU2VydmljZXMvYWNjb3VudHMvVGFsYVRUUzEiLCJzY29wZSI6InNwZWVjaHNlcnZpY2VzIiwiYXVkIjoidXJuOm1zLnNwZWVjaHNlcnZpY2VzLm5vcnRoZXVyb3BlIiwiZXhwIjoxNzEwMjM1ODY0LCJpc3MiOiJ1cm46bXMuY29nbml0aXZlc2VydmljZXMifQ.90Y1GaDTE6pJ_WlHfWncTSfHT-2PjT8vx7-KZCqQ3cit9BkWmjnsCvrb93trkCgZnVWR1F32MJN2pQf2U1rZCQ" // Used for ASR language // TODO: Why does this differ from the endpoint locale above? Should it? Endpoint is probably for GPT generated content locale: locale ? locale.replaceAll("_", "-") : "en-US" /** default */, // TODO: Can we send our json here? // Step 1: AuthoringJson / SanityJson - the simpler version I guess? // Step 2: This is sent to the backend (Azure) and that backend creates an OfferJson - a more complex version // Step 3: When we initiate a dialogue, we have two alternatives: // 3a): Send the offer_id in the URL, the Azure backend will fetch the OfferJson from Sanity Storage // 3b): Send the OfferJson in sessionObjectAdditions // The idea is: // The new authoring tool creates a replica of the SanityJson // The new TalkamaticService (Azure) will send the SanityJson to AzureBackend (POST) and get an OfferJson // The new TalkamaticService will store the OfferJson in a database, together with the SanityJson // The new ConsumerApp will send the OfferJson in the sessionObjectAdditions and the offer_id to the endpoint (production-handler) // "asr_hints": "", // "expected_input": "", // // dme_..., locale, nlg, nlu, odb, odb_metadata... // "offer_id": "${offerID}", // "visual_output": "", // TODO: Send JSON here? // If this JSON has id "foo", should we send /interact/foo in the endpoint above? // DDD = Dialogue Domain Description/Definition // Each grouping is a DDD // TODO: Is the base JSON (offer in fastbuddy) a DDD? sessionObjectAdditions: offerSerialized == "" ? {} : JSON.parse(offerSerialized), asrDefaultCompleteTimeout: 0 /** default */, asrDefaultNoInputTimeout: 5000 /** default */, ttsDefaultVoice: voice, ttsLexicon: locale == "sv_SE" ? "https://cvoiceprodneu.blob.core.windows.net/acc-public-files/33867cc7d3ce43b9a040dc16212a025e/9f6c85e1-4fe9-4268-b337-24015d30b46c.xml" : undefined, azureLanguageCredentials: undefined /** default, not supported by TDM*/, speechRecognitionEndpointId: undefined /** default */, }, }); } catch (error) { return "ERROR talaSpeechSetup"; } } function talaSpeechTurnPage(grouping) { try { // Turn page is actually turn grouping, e.g. "1" window.TalaSpeech.send({ type: "TURN_PAGE", value: grouping }); } catch (error) { return "ERROR talaSpeechTurnPage"; } } function talaSpeechPrepare() { try { window.TalaSpeech.send({ type: "PREPARE" }); } catch (error) { return "ERROR talaSpeechPrepare"; } } function talaSpeechStart() { try { window.TalaSpeech.send({ type: "START" }); } catch (error) { return "ERROR talaSpeechStart"; } } function talaSpeechResume() { try { window.TalaSpeech.send({ type: "CONTROL" }); } catch (error) { return "ERROR talaSpeechResume"; } } function talaSpeechPause() { try { window.TalaSpeech.send({ type: "CONTROL" }); } catch (error) { return "ERROR talaSpeechPause"; } } function talaSpeechStop() { try { window.TalaSpeech.send({ type: "STOP" }); } catch (error) { return "ERROR talaSpeechStop"; } } function talaSpeechSnapshotContext() { try { var jsonResult = window.TalaSpeech.getSnapshot().context; return JSON.stringify(jsonResult); } catch (error) { return JSON.stringify({ message: "ERROR" }); } } function talaSpeechSnapshotContextTdmState() { try { // This will most likely contain the groupings? var jsonResult = window.TalaSpeech.getSnapshot().context.tdmState; return JSON.stringify(jsonResult); } catch (error) { return JSON.stringify({ message: "ERROR" }); } } function talaSpeechSnapshotContextSpeechStateValue() { try { // This generates if it's speaking, listening or idle var jsonResult = window.TalaSpeech.getSnapshot().context.spstRef.getSnapshot().value; return JSON.stringify(jsonResult); } catch (error) { return JSON.stringify({ message: "ERROR" }); } } function talaSpeechSnapshotValue() { try { var jsonResult = window.TalaSpeech.getSnapshot().value; return JSON.stringify(jsonResult); } catch (error) { return JSON.stringify({ message: "ERROR" }); } } function talaSpeechMetaUIValue() { try { var jsonResult = window.TalaSpeechUIState; return JSON.stringify(jsonResult); } catch (error) { return JSON.stringify({ message: "ERROR" }); } } function reloadWindow() { window.location.reload(); } function consoleLog(msg) { window.console.log(msg); } function historyBack() { window.history.back(); }