@rimori/client 2.5.51 → 2.5.52
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.
|
@@ -12,12 +12,14 @@ export declare class ChunkedAudioPlayer {
|
|
|
12
12
|
private currentIndex;
|
|
13
13
|
private startedPlaying;
|
|
14
14
|
private onEndOfSpeech;
|
|
15
|
+
private onChunkStart;
|
|
15
16
|
private readonly backgroundNoiseLevel;
|
|
16
17
|
private currentSource;
|
|
17
18
|
private stopped;
|
|
18
19
|
constructor();
|
|
19
20
|
private init;
|
|
20
21
|
setOnLoudnessChange(callback: (value: number) => void): void;
|
|
22
|
+
setOnChunkStart(callback: (index: number) => void): void;
|
|
21
23
|
setVolume(volume: number): void;
|
|
22
24
|
addChunk(chunk: ArrayBuffer, position: number): Promise<void>;
|
|
23
25
|
private playChunks;
|
|
@@ -12,6 +12,7 @@ export class ChunkedAudioPlayer {
|
|
|
12
12
|
currentIndex = 0;
|
|
13
13
|
startedPlaying = false;
|
|
14
14
|
onEndOfSpeech = () => { };
|
|
15
|
+
onChunkStart = () => { };
|
|
15
16
|
backgroundNoiseLevel = 30; // Background noise level that should be treated as baseline (0)
|
|
16
17
|
currentSource = null;
|
|
17
18
|
stopped = false;
|
|
@@ -28,6 +29,9 @@ export class ChunkedAudioPlayer {
|
|
|
28
29
|
setOnLoudnessChange(callback) {
|
|
29
30
|
this.loudnessCallback = callback;
|
|
30
31
|
}
|
|
32
|
+
setOnChunkStart(callback) {
|
|
33
|
+
this.onChunkStart = callback;
|
|
34
|
+
}
|
|
31
35
|
setVolume(volume) {
|
|
32
36
|
this.volume = volume;
|
|
33
37
|
}
|
|
@@ -125,6 +129,7 @@ export class ChunkedAudioPlayer {
|
|
|
125
129
|
this.analyser.connect(this.audioContext.destination);
|
|
126
130
|
source.start(0);
|
|
127
131
|
gainNode.gain.value = this.volume;
|
|
132
|
+
this.onChunkStart(this.currentIndex);
|
|
128
133
|
source.onended = () => {
|
|
129
134
|
if (this.currentSource === source) {
|
|
130
135
|
this.currentSource = null;
|
|
@@ -2,6 +2,7 @@ type VoiceBackend = (text: string, voice?: string, speed?: number, language?: st
|
|
|
2
2
|
export declare class MessageSender {
|
|
3
3
|
private player;
|
|
4
4
|
private fetchedSentences;
|
|
5
|
+
private sentenceByIndex;
|
|
5
6
|
private lastLoading;
|
|
6
7
|
private voice;
|
|
7
8
|
private voiceBackend;
|
|
@@ -20,6 +21,8 @@ export declare class MessageSender {
|
|
|
20
21
|
setVolume(volume: number): void;
|
|
21
22
|
setOnLoudnessChange(callback: (value: number) => void): void;
|
|
22
23
|
setOnEndOfSpeech(callback: () => void): void;
|
|
24
|
+
/** Fired with the sentence text as it starts being audible, so a caller can render live captions. */
|
|
25
|
+
setOnSentenceChange(callback: (sentence: string) => void): void;
|
|
23
26
|
setVoiceSpeed(speed: number): void;
|
|
24
27
|
}
|
|
25
28
|
export {};
|
|
@@ -2,6 +2,9 @@ import { ChunkedAudioPlayer } from './ChunkedAudioPlayer';
|
|
|
2
2
|
export class MessageSender {
|
|
3
3
|
player = new ChunkedAudioPlayer();
|
|
4
4
|
fetchedSentences = new Set();
|
|
5
|
+
// Sentence text queued at each chunk index, so the player's currentIndex can be resolved
|
|
6
|
+
// back to the sentence currently audible (see setOnSentenceChange).
|
|
7
|
+
sentenceByIndex = [];
|
|
5
8
|
lastLoading = false;
|
|
6
9
|
voice;
|
|
7
10
|
voiceBackend;
|
|
@@ -50,6 +53,7 @@ export class MessageSender {
|
|
|
50
53
|
const sentence = sentences[i];
|
|
51
54
|
if (!this.fetchedSentences.has(sentence)) {
|
|
52
55
|
this.fetchedSentences.add(sentence);
|
|
56
|
+
this.sentenceByIndex[i] = sentence;
|
|
53
57
|
const audioData = await this.generateSpeech(sentence);
|
|
54
58
|
await this.player.addChunk(audioData, i);
|
|
55
59
|
}
|
|
@@ -74,6 +78,7 @@ export class MessageSender {
|
|
|
74
78
|
reset() {
|
|
75
79
|
this.stop();
|
|
76
80
|
this.fetchedSentences.clear();
|
|
81
|
+
this.sentenceByIndex = [];
|
|
77
82
|
this.player.reset();
|
|
78
83
|
}
|
|
79
84
|
setVolume(volume) {
|
|
@@ -87,6 +92,14 @@ export class MessageSender {
|
|
|
87
92
|
setOnEndOfSpeech(callback) {
|
|
88
93
|
this.player.setOnEndOfSpeech(callback);
|
|
89
94
|
}
|
|
95
|
+
/** Fired with the sentence text as it starts being audible, so a caller can render live captions. */
|
|
96
|
+
setOnSentenceChange(callback) {
|
|
97
|
+
this.player.setOnChunkStart((index) => {
|
|
98
|
+
const sentence = this.sentenceByIndex[index];
|
|
99
|
+
if (sentence)
|
|
100
|
+
callback(sentence);
|
|
101
|
+
});
|
|
102
|
+
}
|
|
90
103
|
setVoiceSpeed(speed) {
|
|
91
104
|
this.voiceSpeed = speed;
|
|
92
105
|
}
|