Permalink
Browse files

Add speech support

  • Loading branch information...
eanders-MS committed Jul 20, 2017
1 parent a3c8642 commit 745dbe988cd6c2a739c526eccbdde932a43dedae
Showing with 45 additions and 4 deletions.
  1. +1 −1 ThirdPartyLicenses.txt
  2. +1 −1 package.json
  3. +40 −1 src/client/mainView.tsx
  4. +3 −1 src/server/main.ts
View
@@ -1,4 +1,4 @@
botframework-emulator@3.5.31-alpha (MIT)
botframework-emulator@3.5.31 (MIT)
Copyright (c) Microsoft Corporation
View
@@ -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": {
View
@@ -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;
@@ -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>
@@ -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;
View
@@ -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();
@@ -229,6 +229,7 @@ Electron.app.on('window-all-closed', function () {
Electron.app.quit();
}
});
Electron.app.on('activate', function () {
if (mainWindow === null) {
createMainWindow();
@@ -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 745dbe9

Please sign in to comment.