fix(all): Translator and spelling and audio.
This commit is contained in:
parent
6bad713630
commit
2bbbe502e6
6 changed files with 42 additions and 27 deletions
|
@ -1261,7 +1261,14 @@ export class DialogKeywords {
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
// TODO: const translate = user ? user.basicOptions.translatorOn : false;
|
// TODO: const translate = user ? user.basicOptions.translatorOn : false;
|
||||||
|
text = await min.conversationalService.translate(
|
||||||
|
min,
|
||||||
|
text,
|
||||||
|
user.locale ? user.locale : min.core.getParam(min.instance, 'Locale',
|
||||||
|
GBConfigService.get('LOCALE'))
|
||||||
|
);
|
||||||
|
GBLog.verbose(`Translated text(playMarkdown): ${text}.`);
|
||||||
|
|
||||||
await min.conversationalService['sendOnConversation'](min, user, text);
|
await min.conversationalService['sendOnConversation'](min, user, text);
|
||||||
}
|
}
|
||||||
return { status: 0 };
|
return { status: 0 };
|
||||||
|
|
|
@ -472,7 +472,7 @@ export class GBConversationalService {
|
||||||
Fs.writeFileSync(src, oggFile.read());
|
Fs.writeFileSync(src, oggFile.read());
|
||||||
|
|
||||||
const makeMp3 = shell([
|
const makeMp3 = shell([
|
||||||
'node_modules/ffmpeg-static/ffmpeg.exe',
|
'node_modules/ffmpeg-static/ffmpeg', // TODO: .exe on MSWin.
|
||||||
'-y',
|
'-y',
|
||||||
'-v',
|
'-v',
|
||||||
'error',
|
'error',
|
||||||
|
@ -985,7 +985,12 @@ export class GBConversationalService {
|
||||||
let results = await fetch(url, options);
|
let results = await fetch(url, options);
|
||||||
results = await results.json();
|
results = await results.json();
|
||||||
|
|
||||||
return results[0].translations[0].text;
|
if (results[0]){
|
||||||
|
return results[0].translations[0].text;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
return text;
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const msg = `Error calling MSFT Translator service layer. Error is: ${error}.`;
|
const msg = `Error calling MSFT Translator service layer. Error is: ${error}.`;
|
||||||
|
|
||||||
|
@ -1082,8 +1087,8 @@ export class GBConversationalService {
|
||||||
'Language Detector',
|
'Language Detector',
|
||||||
false) != false;
|
false) != false;
|
||||||
|
|
||||||
locale = user.locale;
|
|
||||||
if (text != '' && detectLanguage && !locale) {
|
if (text != '' && detectLanguage) {
|
||||||
locale = await min.conversationalService.getLanguage(min, text);
|
locale = await min.conversationalService.getLanguage(min, text);
|
||||||
if (user.locale != locale) {
|
if (user.locale != locale) {
|
||||||
|
|
||||||
|
@ -1095,12 +1100,7 @@ export class GBConversationalService {
|
||||||
// Translates text into content language, keeping
|
// Translates text into content language, keeping
|
||||||
// reserved tokens specified in Config.
|
// reserved tokens specified in Config.
|
||||||
|
|
||||||
const contentLocale = min.core.getParam(
|
text = await min.conversationalService.translate(min, text, locale);
|
||||||
min.instance,
|
|
||||||
'Default Content Language',
|
|
||||||
GBConfigService.get('DEFAULT_CONTENT_LANGUAGE')
|
|
||||||
);
|
|
||||||
text = await min.conversationalService.translate(min, text, contentLocale);
|
|
||||||
GBLog.verbose(`Translated text (processMessageActivity): ${text}.`);
|
GBLog.verbose(`Translated text (processMessageActivity): ${text}.`);
|
||||||
|
|
||||||
// Restores all token text back after spell checking and translation.
|
// Restores all token text back after spell checking and translation.
|
||||||
|
|
|
@ -700,7 +700,7 @@ ENDPOINT_UPDATE=true
|
||||||
value = instance['dataValues'][name];
|
value = instance['dataValues'][name];
|
||||||
if (value === null) {
|
if (value === null) {
|
||||||
const minBoot = GBServer.globals.minBoot as any;
|
const minBoot = GBServer.globals.minBoot as any;
|
||||||
params = GBUtil.caseInsensitive(minBoot.instance);
|
params = GBUtil.caseInsensitive(minBoot.instance.dataValues);
|
||||||
value = params[name];
|
value = params[name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -106,11 +106,10 @@ export class AskDialog extends IGBDialog {
|
||||||
text = Messages[locale].ask_first_time;
|
text = Messages[locale].ask_first_time;
|
||||||
} else if (step.options && step.options.isReturning && !step.context.activity.group) {
|
} else if (step.options && step.options.isReturning && !step.context.activity.group) {
|
||||||
const askForMore = min.core.getParam(min.instance, 'Ask For More', null);
|
const askForMore = min.core.getParam(min.instance, 'Ask For More', null);
|
||||||
if (askForMore){
|
if (askForMore) {
|
||||||
text = askForMore ;
|
text = askForMore;
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
|
|
||||||
return await step.endDialog(null);
|
return await step.endDialog(null);
|
||||||
}
|
}
|
||||||
|
@ -340,7 +339,7 @@ export class AskDialog extends IGBDialog {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static async handleAnswer(service: KBService, min: GBMinInstance, step: any, user, answer: GuaribasAnswer) {
|
private static async handleAnswer(service: KBService, min: GBMinInstance, step: any, user, answer: GuaribasAnswer) {
|
||||||
const text = typeof(answer)==='string'? answer:answer.content;
|
let text = typeof (answer) === 'string' ? answer : answer.content;
|
||||||
if (text.endsWith('.docx')) {
|
if (text.endsWith('.docx')) {
|
||||||
const mainName = GBVMService.getMethodNameFromVBSFilename(text);
|
const mainName = GBVMService.getMethodNameFromVBSFilename(text);
|
||||||
await step.endDialog();
|
await step.endDialog();
|
||||||
|
@ -348,7 +347,7 @@ export class AskDialog extends IGBDialog {
|
||||||
} else if (text.startsWith('/')) {
|
} else if (text.startsWith('/')) {
|
||||||
return await step.replaceDialog(text, { answer: answer });
|
return await step.replaceDialog(text, { answer: answer });
|
||||||
} else {
|
} else {
|
||||||
await service.sendAnswer(min, AskDialog.getChannel(step), step, answer);
|
await service.sendAnswer(min, AskDialog.getChannel(step), step, text);
|
||||||
return await step.replaceDialog('/ask', { isReturning: true });
|
return await step.replaceDialog('/ask', { isReturning: true });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -285,6 +285,20 @@ export class KBService implements IGBKBService {
|
||||||
|
|
||||||
const instance = min.instance;
|
const instance = min.instance;
|
||||||
|
|
||||||
|
const contentLocale = min.core.getParam<string>(
|
||||||
|
min.instance,
|
||||||
|
'Default Content Language',
|
||||||
|
GBConfigService.get('DEFAULT_CONTENT_LANGUAGE')
|
||||||
|
);
|
||||||
|
|
||||||
|
query = await min.conversationalService.translate(
|
||||||
|
min,
|
||||||
|
query,
|
||||||
|
contentLocale
|
||||||
|
);
|
||||||
|
|
||||||
|
GBLog.info(`Translated query (prompt): ${query}.`);
|
||||||
|
|
||||||
// Try simple search first.
|
// Try simple search first.
|
||||||
|
|
||||||
const data = await this.getAnswerByText(instance.instanceId, query.trim());
|
const data = await this.getAnswerByText(instance.instanceId, query.trim());
|
||||||
|
@ -639,6 +653,7 @@ export class KBService implements IGBKBService {
|
||||||
} else if (answer.endsWith('.ogg') && process.env.AUDIO_DISABLED !== 'true') {
|
} else if (answer.endsWith('.ogg') && process.env.AUDIO_DISABLED !== 'true') {
|
||||||
await this.playAudio(min, answer, channel, step, min.conversationalService);
|
await this.playAudio(min, answer, channel, step, min.conversationalService);
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
await min.conversationalService.sendText(min, step, answer);
|
await min.conversationalService.sendText(min, step, answer);
|
||||||
await min.conversationalService.sendEvent(min, step, 'stop', undefined);
|
await min.conversationalService.sendEvent(min, step, 'stop', undefined);
|
||||||
}
|
}
|
||||||
|
|
|
@ -482,16 +482,10 @@ export class WhatsappDirectLine extends GBService {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (message.type === 'ptt') {
|
if (message.type === 'ptt') {
|
||||||
let url = provider ? message.body : message.text;
|
|
||||||
if (process.env.AUDIO_DISABLED !== 'true') {
|
if (process.env.AUDIO_DISABLED !== 'true') {
|
||||||
const options = {
|
const media = await message.downloadMedia();
|
||||||
url: url,
|
const buf = Buffer.from(media.data, 'base64');
|
||||||
method: 'GET',
|
|
||||||
encoding: 'binary'
|
|
||||||
};
|
|
||||||
|
|
||||||
const res = await fetch(url, options);
|
|
||||||
const buf = Buffer.from(await res.arrayBuffer());
|
|
||||||
text = await GBConversationalService.getTextFromAudioBuffer(
|
text = await GBConversationalService.getTextFromAudioBuffer(
|
||||||
this.min.instance.speechKey,
|
this.min.instance.speechKey,
|
||||||
this.min.instance.cloudLocation,
|
this.min.instance.cloudLocation,
|
||||||
|
|
Loading…
Add table
Reference in a new issue