Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Merge f4593ec into 28c9d38
Browse files Browse the repository at this point in the history
  • Loading branch information
ecruzado committed May 17, 2018
2 parents 28c9d38 + f4593ec commit 94f56a7
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
6 changes: 5 additions & 1 deletion bin/bst-speak.ts
Expand Up @@ -18,6 +18,8 @@ Global.initializeCLI().then(
\thttps://${Global.SpokesDashboardHost}/skills/${Global.config().sourceID()}/validation
\t(Bespoken Dashboard account required for use of this feature)\n`)
.option("-l, --locale <locale>", "The locale to use for the virtual device (en-US, en-GB, de-DE, etc.)")
.option("-v, --voiceID <voiceID>", "The AWS Polly voice ID to use for generating speech")
.description("Speaks to your virtual Alexa device")
.action(async function () {
// To handle utterances with multiple words, we need to look at the args
Expand All @@ -37,10 +39,12 @@ Global.initializeCLI().then(
// Just by casting program to options, we can get all the options which are set on it
const options: any = program;
const token = options.token;
const locale = options.locale;
const voiceID = options.voiceID;

let virtualDeviceResponse;
try {
virtualDeviceResponse = await VirtualDeviceClient.speak(utterance, token);
virtualDeviceResponse = await VirtualDeviceClient.speak(utterance, token, locale, voiceID);
} catch (error) {
if (error.message === "Token Required") {
console.log("You need a token for this option to work, get it here:");
Expand Down
4 changes: 2 additions & 2 deletions lib/external/virtual-device.ts
Expand Up @@ -2,7 +2,7 @@ import {IVirtualDeviceResult, VirtualDevice} from "virtual-device-sdk";
import {Global} from "../core/global";

export class VirtualDeviceClient {
public static speak(utterance: string, token?: string): Promise<IVirtualDeviceResult> {
public static speak(utterance: string, token?: string, locale?: string, voiceID?: string): Promise<IVirtualDeviceResult> {
if (token) {
if (Global.config()) {
Global.config().updateVirtualDeviceToken(token);
Expand All @@ -15,7 +15,7 @@ export class VirtualDeviceClient {
throw new Error("Token Required");
}

const virtualDevice = new VirtualDevice(tokenToUse);
const virtualDevice = new VirtualDevice(tokenToUse, locale, voiceID);
return virtualDevice.message(utterance);
}

Expand Down
43 changes: 43 additions & 0 deletions test/bin/bst-speak-test.ts
Expand Up @@ -159,6 +159,49 @@ describe("bst-speak", function() {
NodeUtil.load("../../bin/bst-speak.js");
});
});

it("Send message with locale and voiceId options", function() {
return new Promise((resolve, reject) => {

process.argv = command("node bst-speak.js --token Token --locale en-AU --voiceID Nicole Hello");
mockery.registerMock("../lib/external/virtual-device", {
VirtualDeviceClient: {
speak: function(utterance: string, token: string, locale?: string, voiceID?: string) {
assert.equal(locale, "en-AU");
assert.equal(voiceID, "Nicole");
return {
transcript: "Response"
};
},
renderResult: function (result: any) {
try {
assert.equal(result.transcript, "Response");
} catch (error) {
reject(error);
}
return "Response Rendered";
},
}
});

let flagResponse = false;
let flagToken = false;
sandbox.stub(console, "log", function(data: Buffer) {
if (data !== undefined && data.includes(tokenWarning)) {
flagToken = true;
}

if (data !== undefined && data.includes("Response Rendered")) {
flagResponse = true;
}

if (flagResponse && flagToken) {
resolve();
}
});
NodeUtil.load("../../bin/bst-speak.js");
});
});
});
});

Expand Down

0 comments on commit 94f56a7

Please sign in to comment.