Skip to content

Commit

Permalink
Use Speech Services token for speech UI sample (microsoft#1634)
Browse files Browse the repository at this point in the history
* Use Speech Services token

* Add entry

* Clean up
  • Loading branch information
compulim committed Jan 24, 2019
1 parent 2bc6744 commit 31803fb
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
- `component`: [Password input activity](https://microsoft.github.io/BotFramework-WebChat/10.b.customization-password-input/), in [#1569](https://github.com/Microsoft/BotFramework-WebChat/pull/1569)
- `*`: Updated [minimizable Web Chat](https://microsoft.github.io/BotFramework-WebChat/12.customization-minimizable-web-chat/) sample to use `WEB_CHAT/SEND_EVENT` action, in [#1631](https://github.com/Microsoft/BotFramework-WebChat/pull/1631)
- `component`: [Hybrid speech engine](https://microsoft.github.io/BotFramework-WebChat/06.f.hybrid-speech/), in [#1617](https://github.com/Microsoft/BotFramework-WebChat/pull/1617)
- `component`: Use Speech Services token for [speech UI sample](https://microsoft.github.io/BotFramework-WebChat/13.customization-speech-ui/), in [#1634](https://github.com/Microsoft/BotFramework-WebChat/pull/1634)

## [4.2.0] - 2018-12-11
### Added
Expand Down
6 changes: 3 additions & 3 deletions samples/06.b.cognitive-services-bing-speech-react/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
const { render } = window.ReactDOM;
const {
Context,
createCognitiveServicesWebSpeechPonyfillFactory,
createCognitiveServicesBingSpeechPonyfillFactory,
createDirectLine,
ReactWebChat
} = window.WebChat;
Expand All @@ -55,12 +55,12 @@
if (subscriptionKey) {
// In case you are using your own subscription key, please note that client should always authenticate against your server
// to avoid exposing the subscription key to any part of your client code.
webSpeechPonyfillFactory = await window.WebChat.createCognitiveServicesBingSpeechPonyfillFactory({ subscriptionKey });
webSpeechPonyfillFactory = await createCognitiveServicesBingSpeechPonyfillFactory({ subscriptionKey });
} else {
const res = await fetch('https://webchat-mockbot.azurewebsites.net/bingspeech/token', { method: 'POST' });
const { token: authorizationToken } = await res.json();

webSpeechPonyfillFactory = await window.WebChat.createCognitiveServicesBingSpeechPonyfillFactory({ authorizationToken });
webSpeechPonyfillFactory = await createCognitiveServicesBingSpeechPonyfillFactory({ authorizationToken });
}

// Pass a Web Speech ponyfill factory to renderWebChat.
Expand Down
10 changes: 7 additions & 3 deletions samples/13.customization-speech-ui/src/App.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import './App.css';
import { Components, createDirectLine, createCognitiveServicesWebSpeechPonyfillFactory } from 'botframework-webchat';
import { Components, createDirectLine, createCognitiveServicesSpeechServicesPonyfillFactory } from 'botframework-webchat';
import React, { Component } from 'react';

import CustomDictationInterims from './CustomDictationInterims';
import CustomMicrophoneButton from './CustomMicrophoneButton';
import fetchBingSpeechToken from './fetchBingSpeechToken';
import fetchSpeechServicesToken from './fetchSpeechServicesToken';
import LastBotActivity from './LastBotActivity';

const { Composer } = Components;
Expand All @@ -25,7 +25,11 @@ export default class App extends Component {
this.setState(() => ({
directLine: createDirectLine({
token,
webSpeechPonyfillFactory: createCognitiveServicesWebSpeechPonyfillFactory(fetchBingSpeechToken)
webSpeechPonyfillFactory: createCognitiveServicesSpeechServicesPonyfillFactory({
// TODO: [P3] Fetch token should be able to return different region
region: 'westus',
token: fetchSpeechServicesToken
})
})
}));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default function () {
const now = Date.now();

if (!fetchPromise || (now - lastFetch) > RENEW_EVERY) {
fetchPromise = fetch('https://webchat-mockbot.azurewebsites.net/bingspeech/token', { method: 'POST' })
fetchPromise = fetch('https://webchat-mockbot.azurewebsites.net/speechservices/token', { method: 'POST' })
.then(res => res.json())
.then(({ token }) => token)
.catch(() => { lastFetch = 0; });
Expand Down

0 comments on commit 31803fb

Please sign in to comment.