@handsforbots/voice 0.0.0-stage → 2.0.0-alpha.1
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/LICENSE.md +9 -0
- package/README.md +20 -2
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/player.d.ts +33 -0
- package/dist/player.d.ts.map +1 -0
- package/dist/player.js +141 -0
- package/dist/player.js.map +1 -0
- package/dist/providers/echo.d.ts +25 -0
- package/dist/providers/echo.d.ts.map +1 -0
- package/dist/providers/echo.js +85 -0
- package/dist/providers/echo.js.map +1 -0
- package/dist/providers/end-of-turn.d.ts +22 -0
- package/dist/providers/end-of-turn.d.ts.map +1 -0
- package/dist/providers/end-of-turn.js +29 -0
- package/dist/providers/end-of-turn.js.map +1 -0
- package/dist/providers/http.d.ts +48 -0
- package/dist/providers/http.d.ts.map +1 -0
- package/dist/providers/http.js +153 -0
- package/dist/providers/http.js.map +1 -0
- package/dist/providers/media.d.ts +15 -0
- package/dist/providers/media.d.ts.map +1 -0
- package/dist/providers/media.js +122 -0
- package/dist/providers/media.js.map +1 -0
- package/dist/providers/vosk-browser.d.ts +33 -0
- package/dist/providers/vosk-browser.d.ts.map +1 -0
- package/dist/providers/vosk-browser.js +82 -0
- package/dist/providers/vosk-browser.js.map +1 -0
- package/dist/providers/websocket.d.ts +38 -0
- package/dist/providers/websocket.d.ts.map +1 -0
- package/dist/providers/websocket.js +94 -0
- package/dist/providers/websocket.js.map +1 -0
- package/dist/providers/webspeech.d.ts +40 -0
- package/dist/providers/webspeech.d.ts.map +1 -0
- package/dist/providers/webspeech.js +201 -0
- package/dist/providers/webspeech.js.map +1 -0
- package/dist/types.d.ts +263 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +20 -0
- package/dist/types.js.map +1 -0
- package/dist/voice.d.ts +283 -0
- package/dist/voice.d.ts.map +1 -0
- package/dist/voice.js +1209 -0
- package/dist/voice.js.map +1 -0
- package/package.json +42 -3
package/LICENSE.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © 2024 Alex Lana and Hands for Bots contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,21 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @handsforbots/voice
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Plugin. Voice for Hands for Bots: pluggable speech-to-text and text-to-speech (browser or cloud), push-to-talk, hands-free and barge-in.
|
|
4
|
+
|
|
5
|
+
Part of [Hands for Bots](https://github.com/handsforbots/handsforbots), a headless multimodal and action layer between users, GUIs and agents.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @handsforbots/voice@alpha @handsforbots/core@alpha
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Documentation
|
|
14
|
+
|
|
15
|
+
- [This package](https://github.com/handsforbots/handsforbots/blob/main/docs/en-us/plugins.md#voice)
|
|
16
|
+
- [Getting started](https://github.com/handsforbots/handsforbots/blob/main/docs/en-us/getting-started.md)
|
|
17
|
+
- [Documentação em português](https://github.com/handsforbots/handsforbots/blob/main/docs/pt-br/README.md)
|
|
18
|
+
|
|
19
|
+
## License
|
|
20
|
+
|
|
21
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { voice, createVoice, type BargeInOptions, type InputModality, type ListenOptions, type OutputPreference, type SpeechLoadStart, type SpeechLoading, type SpeechWhileLoading, type TtsStatus, type TurnTiming, type VoiceDecision, type VoiceMode, type VoicePhase, type VoiceOptions, type VoiceService, type VoiceSpeechEvent, type VoiceTtsEvent, type VoiceState, } from './voice.js';
|
|
2
|
+
export { webSpeechSTT, webSpeechTTS, splitSentences, utteranceProsody, type WebSpeechSTTOptions, type WebSpeechTTSOptions, } from './providers/webspeech.js';
|
|
3
|
+
export { httpSTT, httpTTS, decodeAudio, type HttpSTTOptions, type HttpTTSOptions } from './providers/http.js';
|
|
4
|
+
export { webAudioPlayer, planProsody, encodeWav, type ProsodyPlan, type WebAudioPlayerOptions } from './player.js';
|
|
5
|
+
export { websocketSTT, voskSTT, type StreamingResult, type WebSocketSTTOptions } from './providers/websocket.js';
|
|
6
|
+
export { voskBrowserSTT, type VoskBrowserModule, type VoskBrowserOptions } from './providers/vosk-browser.js';
|
|
7
|
+
export { httpEndOfTurn, type HttpEndOfTurnOptions } from './providers/end-of-turn.js';
|
|
8
|
+
export { textEchoFilter, echoCoverage, type TextEchoFilterOptions } from './providers/echo.js';
|
|
9
|
+
export { captureFloat, capturePcm16, detectEndOfSpeech, openMicrophone } from './providers/media.js';
|
|
10
|
+
export * from './types.js';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"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/dist/index.js
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { voice, createVoice, } from './voice.js';
|
|
2
|
+
export { webSpeechSTT, webSpeechTTS, splitSentences, utteranceProsody, } from './providers/webspeech.js';
|
|
3
|
+
export { httpSTT, httpTTS, decodeAudio } from './providers/http.js';
|
|
4
|
+
export { webAudioPlayer, planProsody, encodeWav } from './player.js';
|
|
5
|
+
export { websocketSTT, voskSTT } from './providers/websocket.js';
|
|
6
|
+
export { voskBrowserSTT } from './providers/vosk-browser.js';
|
|
7
|
+
export { httpEndOfTurn } from './providers/end-of-turn.js';
|
|
8
|
+
export { textEchoFilter, echoCoverage } from './providers/echo.js';
|
|
9
|
+
export { captureFloat, capturePcm16, detectEndOfSpeech, openMicrophone } from './providers/media.js';
|
|
10
|
+
export * from './types.js';
|
|
11
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,EACL,WAAW,GAkBZ,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,gBAAgB,GAGjB,MAAM,0BAA0B,CAAA;AACjC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,WAAW,EAA4C,MAAM,qBAAqB,CAAA;AAC7G,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,SAAS,EAAgD,MAAM,aAAa,CAAA;AAClH,OAAO,EAAE,YAAY,EAAE,OAAO,EAAkD,MAAM,0BAA0B,CAAA;AAChH,OAAO,EAAE,cAAc,EAAmD,MAAM,6BAA6B,CAAA;AAC7G,OAAO,EAAE,aAAa,EAA6B,MAAM,4BAA4B,CAAA;AACrF,OAAO,EAAE,cAAc,EAAE,YAAY,EAA8B,MAAM,qBAAqB,CAAA;AAC9F,OAAO,EAAE,YAAY,EAAE,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACpG,cAAc,YAAY,CAAA"}
|
package/dist/player.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { type AudioPlayer, type Prosody, type ProsodySupport, type SpeechAudio } from './types.js';
|
|
2
|
+
export type WebAudioPlayerOptions = {
|
|
3
|
+
/** The audio context to play in. Default: one created on the first `unlock()`. */
|
|
4
|
+
context?: AudioContext | (() => AudioContext);
|
|
5
|
+
/**
|
|
6
|
+
* Where the speech goes. Default `context.destination`. Return your own node
|
|
7
|
+
* to tap the voice (an `AnalyserNode` for mouth movement, a recorder).
|
|
8
|
+
*/
|
|
9
|
+
output?: (context: AudioContext) => AudioNode;
|
|
10
|
+
/** How long `play` waits for a suspended context to resume before failing. Default 1000 ms. */
|
|
11
|
+
resumeTimeout?: number;
|
|
12
|
+
};
|
|
13
|
+
/** Plays speech through Web Audio, with the effects of each sentence. */
|
|
14
|
+
export declare function webAudioPlayer(options?: WebAudioPlayerOptions): AudioPlayer;
|
|
15
|
+
export type ProsodyPlan = {
|
|
16
|
+
/** What the provider is asked to do itself. */
|
|
17
|
+
synth: Prosody;
|
|
18
|
+
/** The player's playback rate. */
|
|
19
|
+
playbackRate: number;
|
|
20
|
+
/** The player's gain. */
|
|
21
|
+
gainDb: number;
|
|
22
|
+
};
|
|
23
|
+
/**
|
|
24
|
+
* Splits the prosody between the provider and the player. The provider does
|
|
25
|
+
* what it declares; with a player, pitch becomes a playback rate (which also
|
|
26
|
+
* speeds up the speech, so a provider that controls its rate is asked to slow
|
|
27
|
+
* down by the same factor and the tempo stays) and volume becomes gain. Rate
|
|
28
|
+
* is never faked with the playback rate: it would change the pitch too.
|
|
29
|
+
*/
|
|
30
|
+
export declare function planProsody(native: ProsodySupport | undefined, prosody: Prosody | undefined, player: boolean): ProsodyPlan;
|
|
31
|
+
/** 16-bit PCM WAV file of mono audio. */
|
|
32
|
+
export declare function encodeWav(audio: SpeechAudio): Blob;
|
|
33
|
+
//# sourceMappingURL=player.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"player.d.ts","sourceRoot":"","sources":["../src/player.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,WAAW,EAAE,KAAK,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAA;AAE/G,MAAM,MAAM,qBAAqB,GAAG;IAClC,kFAAkF;IAClF,OAAO,CAAC,EAAE,YAAY,GAAG,CAAC,MAAM,YAAY,CAAC,CAAA;IAC7C;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,YAAY,KAAK,SAAS,CAAA;IAC7C,+FAA+F;IAC/F,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB,CAAA;AAED,yEAAyE;AACzE,wBAAgB,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,WAAW,CA0F/E;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,+CAA+C;IAC/C,KAAK,EAAE,OAAO,CAAA;IACd,kCAAkC;IAClC,YAAY,EAAE,MAAM,CAAA;IACpB,yBAAyB;IACzB,MAAM,EAAE,MAAM,CAAA;CACf,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,cAAc,YAAK,EAAE,OAAO,EAAE,OAAO,YAAK,EAAE,MAAM,EAAE,OAAO,GAAG,WAAW,CAe5G;AAED,yCAAyC;AACzC,wBAAgB,SAAS,CAAC,KAAK,EAAE,WAAW,GAAG,IAAI,CAoBlD"}
|
package/dist/player.js
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { SpeechError } from './types.js';
|
|
2
|
+
/** Plays speech through Web Audio, with the effects of each sentence. */
|
|
3
|
+
export function webAudioPlayer(options = {}) {
|
|
4
|
+
let context;
|
|
5
|
+
let output;
|
|
6
|
+
/** Everything still sounding: the current sentence and the tails of earlier ones. */
|
|
7
|
+
const live = new Set();
|
|
8
|
+
const ensure = () => {
|
|
9
|
+
if (!context) {
|
|
10
|
+
const given = options.context;
|
|
11
|
+
context = typeof given === 'function' ? given() : (given ?? new AudioContext());
|
|
12
|
+
output = options.output?.(context) ?? context.destination;
|
|
13
|
+
}
|
|
14
|
+
return context;
|
|
15
|
+
};
|
|
16
|
+
const running = async (ctx) => {
|
|
17
|
+
if (ctx.state === 'running')
|
|
18
|
+
return true;
|
|
19
|
+
const resumed = ctx.resume().then(() => true, () => false);
|
|
20
|
+
const timeout = new Promise((resolve) => setTimeout(() => resolve(false), options.resumeTimeout ?? 1000));
|
|
21
|
+
return (await Promise.race([resumed, timeout])) && ctx.state === 'running';
|
|
22
|
+
};
|
|
23
|
+
return {
|
|
24
|
+
isSupported: () => typeof AudioContext !== 'undefined' || !!options.context,
|
|
25
|
+
unlock() {
|
|
26
|
+
const ctx = ensure();
|
|
27
|
+
if (ctx.state !== 'running')
|
|
28
|
+
ctx.resume().catch(() => { });
|
|
29
|
+
},
|
|
30
|
+
async play(audio, play) {
|
|
31
|
+
const ctx = ensure();
|
|
32
|
+
if (play.signal?.aborted)
|
|
33
|
+
return;
|
|
34
|
+
if (!(await running(ctx))) {
|
|
35
|
+
throw new SpeechError('output-blocked', 'Audio is blocked until the user interacts with the page (call voice.unlockAudio() in a click)', 'speak');
|
|
36
|
+
}
|
|
37
|
+
if (play.signal?.aborted)
|
|
38
|
+
return;
|
|
39
|
+
const processed = play.effects?.process?.(audio) ?? audio;
|
|
40
|
+
const buffer = ctx.createBuffer(1, Math.max(1, processed.samples.length), processed.sampleRate);
|
|
41
|
+
buffer.getChannelData(0).set(processed.samples);
|
|
42
|
+
const source = ctx.createBufferSource();
|
|
43
|
+
source.buffer = buffer;
|
|
44
|
+
source.playbackRate.value = play.playbackRate ?? 1;
|
|
45
|
+
const chain = play.effects?.connect(ctx, source) ?? { output: source };
|
|
46
|
+
const gain = ctx.createGain();
|
|
47
|
+
gain.gain.value = 10 ** ((play.gainDb ?? 0) / 20);
|
|
48
|
+
chain.output.connect(gain).connect(output);
|
|
49
|
+
let released = false;
|
|
50
|
+
let tailTimer;
|
|
51
|
+
const release = () => {
|
|
52
|
+
if (released)
|
|
53
|
+
return;
|
|
54
|
+
released = true;
|
|
55
|
+
clearTimeout(tailTimer);
|
|
56
|
+
live.delete(release);
|
|
57
|
+
try {
|
|
58
|
+
source.stop();
|
|
59
|
+
}
|
|
60
|
+
catch { }
|
|
61
|
+
gain.disconnect();
|
|
62
|
+
chain.dispose?.();
|
|
63
|
+
};
|
|
64
|
+
live.add(release);
|
|
65
|
+
await new Promise((resolve) => {
|
|
66
|
+
const done = () => {
|
|
67
|
+
play.signal?.removeEventListener('abort', abort);
|
|
68
|
+
resolve();
|
|
69
|
+
};
|
|
70
|
+
const abort = () => {
|
|
71
|
+
release();
|
|
72
|
+
done();
|
|
73
|
+
};
|
|
74
|
+
source.onended = () => {
|
|
75
|
+
// The speech is over; the effects ring out on their own.
|
|
76
|
+
tailTimer = setTimeout(release, ((chain.tail ?? 0) + 0.1) * 1000);
|
|
77
|
+
done();
|
|
78
|
+
};
|
|
79
|
+
play.signal?.addEventListener('abort', abort, { once: true });
|
|
80
|
+
source.start();
|
|
81
|
+
});
|
|
82
|
+
},
|
|
83
|
+
stop() {
|
|
84
|
+
for (const release of [...live])
|
|
85
|
+
release();
|
|
86
|
+
},
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Splits the prosody between the provider and the player. The provider does
|
|
91
|
+
* what it declares; with a player, pitch becomes a playback rate (which also
|
|
92
|
+
* speeds up the speech, so a provider that controls its rate is asked to slow
|
|
93
|
+
* down by the same factor and the tempo stays) and volume becomes gain. Rate
|
|
94
|
+
* is never faked with the playback rate: it would change the pitch too.
|
|
95
|
+
*/
|
|
96
|
+
export function planProsody(native = {}, prosody = {}, player) {
|
|
97
|
+
const synth = {};
|
|
98
|
+
let playbackRate = 1;
|
|
99
|
+
let gainDb = 0;
|
|
100
|
+
if (prosody.pitch) {
|
|
101
|
+
if (native.pitch)
|
|
102
|
+
synth.pitch = prosody.pitch;
|
|
103
|
+
else if (player)
|
|
104
|
+
playbackRate = 2 ** (prosody.pitch / 12);
|
|
105
|
+
}
|
|
106
|
+
const rate = prosody.rate ?? 1;
|
|
107
|
+
if (native.rate && (rate !== 1 || playbackRate !== 1))
|
|
108
|
+
synth.rate = rate / playbackRate;
|
|
109
|
+
if (prosody.volume) {
|
|
110
|
+
if (native.volume)
|
|
111
|
+
synth.volume = prosody.volume;
|
|
112
|
+
else if (player)
|
|
113
|
+
gainDb = prosody.volume;
|
|
114
|
+
}
|
|
115
|
+
return { synth, playbackRate, gainDb };
|
|
116
|
+
}
|
|
117
|
+
/** 16-bit PCM WAV file of mono audio. */
|
|
118
|
+
export function encodeWav(audio) {
|
|
119
|
+
const { samples, sampleRate } = audio;
|
|
120
|
+
const view = new DataView(new ArrayBuffer(44 + samples.length * 2));
|
|
121
|
+
const text = (offset, value) => {
|
|
122
|
+
for (let i = 0; i < value.length; i++)
|
|
123
|
+
view.setUint8(offset + i, value.charCodeAt(i));
|
|
124
|
+
};
|
|
125
|
+
text(0, 'RIFF');
|
|
126
|
+
view.setUint32(4, 36 + samples.length * 2, true);
|
|
127
|
+
text(8, 'WAVEfmt ');
|
|
128
|
+
view.setUint32(16, 16, true);
|
|
129
|
+
view.setUint16(20, 1, true);
|
|
130
|
+
view.setUint16(22, 1, true);
|
|
131
|
+
view.setUint32(24, sampleRate, true);
|
|
132
|
+
view.setUint32(28, sampleRate * 2, true);
|
|
133
|
+
view.setUint16(32, 2, true);
|
|
134
|
+
view.setUint16(34, 16, true);
|
|
135
|
+
text(36, 'data');
|
|
136
|
+
view.setUint32(40, samples.length * 2, true);
|
|
137
|
+
for (let i = 0; i < samples.length; i++)
|
|
138
|
+
view.setInt16(44 + i * 2, Math.max(-1, Math.min(1, samples[i])) * 0x7fff, true);
|
|
139
|
+
return new Blob([view], { type: 'audio/wav' });
|
|
140
|
+
}
|
|
141
|
+
//# sourceMappingURL=player.js.map
|
|
@@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I,CAAC,CAAA;IACpC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,UAAU,GAAG,CAAC,EAAE,IAAI,CAAC,CAAA;IACxC,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,CAAC,EAAE,IAAI,CAAC,CAAA;IAC3B,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,EAAE,EAAE,IAAI,CAAC,CAAA;IAC5B,IAAI,CAAC,EAAE,EAAE,MAAM,CAAC,CAAA;IAChB,IAAI,CAAC,SAAS,CAAC,EAAE,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,EAAE,IAAI,CAAC,CAAA;IAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE;QAAE,IAAI,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,CAAE,CAAC,CAAC,GAAG,MAAM,EAAE,IAAI,CAAC,CAAA;IACzH,OAAO,IAAI,IAAI,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAA;AAChD,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { EchoFilter } from '../types.js';
|
|
2
|
+
export type TextEchoFilterOptions = {
|
|
3
|
+
/** Share of the heard words that must repeat what the bot said for the text to count as echo. Default 0.6. */
|
|
4
|
+
threshold?: number;
|
|
5
|
+
/** Consecutive words that must match the bot's speech, in order, before they count. Default 2. */
|
|
6
|
+
minRun?: number;
|
|
7
|
+
/** How long after a sentence ends its words can still come back from the recognizer (ms). Default 2000. */
|
|
8
|
+
tail?: number;
|
|
9
|
+
name?: string;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Share of `heard` covered by runs of at least `minRun` consecutive words that
|
|
13
|
+
* also appear, in the same order, in `spoken`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function echoCoverage(heard: string[], spoken: string[], minRun: number): number;
|
|
16
|
+
/**
|
|
17
|
+
* Drops what the recognizer heard when it repeats the bot's own speech (the
|
|
18
|
+
* speaker leaking into the microphone), so the bot does not interrupt or
|
|
19
|
+
* answer itself. It compares words, not audio, so it works with any
|
|
20
|
+
* recognizer, Web Speech included. The decision is all or nothing: a text
|
|
21
|
+
* that is mostly the bot's words is dropped; anything else is kept whole, so
|
|
22
|
+
* a user who quotes the bot while talking over it is never cut short.
|
|
23
|
+
*/
|
|
24
|
+
export declare function textEchoFilter(options?: TextEchoFilterOptions): EchoFilter;
|
|
25
|
+
//# sourceMappingURL=echo.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"echo.d.ts","sourceRoot":"","sources":["../../src/providers/echo.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAa,MAAM,aAAa,CAAA;AAExD,MAAM,MAAM,qBAAqB,GAAG;IAClC,8GAA8G;IAC9G,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,kGAAkG;IAClG,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,2GAA2G;IAC3G,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAoCD;;;GAGG;AACH,wBAAgB,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAgBtF;AAED;;;;;;;GAOG;AACH,wBAAgB,cAAc,CAAC,OAAO,GAAE,qBAA0B,GAAG,UAAU,CAc9E"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
/** Lowercase, without accents and punctuation: "Você," and "voce" are the same word. */
|
|
2
|
+
const wordKey = (word) => word
|
|
3
|
+
.normalize('NFD')
|
|
4
|
+
.replace(/\p{M}/gu, '')
|
|
5
|
+
.toLowerCase()
|
|
6
|
+
.replace(/[^\p{L}\p{N}']/gu, '');
|
|
7
|
+
const wordsOf = (text) => text.split(/\s+/).map(wordKey).filter(Boolean);
|
|
8
|
+
/** Same word, allowing one wrong letter in longer words (recognizers mishear echo). */
|
|
9
|
+
function sameWord(a, b) {
|
|
10
|
+
if (a === b)
|
|
11
|
+
return true;
|
|
12
|
+
if (Math.min(a.length, b.length) < 4 || Math.abs(a.length - b.length) > 1)
|
|
13
|
+
return false;
|
|
14
|
+
let i = 0;
|
|
15
|
+
let j = 0;
|
|
16
|
+
let edits = 0;
|
|
17
|
+
while (i < a.length && j < b.length) {
|
|
18
|
+
if (a[i] === b[j]) {
|
|
19
|
+
i++;
|
|
20
|
+
j++;
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
if (++edits > 1)
|
|
24
|
+
return false;
|
|
25
|
+
if (a.length > b.length)
|
|
26
|
+
i++;
|
|
27
|
+
else if (b.length > a.length)
|
|
28
|
+
j++;
|
|
29
|
+
else {
|
|
30
|
+
i++;
|
|
31
|
+
j++;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return edits + (a.length - i) + (b.length - j) <= 1;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Share of `heard` covered by runs of at least `minRun` consecutive words that
|
|
38
|
+
* also appear, in the same order, in `spoken`.
|
|
39
|
+
*/
|
|
40
|
+
export function echoCoverage(heard, spoken, minRun) {
|
|
41
|
+
if (heard.length === 0 || spoken.length === 0)
|
|
42
|
+
return 0;
|
|
43
|
+
const covered = new Array(heard.length).fill(false);
|
|
44
|
+
// run[j]: length of the matching run ending at heard[i] and spoken[j].
|
|
45
|
+
let previous = new Array(spoken.length + 1).fill(0);
|
|
46
|
+
for (let i = 0; i < heard.length; i++) {
|
|
47
|
+
const current = new Array(spoken.length + 1).fill(0);
|
|
48
|
+
for (let j = 0; j < spoken.length; j++) {
|
|
49
|
+
if (!sameWord(heard[i], spoken[j]))
|
|
50
|
+
continue;
|
|
51
|
+
const run = previous[j] + 1;
|
|
52
|
+
current[j + 1] = run;
|
|
53
|
+
if (run >= minRun)
|
|
54
|
+
for (let k = i - run + 1; k <= i; k++)
|
|
55
|
+
covered[k] = true;
|
|
56
|
+
}
|
|
57
|
+
previous = current;
|
|
58
|
+
}
|
|
59
|
+
return covered.filter(Boolean).length / heard.length;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Drops what the recognizer heard when it repeats the bot's own speech (the
|
|
63
|
+
* speaker leaking into the microphone), so the bot does not interrupt or
|
|
64
|
+
* answer itself. It compares words, not audio, so it works with any
|
|
65
|
+
* recognizer, Web Speech included. The decision is all or nothing: a text
|
|
66
|
+
* that is mostly the bot's words is dropped; anything else is kept whole, so
|
|
67
|
+
* a user who quotes the bot while talking over it is never cut short.
|
|
68
|
+
*/
|
|
69
|
+
export function textEchoFilter(options = {}) {
|
|
70
|
+
const threshold = options.threshold ?? 0.6;
|
|
71
|
+
const minRun = Math.max(1, options.minRun ?? 2);
|
|
72
|
+
return {
|
|
73
|
+
name: options.name ?? 'text-echo',
|
|
74
|
+
tail: options.tail ?? 2000,
|
|
75
|
+
filter(input) {
|
|
76
|
+
const heard = wordsOf(input.text);
|
|
77
|
+
// One word cannot be told apart from a user saying the same word.
|
|
78
|
+
if (heard.length < minRun)
|
|
79
|
+
return input.text;
|
|
80
|
+
const spoken = wordsOf(input.speech.map((s) => s.text).join(' '));
|
|
81
|
+
return echoCoverage(heard, spoken, minRun) >= threshold ? '' : input.text;
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
//# sourceMappingURL=echo.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"echo.js","sourceRoot":"","sources":["../../src/providers/echo.ts"],"names":[],"mappings":"AAYA,wFAAwF;AACxF,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,EAAE,CAC/B,IAAI;KACD,SAAS,CAAC,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int. It receives `{ partial, history, language }` and
|
|
5
|
+
* answers with the probability that the user finished, from a classifier
|
|
6
|
+
* (LiveKit turn-detector, a BERT model), a typed-decision model or the LLM.
|
|
7
|
+
* Keys stay on the server.
|
|
8
|
+
*/
|
|
9
|
+
url: string;
|
|
10
|
+
headers?: Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
11
|
+
/** Reads the probability from the JSON response. Default: `probability`, or `done` as 1/0. */
|
|
12
|
+
parse?: (json: any) => number;
|
|
13
|
+
/** Recent turns sent along. Default 6. */
|
|
14
|
+
historyTurns?: number;
|
|
15
|
+
/** Consent purpose required to send the transcript to your backend (ADR 0010). */
|
|
16
|
+
consent?: string;
|
|
17
|
+
fetch?: typeof fetch;
|
|
18
|
+
name?: string;
|
|
19
|
+
};
|
|
20
|
+
/** End-of-turn decided by your backend, over the transcript (ADR 0011). */
|
|
21
|
+
export declare function httpEndOfTurn(options: HttpEndOfTurnOptions): EndOfTurn;
|
|
22
|
+
//# sourceMappingURL=end-of-turn.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"end-of-turn.d.ts","sourceRoot":"","sources":["../../src/providers/end-of-turn.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAkB,MAAM,aAAa,CAAA;AAE5D,MAAM,MAAM,oBAAoB,GAAG;IACjC;;;;;OAKG;IACH,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAA;IACnG,8FAA8F;IAC9F,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,GAAG,KAAK,MAAM,CAAA;IAC7B,0CAA0C;IAC1C,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,kFAAkF;IAClF,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,KAAK,CAAC,EAAE,OAAO,KAAK,CAAA;IACpB,IAAI,CAAC,EAAE,MAAM,CAAA;CACd,CAAA;AAKD,2EAA2E;AAC3E,wBAAgB,aAAa,CAAC,OAAO,EAAE,oBAAoB,GAAG,SAAS,CAuBtE"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const defaultParse = (json) => typeof json?.probability === 'number' ? json.probability : json?.done === true ? 1 : json?.done === false ? 0 : NaN;
|
|
2
|
+
/** End-of-turn decided by your backend, over the transcript (ADR 0011). */
|
|
3
|
+
export function httpEndOfTurn(options) {
|
|
4
|
+
const parse = options.parse ?? defaultParse;
|
|
5
|
+
return {
|
|
6
|
+
name: options.name ?? 'http-end-of-turn',
|
|
7
|
+
input: 'text',
|
|
8
|
+
historyTurns: options.historyTurns ?? 6,
|
|
9
|
+
remote: true,
|
|
10
|
+
consent: options.consent,
|
|
11
|
+
isSupported: () => typeof (options.fetch ?? globalThis.fetch) === 'function',
|
|
12
|
+
async predict(input, signal) {
|
|
13
|
+
const headers = typeof options.headers === 'function' ? await options.headers() : (options.headers ?? {});
|
|
14
|
+
const response = await (options.fetch ?? globalThis.fetch)(options.url, {
|
|
15
|
+
method: 'POST',
|
|
16
|
+
headers: { 'Content-Type': 'application/json', ...headers },
|
|
17
|
+
body: JSON.stringify({ partial: input.partial, history: input.history, language: input.language }),
|
|
18
|
+
signal,
|
|
19
|
+
});
|
|
20
|
+
if (!response.ok)
|
|
21
|
+
throw new Error(`End-of-turn service answered ${response.status}`);
|
|
22
|
+
const probability = parse(await response.json());
|
|
23
|
+
if (!Number.isFinite(probability))
|
|
24
|
+
throw new Error('End-of-turn service sent no probability');
|
|
25
|
+
return Math.max(0, Math.min(1, probability));
|
|
26
|
+
},
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=end-of-turn.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"end-of-tur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AI,CAAC,SAAS,CAAC,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,QAAQ,EAAE,KAAK,CAAC,QAAQ,EAAE,CAAC;gBAClG,MAAM;aACP,CAAC,CAAA;YACF,IAAI,CAAC,QAAQ,CAAC,EAAE;gBAAE,MAAM,IAAI,KAAK,CAAC,gCAAgC,QAAQ,CAAC,MAAM,EAAE,CAAC,CAAA;YACpF,MAAM,WAAW,GAAG,KAAK,CAAC,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC,CAAA;YAChD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,WAAW,CAAC;gBAAE,MAAM,IAAI,KAAK,CAAC,yCAAyC,CAAC,CAAA;YAC7F,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC,CAAA;QAC9C,CAAC;KACF,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { type ProsodySupport, type SpeakOptions, type SpeechAudio, type SpeechToText, type TextToSpeech } from '../types.js';
|
|
2
|
+
type Headers = Record<string, string> | (() => Record<string, string> | Promise<Record<string, string>>);
|
|
3
|
+
export type HttpSTTOptions = {
|
|
4
|
+
/** Your backend endpoint; it proxies the cloud provider so keys never reach the browser. */
|
|
5
|
+
url: string;
|
|
6
|
+
headers?: Headers;
|
|
7
|
+
/** Reads the transcript from the JSON response. Default: `{ text, confidence? }`. */
|
|
8
|
+
parse?: (json: any) => {
|
|
9
|
+
text: string;
|
|
10
|
+
confidence?: number;
|
|
11
|
+
};
|
|
12
|
+
/** Silence that ends an utterance. Default 1200 ms. */
|
|
13
|
+
silenceMs?: number;
|
|
14
|
+
fetch?: typeof fetch;
|
|
15
|
+
name?: string;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Records an utterance and POSTs it (multipart: `audio`, `language`) to your
|
|
19
|
+
* backend. Works with any cloud STT (Whisper, Google, Azure…) behind a proxy.
|
|
20
|
+
*/
|
|
21
|
+
export declare function httpSTT(options: HttpSTTOptions): SpeechToText;
|
|
22
|
+
export type HttpTTSOptions = {
|
|
23
|
+
/** Your backend endpoint: receives `{ text, language, voice, prosody? }`, returns audio (WAV, MP3, Ogg…). */
|
|
24
|
+
url: string;
|
|
25
|
+
headers?: Headers;
|
|
26
|
+
fetch?: typeof fetch;
|
|
27
|
+
name?: string;
|
|
28
|
+
/**
|
|
29
|
+
* The prosody your backend applies (for example as SSML, see `toSSML` in
|
|
30
|
+
* `@handsforbots/voice-effects`). `true` = rate, pitch and volume. What it
|
|
31
|
+
* does not apply, the player does where it can. Default: none, and the body
|
|
32
|
+
* carries no `prosody`.
|
|
33
|
+
*/
|
|
34
|
+
prosody?: boolean | ProsodySupport;
|
|
35
|
+
/** Builds the JSON body. Default `{ text, language, voice, prosody? }`. */
|
|
36
|
+
body?: (text: string, options: SpeakOptions) => unknown;
|
|
37
|
+
/**
|
|
38
|
+
* `webaudio` (default): the voice plugin plays the decoded audio, through the
|
|
39
|
+
* effects. `element`: an `<audio>` element plays it, without effects.
|
|
40
|
+
*/
|
|
41
|
+
playback?: 'webaudio' | 'element';
|
|
42
|
+
};
|
|
43
|
+
/** Decodes an audio file into mono samples (Web Audio). */
|
|
44
|
+
export declare function decodeAudio(bytes: ArrayBuffer): Promise<SpeechAudio>;
|
|
45
|
+
/** Cloud TTS through your backend; the voice plugin plays the returned audio. */
|
|
46
|
+
export declare function httpTTS(options: HttpTTSOptions): TextToSpeech;
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=http.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/providers/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,cAAc,EACnB,KAAK,YAAY,EACjB,KAAK,WAAW,EAChB,KAAK,YAAY,EACjB,KAAK,Y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