@memori.ai/memori-api-client 0.11.0 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/README.md +0 -46
- package/dist/backend.d.ts +14 -0
- package/dist/engine.d.ts +48 -10
- package/dist/index.d.ts +62 -18
- package/dist/memori-api-client.cjs.development.js +0 -235
- package/dist/memori-api-client.cjs.development.js.map +1 -1
- package/dist/memori-api-client.cjs.production.min.js +1 -1
- package/dist/memori-api-client.cjs.production.min.js.map +1 -1
- package/dist/memori-api-client.esm.js +0 -235
- package/dist/memori-api-client.esm.js.map +1 -1
- package/package.json +2 -3
- package/src/index.ts +0 -2
- package/dist/speech.d.ts +0 -13
- package/src/speech.ts +0 -243
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
|
|
6
6
|
|
|
7
7
|
var fetch$1 = _interopDefault(require('cross-fetch'));
|
|
8
|
-
var speechSdk = require('microsoft-cognitiveservices-speech-sdk');
|
|
9
8
|
|
|
10
9
|
function _regeneratorRuntime() {
|
|
11
10
|
/*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */
|
|
@@ -4108,239 +4107,6 @@ var constants = {
|
|
|
4108
4107
|
anonTag: anonTag
|
|
4109
4108
|
};
|
|
4110
4109
|
|
|
4111
|
-
var getTTSVoice = function getTTSVoice(lang, voiceType) {
|
|
4112
|
-
var voice = '';
|
|
4113
|
-
var voiceLang = lang.toUpperCase();
|
|
4114
|
-
|
|
4115
|
-
switch (voiceLang) {
|
|
4116
|
-
case 'IT':
|
|
4117
|
-
voice = "" + (voiceType === 'MALE' ? 'it-IT-DiegoNeural' : 'it-IT-ElsaNeural');
|
|
4118
|
-
break;
|
|
4119
|
-
|
|
4120
|
-
case 'DE':
|
|
4121
|
-
voice = "" + (voiceType === 'MALE' ? 'de-DE-ConradNeural' : 'de-DE-KatjaNeural');
|
|
4122
|
-
break;
|
|
4123
|
-
|
|
4124
|
-
case 'EN':
|
|
4125
|
-
voice = "" + (voiceType === 'MALE' ? 'en-GB-RyanNeural' : 'en-GB-SoniaNeural');
|
|
4126
|
-
break;
|
|
4127
|
-
|
|
4128
|
-
case 'ES':
|
|
4129
|
-
voice = "" + (voiceType === 'MALE' ? 'es-ES-AlvaroNeural' : 'es-ES-ElviraNeural');
|
|
4130
|
-
break;
|
|
4131
|
-
|
|
4132
|
-
case 'FR':
|
|
4133
|
-
voice = "" + (voiceType === 'MALE' ? 'fr-FR-HenriNeural' : 'fr-FR-DeniseNeural');
|
|
4134
|
-
break;
|
|
4135
|
-
|
|
4136
|
-
case 'PT':
|
|
4137
|
-
voice = "" + (voiceType === 'MALE' ? 'pt-PT-DuarteNeural' : 'pt-PT-RaquelNeural');
|
|
4138
|
-
break;
|
|
4139
|
-
|
|
4140
|
-
default:
|
|
4141
|
-
voice = "" + (voiceType === 'MALE' ? 'it-IT-DiegoNeural' : 'it-IT-IsabellaNeural');
|
|
4142
|
-
break;
|
|
4143
|
-
}
|
|
4144
|
-
|
|
4145
|
-
return voice;
|
|
4146
|
-
};
|
|
4147
|
-
|
|
4148
|
-
var getCultureCodeByLanguage = function getCultureCodeByLanguage(lang) {
|
|
4149
|
-
var voice = '';
|
|
4150
|
-
var voiceLang = lang.toUpperCase();
|
|
4151
|
-
|
|
4152
|
-
switch (voiceLang) {
|
|
4153
|
-
case 'IT':
|
|
4154
|
-
voice = 'it-IT';
|
|
4155
|
-
break;
|
|
4156
|
-
|
|
4157
|
-
case 'DE':
|
|
4158
|
-
voice = 'de-DE';
|
|
4159
|
-
break;
|
|
4160
|
-
|
|
4161
|
-
case 'EN':
|
|
4162
|
-
voice = 'en-US';
|
|
4163
|
-
break;
|
|
4164
|
-
|
|
4165
|
-
case 'ES':
|
|
4166
|
-
voice = 'es-ES';
|
|
4167
|
-
break;
|
|
4168
|
-
|
|
4169
|
-
case 'FR':
|
|
4170
|
-
voice = 'fr-FR';
|
|
4171
|
-
break;
|
|
4172
|
-
|
|
4173
|
-
case 'PT':
|
|
4174
|
-
voice = 'pt-PT';
|
|
4175
|
-
break;
|
|
4176
|
-
|
|
4177
|
-
default:
|
|
4178
|
-
voice = 'it-IT';
|
|
4179
|
-
break;
|
|
4180
|
-
}
|
|
4181
|
-
|
|
4182
|
-
return voice;
|
|
4183
|
-
};
|
|
4184
|
-
/**
|
|
4185
|
-
* EXPERIMENTAL
|
|
4186
|
-
*/
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
var speech = function speech(AZURE_COGNITIVE_SERVICES_TTS_KEY, DEBUG) {
|
|
4190
|
-
if (DEBUG === void 0) {
|
|
4191
|
-
DEBUG = false;
|
|
4192
|
-
}
|
|
4193
|
-
|
|
4194
|
-
return function (lang, voiceType) {
|
|
4195
|
-
var speechConfig = speechSdk.SpeechConfig.fromSubscription(AZURE_COGNITIVE_SERVICES_TTS_KEY, 'eastus');
|
|
4196
|
-
var speechSynthesizer;
|
|
4197
|
-
var audioDestination;
|
|
4198
|
-
audioDestination = new speechSdk.SpeakerAudioDestination();
|
|
4199
|
-
var audioOutputConfig = speechSdk.AudioConfig.fromSpeakerOutput(audioDestination); // https://docs.microsoft.com/it-it/azure/cognitive-services/speech-service/language-support#text-to-speech
|
|
4200
|
-
|
|
4201
|
-
speechConfig.speechSynthesisVoiceName = getTTSVoice(lang, voiceType);
|
|
4202
|
-
var langCultureCode = getCultureCodeByLanguage(lang);
|
|
4203
|
-
speechConfig.speechSynthesisLanguage = langCultureCode;
|
|
4204
|
-
speechConfig.speechRecognitionLanguage = langCultureCode;
|
|
4205
|
-
/**
|
|
4206
|
-
* speak
|
|
4207
|
-
* @description Speaks the text using the speech synthesizer. (TTS)
|
|
4208
|
-
* @param {string} text - The text to be synthesized.
|
|
4209
|
-
* @param {func=} onAudioEnd - The callback to be invoked when the synthesized audio is finished.
|
|
4210
|
-
*/
|
|
4211
|
-
|
|
4212
|
-
var speak = function speak(text, onAudioEnd) {
|
|
4213
|
-
stopSpeaking();
|
|
4214
|
-
speechSynthesizer = new speechSdk.SpeechSynthesizer(speechConfig, audioOutputConfig);
|
|
4215
|
-
if (onAudioEnd) audioDestination.onAudioEnd = onAudioEnd;
|
|
4216
|
-
speechSynthesizer.speakTextAsync(text, function (result) {
|
|
4217
|
-
if (result) {
|
|
4218
|
-
try {
|
|
4219
|
-
if (DEBUG) console.log('speak result', result);
|
|
4220
|
-
|
|
4221
|
-
if (speechSynthesizer) {
|
|
4222
|
-
speechSynthesizer.close();
|
|
4223
|
-
speechSynthesizer = null;
|
|
4224
|
-
}
|
|
4225
|
-
} catch (e) {
|
|
4226
|
-
console.error('speak error: ', e);
|
|
4227
|
-
window.speechSynthesis.speak(new SpeechSynthesisUtterance(text));
|
|
4228
|
-
}
|
|
4229
|
-
} else if (DEBUG) {
|
|
4230
|
-
console.log('speak no result', result);
|
|
4231
|
-
}
|
|
4232
|
-
}, function (error) {
|
|
4233
|
-
console.error('speak:', error);
|
|
4234
|
-
window.speechSynthesis.speak(new SpeechSynthesisUtterance(text));
|
|
4235
|
-
});
|
|
4236
|
-
};
|
|
4237
|
-
/**
|
|
4238
|
-
* isSpeaking
|
|
4239
|
-
* @description Returns true if the synthesizer is speaking.
|
|
4240
|
-
* @returns {boolean}
|
|
4241
|
-
*/
|
|
4242
|
-
|
|
4243
|
-
|
|
4244
|
-
var isSpeaking = function isSpeaking() {
|
|
4245
|
-
return !!speechSynthesizer;
|
|
4246
|
-
};
|
|
4247
|
-
/**
|
|
4248
|
-
* stopSpeaking
|
|
4249
|
-
* @description Stops the speech synthesizer if it is synthesizing.
|
|
4250
|
-
*/
|
|
4251
|
-
|
|
4252
|
-
|
|
4253
|
-
var stopSpeaking = function stopSpeaking() {
|
|
4254
|
-
if (audioDestination) audioDestination.pause();
|
|
4255
|
-
|
|
4256
|
-
if (speechSynthesizer) {
|
|
4257
|
-
speechSynthesizer.close();
|
|
4258
|
-
speechSynthesizer = null;
|
|
4259
|
-
}
|
|
4260
|
-
};
|
|
4261
|
-
|
|
4262
|
-
var audioInputConfig = speechSdk.AudioConfig.fromDefaultMicrophoneInput();
|
|
4263
|
-
var recognizer;
|
|
4264
|
-
/**
|
|
4265
|
-
* recognize
|
|
4266
|
-
* @description Starts the speech recognition.
|
|
4267
|
-
* @param {func=} onRecognized - Callback method invoked when the speech is recognized with the text.
|
|
4268
|
-
*/
|
|
4269
|
-
|
|
4270
|
-
var recognize = function recognize(onRecognized) {
|
|
4271
|
-
recognizer = new speechSdk.SpeechRecognizer(speechConfig, audioInputConfig);
|
|
4272
|
-
|
|
4273
|
-
recognizer.recognizing = function (_s, e) {
|
|
4274
|
-
if (DEBUG) console.log("RECOGNIZING: Text=" + e.result.text);
|
|
4275
|
-
};
|
|
4276
|
-
|
|
4277
|
-
recognizer.recognized = function (_s, e) {
|
|
4278
|
-
if (e.result.reason === speechSdk.ResultReason.RecognizedSpeech) {
|
|
4279
|
-
var _e$result$text;
|
|
4280
|
-
|
|
4281
|
-
if (DEBUG) console.log("RECOGNIZED: Text=" + e.result.text);
|
|
4282
|
-
onRecognized((_e$result$text = e.result.text) != null ? _e$result$text : '');
|
|
4283
|
-
} else if (e.result.reason === speechSdk.ResultReason.NoMatch && DEBUG) {
|
|
4284
|
-
console.log('NOMATCH: Speech could not be recognized.');
|
|
4285
|
-
}
|
|
4286
|
-
};
|
|
4287
|
-
|
|
4288
|
-
recognizer.canceled = function (_s, e) {
|
|
4289
|
-
if (DEBUG) console.log("CANCELED: Reason=" + e.reason);
|
|
4290
|
-
|
|
4291
|
-
if (e.reason === speechSdk.CancellationReason.Error && DEBUG) {
|
|
4292
|
-
console.log("\"CANCELED: ErrorCode=" + e.errorCode);
|
|
4293
|
-
console.log("\"CANCELED: ErrorDetails=" + e.errorDetails);
|
|
4294
|
-
console.log('CANCELED: Did you set the speech resource key and region values?');
|
|
4295
|
-
}
|
|
4296
|
-
|
|
4297
|
-
stopRecognizing();
|
|
4298
|
-
};
|
|
4299
|
-
|
|
4300
|
-
recognizer.sessionStopped = function (_s, _e) {
|
|
4301
|
-
if (DEBUG) console.log('\n Session stopped event.');
|
|
4302
|
-
if (recognizer) recognizer.stopContinuousRecognitionAsync();
|
|
4303
|
-
};
|
|
4304
|
-
|
|
4305
|
-
recognizer.startContinuousRecognitionAsync();
|
|
4306
|
-
};
|
|
4307
|
-
/**
|
|
4308
|
-
* isRecognizing
|
|
4309
|
-
* @description Returns true if the recognizer is recognizing.
|
|
4310
|
-
* @returns {boolean}
|
|
4311
|
-
*/
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
var isRecognizing = function isRecognizing() {
|
|
4315
|
-
return !!recognizer;
|
|
4316
|
-
};
|
|
4317
|
-
/**
|
|
4318
|
-
* stopRecognizing
|
|
4319
|
-
* @description Stops the speech recognizer if it is recognizing.
|
|
4320
|
-
* @param {func=} onStop - (optional) The callback to be invoked when the speech recognition is stopped.
|
|
4321
|
-
*/
|
|
4322
|
-
|
|
4323
|
-
|
|
4324
|
-
var stopRecognizing = function stopRecognizing(onStop) {
|
|
4325
|
-
if (recognizer) {
|
|
4326
|
-
recognizer.stopContinuousRecognitionAsync();
|
|
4327
|
-
recognizer.close();
|
|
4328
|
-
recognizer = null;
|
|
4329
|
-
if (onStop) onStop();
|
|
4330
|
-
}
|
|
4331
|
-
};
|
|
4332
|
-
|
|
4333
|
-
return {
|
|
4334
|
-
speak: speak,
|
|
4335
|
-
isSpeaking: isSpeaking,
|
|
4336
|
-
stopSpeaking: stopSpeaking,
|
|
4337
|
-
recognize: recognize,
|
|
4338
|
-
isRecognizing: isRecognizing,
|
|
4339
|
-
stopRecognizing: stopRecognizing
|
|
4340
|
-
};
|
|
4341
|
-
};
|
|
4342
|
-
};
|
|
4343
|
-
|
|
4344
4110
|
var asset$1 = (function (apiUrl) {
|
|
4345
4111
|
return {
|
|
4346
4112
|
/**
|
|
@@ -4383,7 +4149,6 @@ var api = function api(hostname) {
|
|
|
4383
4149
|
return _extends({
|
|
4384
4150
|
backend: backendAPI(apiUrl + "/api/v2")
|
|
4385
4151
|
}, engine(apiUrl + "/memori/v2"), {
|
|
4386
|
-
speech: speech,
|
|
4387
4152
|
constants: constants,
|
|
4388
4153
|
asset: asset$1(apiUrl + "/api/v2")
|
|
4389
4154
|
});
|