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