NEW: Added STT and TTS capabilities to default.gbui.
This commit is contained in:
parent
c4f767156b
commit
0955599855
5 changed files with 75 additions and 16 deletions
|
@ -1,5 +1,9 @@
|
|||
# Release History
|
||||
|
||||
## Version 0.0.29
|
||||
|
||||
- NEW: Added STT and TTS capabilities to default.gbui.
|
||||
|
||||
## Version 0.0.28
|
||||
|
||||
- FIX: gbui packages updated.
|
||||
|
|
|
@ -101,6 +101,8 @@ export class GuaribasInstance extends Model<GuaribasInstance> implements IGBInst
|
|||
|
||||
@Column whatsappServiceWebhookUrl: string;
|
||||
|
||||
@Column speechKey: string;
|
||||
|
||||
@Column spellcheckerKey: string;
|
||||
|
||||
@Column theme: string;
|
||||
|
|
|
@ -131,15 +131,29 @@ export class GBMinService {
|
|||
botId,
|
||||
(instance: IGBInstance, err) => {
|
||||
if (instance) {
|
||||
res.send(
|
||||
JSON.stringify({
|
||||
instanceId: instance.instanceId,
|
||||
botId: botId,
|
||||
theme: instance.theme,
|
||||
secret: instance.webchatKey, // TODO: Use token.
|
||||
conversationId: responseObject.conversationId
|
||||
})
|
||||
);
|
||||
|
||||
let options = {
|
||||
url:
|
||||
"https://api.cognitive.microsoft.com/sts/v1.0/issueToken",
|
||||
method: "POST",
|
||||
headers: {
|
||||
"Ocp-Apim-Subscription-Key": instance.speechKey
|
||||
}
|
||||
};
|
||||
request(options).then((response:
|
||||
string) => {
|
||||
|
||||
res.send(
|
||||
JSON.stringify({
|
||||
instanceId: instance.instanceId,
|
||||
botId: botId,
|
||||
theme: instance.theme,
|
||||
secret: instance.webchatKey, // TODO: Use token.
|
||||
speechToken: response,
|
||||
conversationId: responseObject.conversationId
|
||||
})
|
||||
);
|
||||
});
|
||||
} else {
|
||||
let error = `Instance not found: ${botId}.`;
|
||||
res.send(error);
|
||||
|
|
|
@ -39,7 +39,12 @@ import SidebarMenu from "./components/SidebarMenu.js";
|
|||
import GBCss from "./components/GBCss.js";
|
||||
import { DirectLine } from "botframework-directlinejs";
|
||||
import { ConnectionStatus } from "botframework-directlinejs";
|
||||
import { SpeechRecognizer } from "botframework-webchat/CognitiveServices";
|
||||
import { SpeechSynthesizer } from "botframework-webchat/CognitiveServices";
|
||||
import { SynthesisGender } from "botframework-webchat/CognitiveServices";
|
||||
import { Chat } from "botframework-webchat";
|
||||
import { BotChat } from "botframework-webchat";
|
||||
import { Speech } from "botframework-webchat/botchat";
|
||||
import GBPowerBIPlayer from "./players/GBPowerBIPlayer.js";
|
||||
|
||||
class GBUIApp extends React.Component {
|
||||
|
@ -49,7 +54,8 @@ class GBUIApp extends React.Component {
|
|||
this.state = {
|
||||
botConnection: null,
|
||||
instance: null,
|
||||
token: null
|
||||
token: null,
|
||||
instanceClient: null
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -97,7 +103,8 @@ class GBUIApp extends React.Component {
|
|||
.then(res => res.json())
|
||||
.then(
|
||||
result => {
|
||||
this.setupBotConnection(result.secret);
|
||||
this.setState({instanceClient:result});
|
||||
this.setupBotConnection();
|
||||
},
|
||||
error => {
|
||||
this.setState({
|
||||
|
@ -108,12 +115,12 @@ class GBUIApp extends React.Component {
|
|||
);
|
||||
}
|
||||
|
||||
setupBotConnection(secret) {
|
||||
setupBotConnection() {
|
||||
let _this_ = this;
|
||||
window["botchatDebug"] = true;
|
||||
|
||||
const botConnection = new DirectLine({
|
||||
secret: secret
|
||||
secret: this.state.instanceClient.secret
|
||||
});
|
||||
|
||||
botConnection.connectionStatus$.subscribe(connectionStatus => {
|
||||
|
@ -224,25 +231,57 @@ class GBUIApp extends React.Component {
|
|||
);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
let speechOptions;
|
||||
|
||||
let sideBar = (
|
||||
<div className="sidebar">
|
||||
<SidebarMenu chat={this.chat} instance={this.state.instance} />
|
||||
</div>
|
||||
);
|
||||
|
||||
if (this.state.botConnection) {
|
||||
|
||||
if (this.state.botConnection && this.state.instance) {
|
||||
let token = this.state.instanceClient.speechToken;
|
||||
|
||||
function getToken() {
|
||||
return new Promise((resolve, reject) => {
|
||||
resolve(token);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
speechOptions = {
|
||||
speechRecognizer: new SpeechRecognizer({
|
||||
locale: "pt-br",
|
||||
fetchCallback: (authFetchEventId) => getToken(),
|
||||
fetchOnExpiryCallback: (authFetchEventId) => getToken()
|
||||
}),
|
||||
speechSynthesizer: new SpeechSynthesizer({
|
||||
fetchCallback: (authFetchEventId) => getToken(),
|
||||
fetchOnExpiryCallback: (authFetchEventId) => getToken(),
|
||||
gender: SynthesisGender.Male,
|
||||
voiceName: 'Microsoft Server Speech Text to Speech Voice (pt-BR, Daniel, Apollo)'
|
||||
})
|
||||
};
|
||||
|
||||
chat = (
|
||||
<Chat
|
||||
ref={chat => {
|
||||
this.chat = chat;
|
||||
}}
|
||||
locale={'pt-br'}
|
||||
botConnection={this.state.botConnection}
|
||||
user={this.getUser()}
|
||||
bot={{ id: "bot@gb", name: "Bot" }}
|
||||
speechOptions={speechOptions}
|
||||
/>
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
if (!this.state.instance) {
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "botserver",
|
||||
"version": "0.0.28",
|
||||
"version": "0.0.29",
|
||||
"description": "General Bot Community Edition open-core server.",
|
||||
"main": "./src/app.ts",
|
||||
"homepage": "http://www.generalbot.com",
|
||||
|
@ -33,7 +33,7 @@
|
|||
"async": "^2.6.1",
|
||||
"body-parser": "^1.18.3",
|
||||
"botbuilder": "^3.15.0",
|
||||
"botlib": "^0.0.25",
|
||||
"botlib": "^0.0.28",
|
||||
"chokidar": "^2.0.3",
|
||||
"csv-parse": "^2.4.0",
|
||||
"dotenv-extended": "^2.0.2",
|
||||
|
|
Loading…
Add table
Reference in a new issue