Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Speech Services token for speech UI sample #1634

Merged
merged 3 commits into from
Jan 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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