@websolutespa/bom-llm 0.0.36 → 0.0.38
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 +12 -0
- package/dist/umd/index.js +98 -98
- package/dist/umd/index.js.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/dist/umd/index.js
CHANGED
|
@@ -22063,90 +22063,6 @@ ${Object.entries(vars).map(_ref2 => {
|
|
|
22063
22063
|
}
|
|
22064
22064
|
}
|
|
22065
22065
|
}
|
|
22066
|
-
class ElevenlabsTextToSpeech {
|
|
22067
|
-
chunks_ = [];
|
|
22068
|
-
lang = 'it';
|
|
22069
|
-
speaking = false;
|
|
22070
|
-
get hasSupport() {
|
|
22071
|
-
return true;
|
|
22072
|
-
}
|
|
22073
|
-
constructor(apiKey, voiceId) {
|
|
22074
|
-
this.apiKey = apiKey;
|
|
22075
|
-
this.voiceId = voiceId;
|
|
22076
|
-
}
|
|
22077
|
-
speak(text) {
|
|
22078
|
-
// console.log('ElevenlabsTextToSpeech.speak', text, this.enabled, this.hasSupport);
|
|
22079
|
-
|
|
22080
|
-
if (!this.apiKey) {
|
|
22081
|
-
console.error('ElevenlabsTextToSpeech.error: missing apiKey!');
|
|
22082
|
-
return;
|
|
22083
|
-
}
|
|
22084
|
-
if (!this.voiceId) {
|
|
22085
|
-
console.error('ElevenlabsTextToSpeech.error: missing voiceId!');
|
|
22086
|
-
return;
|
|
22087
|
-
}
|
|
22088
|
-
if (this.speaking) {
|
|
22089
|
-
// console.warn('speak already speaking');
|
|
22090
|
-
this.chunks_.push(text);
|
|
22091
|
-
return;
|
|
22092
|
-
}
|
|
22093
|
-
this.speaking = true;
|
|
22094
|
-
const ctx = new AudioContext();
|
|
22095
|
-
const options = {
|
|
22096
|
-
method: 'POST',
|
|
22097
|
-
headers: {
|
|
22098
|
-
'xi-api-key': this.apiKey,
|
|
22099
|
-
'Content-Type': 'application/json'
|
|
22100
|
-
},
|
|
22101
|
-
body: JSON.stringify({
|
|
22102
|
-
voice_settings: {
|
|
22103
|
-
stability: 1,
|
|
22104
|
-
similarity_boost: 1
|
|
22105
|
-
},
|
|
22106
|
-
text: text,
|
|
22107
|
-
model_id: 'eleven_multilingual_v2'
|
|
22108
|
-
})
|
|
22109
|
-
};
|
|
22110
|
-
fetch(`https://api.elevenlabs.io/v1/text-to-speech/${this.voiceId}?output_format=mp3_22050_32`, options).then(data => data.arrayBuffer()).then(arrayBuffer => ctx.decodeAudioData(arrayBuffer)).then(audioBuffer => {
|
|
22111
|
-
return new Promise((resolve, reject) => {
|
|
22112
|
-
const audioSource = this.audioSource_ = ctx.createBufferSource();
|
|
22113
|
-
audioSource.buffer = audioBuffer;
|
|
22114
|
-
audioSource.connect(ctx.destination);
|
|
22115
|
-
audioSource.start(ctx.currentTime);
|
|
22116
|
-
audioSource.addEventListener('ended', () => {
|
|
22117
|
-
this.audioSource_ = undefined;
|
|
22118
|
-
resolve(audioSource);
|
|
22119
|
-
});
|
|
22120
|
-
audioSource.addEventListener('error', error => {
|
|
22121
|
-
this.audioSource_ = undefined;
|
|
22122
|
-
reject(error);
|
|
22123
|
-
});
|
|
22124
|
-
});
|
|
22125
|
-
}).then(audioSource => {
|
|
22126
|
-
console.log('ElevenlabsTextToSpeech.speak.success', audioSource);
|
|
22127
|
-
}).catch(error => {
|
|
22128
|
-
console.error('ElevenlabsTextToSpeech.speak.error', error);
|
|
22129
|
-
}).finally(() => {
|
|
22130
|
-
this.speaking = false;
|
|
22131
|
-
if (this.chunks_.length > 0) {
|
|
22132
|
-
const text = this.chunks_.shift();
|
|
22133
|
-
if (text) {
|
|
22134
|
-
this.speak(text);
|
|
22135
|
-
}
|
|
22136
|
-
}
|
|
22137
|
-
});
|
|
22138
|
-
}
|
|
22139
|
-
cancel() {
|
|
22140
|
-
if (this.speaking) {
|
|
22141
|
-
// cancel
|
|
22142
|
-
if (this.audioSource_) {
|
|
22143
|
-
this.audioSource_.stop();
|
|
22144
|
-
this.audioSource_ = undefined;
|
|
22145
|
-
}
|
|
22146
|
-
this.speaking = false;
|
|
22147
|
-
}
|
|
22148
|
-
}
|
|
22149
|
-
}
|
|
22150
22066
|
class DefaultTextToSpeech {
|
|
22151
22067
|
chunks_ = [];
|
|
22152
22068
|
lang = 'it';
|
|
@@ -22252,6 +22168,7 @@ ${Object.entries(vars).map(_ref2 => {
|
|
|
22252
22168
|
synthesis.speak(utterance);
|
|
22253
22169
|
}
|
|
22254
22170
|
cancel() {
|
|
22171
|
+
this.chunks_ = [];
|
|
22255
22172
|
if (!this.hasSupport) {
|
|
22256
22173
|
return;
|
|
22257
22174
|
}
|
|
@@ -22271,6 +22188,90 @@ ${Object.entries(vars).map(_ref2 => {
|
|
|
22271
22188
|
console.log('DefaultTextToSpeech', ...rest);
|
|
22272
22189
|
}
|
|
22273
22190
|
}
|
|
22191
|
+
class ElevenlabsTextToSpeech {
|
|
22192
|
+
chunks_ = [];
|
|
22193
|
+
lang = 'it';
|
|
22194
|
+
speaking = false;
|
|
22195
|
+
get hasSupport() {
|
|
22196
|
+
return true;
|
|
22197
|
+
}
|
|
22198
|
+
constructor(apiKey, voiceId) {
|
|
22199
|
+
this.apiKey = apiKey;
|
|
22200
|
+
this.voiceId = voiceId;
|
|
22201
|
+
}
|
|
22202
|
+
speak(text) {
|
|
22203
|
+
// console.log('ElevenlabsTextToSpeech.speak', text, this.enabled, this.hasSupport);
|
|
22204
|
+
|
|
22205
|
+
if (!this.apiKey) {
|
|
22206
|
+
console.error('ElevenlabsTextToSpeech.error: missing apiKey!');
|
|
22207
|
+
return;
|
|
22208
|
+
}
|
|
22209
|
+
if (!this.voiceId) {
|
|
22210
|
+
console.error('ElevenlabsTextToSpeech.error: missing voiceId!');
|
|
22211
|
+
return;
|
|
22212
|
+
}
|
|
22213
|
+
if (this.speaking) {
|
|
22214
|
+
// console.warn('speak already speaking');
|
|
22215
|
+
this.chunks_.push(text);
|
|
22216
|
+
return;
|
|
22217
|
+
}
|
|
22218
|
+
this.speaking = true;
|
|
22219
|
+
const ctx = new AudioContext();
|
|
22220
|
+
const options = {
|
|
22221
|
+
method: 'POST',
|
|
22222
|
+
headers: {
|
|
22223
|
+
'xi-api-key': this.apiKey,
|
|
22224
|
+
'Content-Type': 'application/json'
|
|
22225
|
+
},
|
|
22226
|
+
body: JSON.stringify({
|
|
22227
|
+
voice_settings: {
|
|
22228
|
+
stability: 1,
|
|
22229
|
+
similarity_boost: 1
|
|
22230
|
+
},
|
|
22231
|
+
text: text,
|
|
22232
|
+
model_id: 'eleven_multilingual_v2'
|
|
22233
|
+
})
|
|
22234
|
+
};
|
|
22235
|
+
fetch(`https://api.elevenlabs.io/v1/text-to-speech/${this.voiceId}?output_format=mp3_22050_32`, options).then(data => data.arrayBuffer()).then(arrayBuffer => ctx.decodeAudioData(arrayBuffer)).then(audioBuffer => {
|
|
22236
|
+
return new Promise((resolve, reject) => {
|
|
22237
|
+
const audioSource = this.audioSource_ = ctx.createBufferSource();
|
|
22238
|
+
audioSource.buffer = audioBuffer;
|
|
22239
|
+
audioSource.connect(ctx.destination);
|
|
22240
|
+
audioSource.start(ctx.currentTime);
|
|
22241
|
+
audioSource.addEventListener('ended', () => {
|
|
22242
|
+
this.audioSource_ = undefined;
|
|
22243
|
+
resolve(audioSource);
|
|
22244
|
+
});
|
|
22245
|
+
audioSource.addEventListener('error', error => {
|
|
22246
|
+
this.audioSource_ = undefined;
|
|
22247
|
+
reject(error);
|
|
22248
|
+
});
|
|
22249
|
+
});
|
|
22250
|
+
}).then(audioSource => {
|
|
22251
|
+
console.log('ElevenlabsTextToSpeech.speak.success', audioSource);
|
|
22252
|
+
}).catch(error => {
|
|
22253
|
+
console.error('ElevenlabsTextToSpeech.speak.error', error);
|
|
22254
|
+
}).finally(() => {
|
|
22255
|
+
this.speaking = false;
|
|
22256
|
+
if (this.chunks_.length > 0) {
|
|
22257
|
+
const text = this.chunks_.shift();
|
|
22258
|
+
if (text) {
|
|
22259
|
+
this.speak(text);
|
|
22260
|
+
}
|
|
22261
|
+
}
|
|
22262
|
+
});
|
|
22263
|
+
}
|
|
22264
|
+
cancel() {
|
|
22265
|
+
this.chunks_ = [];
|
|
22266
|
+
if (this.speaking) {
|
|
22267
|
+
if (this.audioSource_) {
|
|
22268
|
+
this.audioSource_.stop();
|
|
22269
|
+
this.audioSource_ = undefined;
|
|
22270
|
+
}
|
|
22271
|
+
this.speaking = false;
|
|
22272
|
+
}
|
|
22273
|
+
}
|
|
22274
|
+
}
|
|
22274
22275
|
class DefaultSpeechToText {
|
|
22275
22276
|
lang = 'it';
|
|
22276
22277
|
enabled = false;
|
|
@@ -22586,6 +22587,7 @@ ${Object.entries(vars).map(_ref2 => {
|
|
|
22586
22587
|
}, 2000);
|
|
22587
22588
|
},
|
|
22588
22589
|
initIntersection: element => {
|
|
22590
|
+
// console.log('initIntersection', element);
|
|
22589
22591
|
const handleIntersection = () => {
|
|
22590
22592
|
// console.log('handleIntersection', element);
|
|
22591
22593
|
if (!element) {
|
|
@@ -22799,19 +22801,18 @@ ${Object.entries(vars).map(_ref2 => {
|
|
|
22799
22801
|
return;
|
|
22800
22802
|
}
|
|
22801
22803
|
const state = get();
|
|
22802
|
-
const disableSpeechSynthesis = app.contents.synthesisMode ? app.contents.synthesisMode === 'none' : app.contents.disableSpeechSynthesis;
|
|
22803
22804
|
const textToSpeechApiKey = app.contents.textToSpeechApiKey;
|
|
22804
22805
|
const textToSpeechVoiceId = app.contents.textToSpeechVoiceId;
|
|
22805
|
-
const synthesisMode = app.contents.synthesisMode || 'default';
|
|
22806
|
-
const recognitionMode = app.contents.recognitionMode || 'default';
|
|
22807
|
-
const speechEnabled = state.speakEnabled
|
|
22806
|
+
const synthesisMode = app.contents.synthesisMode || (app.contents.disableSpeechSynthesis ? 'none' : 'default');
|
|
22807
|
+
const recognitionMode = app.contents.recognitionMode || (app.contents.disableSpeechRecognition ? 'none' : 'default');
|
|
22808
|
+
const speechEnabled = state.speakEnabled;
|
|
22808
22809
|
speech.lang = locale;
|
|
22809
22810
|
speech.enabled = speechEnabled;
|
|
22810
22811
|
speech.textToSpeechApiKey = textToSpeechApiKey;
|
|
22811
22812
|
speech.textToSpeechVoiceId = textToSpeechVoiceId;
|
|
22812
22813
|
speech.synthesisMode = synthesisMode;
|
|
22813
22814
|
speech.recognitionMode = recognitionMode;
|
|
22814
|
-
// console.log('useLlm.init', { textToSpeechApiKey, textToSpeechVoiceId, synthesisMode, recognitionMode,
|
|
22815
|
+
// console.log('useLlm.init', { textToSpeechApiKey, textToSpeechVoiceId, synthesisMode, recognitionMode, speechEnabled });
|
|
22815
22816
|
speech.on('result', async transcript => {
|
|
22816
22817
|
const state = get();
|
|
22817
22818
|
state.actions.setPrompt(transcript);
|
|
@@ -22954,18 +22955,16 @@ ${Object.entries(vars).map(_ref2 => {
|
|
|
22954
22955
|
prompt
|
|
22955
22956
|
})),
|
|
22956
22957
|
hasSpeechSynthesisSupport: () => {
|
|
22957
|
-
|
|
22958
|
-
|
|
22959
|
-
return speech.hasTextToSpeechSupport && !disableSpeechSynthesis;
|
|
22958
|
+
get();
|
|
22959
|
+
return speech.hasTextToSpeechSupport;
|
|
22960
22960
|
},
|
|
22961
22961
|
hasSpeechRecognitionSupport: () => {
|
|
22962
|
-
|
|
22963
|
-
|
|
22964
|
-
return speech.hasSpeechToTextSupport && !disableSpeechRecognition;
|
|
22962
|
+
get();
|
|
22963
|
+
return speech.hasSpeechToTextSupport;
|
|
22965
22964
|
},
|
|
22966
22965
|
toggleSpeak: () => {
|
|
22967
22966
|
set(state => {
|
|
22968
|
-
const speakEnabled = !state.speakEnabled
|
|
22967
|
+
const speakEnabled = !state.speakEnabled;
|
|
22969
22968
|
speech.setEnabled(speakEnabled);
|
|
22970
22969
|
return {
|
|
22971
22970
|
speakEnabled
|
|
@@ -23776,6 +23775,7 @@ void main(void) {
|
|
|
23776
23775
|
canvasRef,
|
|
23777
23776
|
shaderRef,
|
|
23778
23777
|
attach: canvas => {
|
|
23778
|
+
// console.log('CanvasOffscreenContextProvider.attach', canvas, shaderRef.current);
|
|
23779
23779
|
if (shaderRef.current) {
|
|
23780
23780
|
shaderRef.current.attach(canvas);
|
|
23781
23781
|
}
|
|
@@ -33696,10 +33696,10 @@ void main(void) {
|
|
|
33696
33696
|
initView();
|
|
33697
33697
|
}, [init, locale, initView]);
|
|
33698
33698
|
reactExports.useEffect(() => {
|
|
33699
|
-
if (innerRef.current) {
|
|
33699
|
+
if (mounted && ready && innerRef.current) {
|
|
33700
33700
|
initIntersection(innerRef.current);
|
|
33701
33701
|
}
|
|
33702
|
-
}, [mounted, initIntersection, innerRef]);
|
|
33702
|
+
}, [mounted, ready, initIntersection, innerRef]);
|
|
33703
33703
|
reactExports.useEffect(() => {
|
|
33704
33704
|
if (!embedded) {
|
|
33705
33705
|
document.documentElement.style.overflow = opened ? 'hidden' : 'auto';
|