diff --git a/bin/bst-launch.ts b/bin/bst-launch.ts index b4a644ef..84fcea08 100644 --- a/bin/bst-launch.ts +++ b/bin/bst-launch.ts @@ -52,7 +52,7 @@ program const speaker = new BSTVirtualAlexa(url, interactionModel, intentSchemaPath, samplesPath, applicationID, locale); try { - speaker.start(); + speaker.start(true); } catch (error) { process.exit(0); return; diff --git a/lib/client/bst-virtual-alexa.ts b/lib/client/bst-virtual-alexa.ts index df296d3e..e7885489 100644 --- a/lib/client/bst-virtual-alexa.ts +++ b/lib/client/bst-virtual-alexa.ts @@ -16,6 +16,7 @@ export class BSTVirtualAlexa { public static DefaultIntentSchemaLocation = "speechAssets/IntentSchema.json"; public static DefaultSampleUtterancesLocation = "speechAssets/SampleUtterances.txt"; public static DefaultInteractionModelLocation = "models/en-US.json"; + static DefaultInteractionModel = { interactionModel: { languageModel: { invocationName: "", intents: [] }}}; private virtualAlexa: VirtualAlexa = null; private interactionModelProvided: boolean = false; @@ -132,7 +133,7 @@ export class BSTVirtualAlexa { } } - private validateFilesAndBuild(): VirtualAlexa { + private validateFilesAndBuild(createdEmptyInteractionModelIfNeeded: boolean): VirtualAlexa { const builder = VirtualAlexa.Builder().applicationID(this.applicationID).skillURL(this.skillURL); let usingInteractionModel = false; @@ -144,11 +145,12 @@ export class BSTVirtualAlexa { } } + if (!(this.interactionModelProvided || this.intentSchemaProvided)) { // No model provided, we check if default files exists if (fs.existsSync(this.interactionModel)) { usingInteractionModel = true; - } else if (!(fs.existsSync(this.intentSchemaFile) && fs.existsSync(this.sampleUtterancesFile))) { + } else if (!(fs.existsSync(this.intentSchemaFile) && fs.existsSync(this.sampleUtterancesFile)) && !createdEmptyInteractionModelIfNeeded) { // Model don't exist in default locations console.error("Error loading Interaction model, no file provided and none found in default locations"); throw new Error("Error loading Interaction model, no file provided and none found in default locations"); @@ -173,19 +175,20 @@ export class BSTVirtualAlexa { if (usingInteractionModel) { this.validateJsonFiles(this.interactionModel, BSTVirtualAlexa.FileTypes.InterationModel); builder.interactionModelFile(this.interactionModel); + } else if (createdEmptyInteractionModelIfNeeded) { + builder.interactionModel(BSTVirtualAlexa.DefaultInteractionModel); } else { this.validateJsonFiles(this.intentSchemaFile, BSTVirtualAlexa.FileTypes.IntentSchema); builder.intentSchemaFile(this.intentSchemaFile).sampleUtterancesFile(this.sampleUtterancesFile); } - return builder.create(); } /** * Start the emulator */ - public start(): void { - this.virtualAlexa = this.validateFilesAndBuild(); + public start(createdEmptyInteractionModelIfNeeded?: boolean): void { + this.virtualAlexa = this.validateFilesAndBuild(createdEmptyInteractionModelIfNeeded); } /** diff --git a/test/client/bst-virtual-alexa-test.ts b/test/client/bst-virtual-alexa-test.ts index ea8c25ac..863a7db8 100644 --- a/test/client/bst-virtual-alexa-test.ts +++ b/test/client/bst-virtual-alexa-test.ts @@ -92,6 +92,14 @@ describe("BSTVirtualAlexa", async function() { process.chdir("../.."); }); + it("Start with defaults and non english model", function () { + process.chdir("test/resources/nonUSModel"); + const speak = new BSTVirtualAlexa("http://localhost:9000"); + speak.start(true); + assert(true, "Start processed without exceptions"); + process.chdir("../../.."); + }); + it("Use provided models even when default is present in folder", function () { process.chdir("test/resources/allSpeechModels"); const speak = new BSTVirtualAlexa("http://localhost:9000",