Skip to content

Commit

Permalink
Merge pull request #251 from Microsoft/eanders-MS
Browse files Browse the repository at this point in the history
Add speech support
  • Loading branch information
eanders-ms committed Jul 20, 2017
2 parents a3c8642 + 745dbe9 commit 4923221
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ThirdPartyLicenses.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
botframework-emulator@3.5.31-alpha (MIT)
botframework-emulator@3.5.31 (MIT)

Copyright (c) Microsoft Corporation

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "botframework-emulator",
"version": "3.5.31-alpha",
"version": "3.5.31",
"description": "Emulator for the Microsoft Bot Framework. Allows developers to test and debug their bots on localhost.",
"main": "./app/server/main.js",
"scripts": {
Expand Down
41 changes: 40 additions & 1 deletion src/client/mainView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ import * as Constants from './constants';
import { Emulator } from './emulator';
import { BotEmulatorContext } from './botEmulatorContext';
import { AddressBarOperators } from './addressBar/addressBarOperators';
import * as log from './log';
import { ISpeechTokenInfo } from '../types/speechTypes';

const CognitiveServices = require('../../node_modules/botframework-webchat/CognitiveServices');
const remote = require('electron').remote;
const ipcRenderer = require('electron').ipcRenderer;

Expand Down Expand Up @@ -248,7 +251,14 @@ export class MainView extends React.Component<{}, {}> {
selectedActivity: selectedActivity$() as any,
user: this.getCurrentUser(settings.serverSettings),
bot: { name: "Bot", id: activeBot.botId },
resize: 'detect'
resize: 'detect',
speechOptions: {
speechRecognizer: new CognitiveServices.SpeechRecognizer({
fetchCallback: this.fetchSpeechToken.bind(this),
fetchOnExpiryCallback: this.fetchSpeechTokenOnExpiry.bind(this)
}),
speechSynthesizer: new BotChat.Speech.BrowserSpeechSynthesizer()
}
}
InspectorActions.clear();
return <div className="wc-app" ref={ref => this.initBotChatContainerRef(ref, initialWidth)}><BotChat.Chat key={this.reuseKey} {...props} /></div>
Expand All @@ -261,6 +271,35 @@ export class MainView extends React.Component<{}, {}> {
}
}

private fetchSpeechToken(authIdEvent: string): Promise<string> {
return this.getSpeechToken(authIdEvent, false);
}

private fetchSpeechTokenOnExpiry(authIdEvent: string): Promise<string> {
return this.getSpeechToken(authIdEvent, true);
}

private getSpeechToken(authIdEvent: string, refresh: boolean = false): Promise<string> {
return new Promise<string>((resolve, reject) => {
let message = refresh ? 'refreshSpeechToken' : 'getSpeechToken';
// Electron 1.7.2 @types incorrectly specifies sendSync having a void return type, so cast result to `any`.
let speechToken = ipcRenderer.sendSync(message, this.conversationId) as any as ISpeechTokenInfo;
if (speechToken) {
if (speechToken.access_Token) {
resolve(speechToken.access_Token);
return;
} else {
log.warn('Could not retrieve Cognitive Services speech token');
log.warn('Error: ' + speechToken.error);
log.warn('Details: ' + speechToken.error_Description);
}
} else {
log.error('Could not retrieve Cognitive Services speech token.');
}
resolve();
});
}

render() {
const settings = getSettings();
let vertSplit = settings.layout.vertSplit;
Expand Down
4 changes: 3 additions & 1 deletion src/server/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ const createMainWindow = () => {
width: initBounds.width,
height: initBounds.height,
x: initBounds.x,
y: initBounds.y,
y: initBounds.y
});
mainWindow.setTitle(windowTitle);
windowManager = new WindowManager();
Expand Down Expand Up @@ -229,6 +229,7 @@ Electron.app.on('window-all-closed', function () {
Electron.app.quit();
}
});

Electron.app.on('activate', function () {
if (mainWindow === null) {
createMainWindow();
Expand All @@ -237,3 +238,4 @@ Electron.app.on('activate', function () {

// Do this last, otherwise startup bugs are harder to diagnose.
require('electron-debug')();

0 comments on commit 4923221

Please sign in to comment.