@rimori/react-client 0.4.7 → 0.4.8
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/dist/components/ai/Avatar.d.ts +2 -1
- package/dist/components/ai/Avatar.js +2 -2
- package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.d.ts +3 -2
- package/dist/components/ai/EmbeddedAssistent/TTS/MessageSender.js +3 -2
- package/dist/components/audio/Playbutton.d.ts +1 -0
- package/dist/components/audio/Playbutton.js +2 -2
- package/package.json +3 -3
- package/src/components/ai/Avatar.tsx +6 -1
- package/src/components/ai/EmbeddedAssistent/TTS/MessageSender.ts +5 -3
- package/src/components/audio/Playbutton.tsx +3 -1
|
@@ -2,6 +2,7 @@ import { Tool } from '@rimori/client';
|
|
|
2
2
|
import { FirstMessages } from './utils';
|
|
3
3
|
interface Props {
|
|
4
4
|
voiceId: string;
|
|
5
|
+
cache?: boolean;
|
|
5
6
|
agentTools: Tool[];
|
|
6
7
|
avatarImageUrl: string;
|
|
7
8
|
circleSize?: string;
|
|
@@ -9,5 +10,5 @@ interface Props {
|
|
|
9
10
|
autoStartConversation?: FirstMessages;
|
|
10
11
|
className?: string;
|
|
11
12
|
}
|
|
12
|
-
export declare function Avatar({ avatarImageUrl, voiceId, agentTools, autoStartConversation, children, circleSize, className, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
13
|
+
export declare function Avatar({ avatarImageUrl, voiceId, agentTools, autoStartConversation, children, circleSize, className, cache, }: Props): import("react/jsx-runtime").JSX.Element;
|
|
13
14
|
export {};
|
|
@@ -7,12 +7,12 @@ import { useChat } from '../../hooks/UseChatHook';
|
|
|
7
7
|
import { useRimori } from '../../providers/PluginProvider';
|
|
8
8
|
import { getFirstMessages } from './utils';
|
|
9
9
|
import { useTheme } from '../../hooks/ThemeSetter';
|
|
10
|
-
export function Avatar({ avatarImageUrl, voiceId, agentTools, autoStartConversation, children, circleSize = '300px', className, }) {
|
|
10
|
+
export function Avatar({ avatarImageUrl, voiceId, agentTools, autoStartConversation, children, circleSize = '300px', className, cache = false, }) {
|
|
11
11
|
const { ai, event, plugin } = useRimori();
|
|
12
12
|
const { isDark: isDarkThemeValue } = useTheme(plugin.theme);
|
|
13
13
|
const [agentReplying, setAgentReplying] = useState(false);
|
|
14
14
|
const [isProcessingMessage, setIsProcessingMessage] = useState(false);
|
|
15
|
-
const sender = useMemo(() => new MessageSender((...args) => ai.getVoice(...args), voiceId), [voiceId]);
|
|
15
|
+
const sender = useMemo(() => new MessageSender((...args) => ai.getVoice(...args), voiceId, cache), [voiceId, ai, cache]);
|
|
16
16
|
const { messages, append, isLoading, lastMessage, setMessages } = useChat(agentTools);
|
|
17
17
|
useEffect(() => {
|
|
18
18
|
console.log('messages', messages);
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
type VoiceBackend = (text: string, voice?: string, speed?: number) => Promise<Blob>;
|
|
1
|
+
type VoiceBackend = (text: string, voice?: string, speed?: number, language?: string, cache?: boolean) => Promise<Blob>;
|
|
2
2
|
export declare class MessageSender {
|
|
3
3
|
private player;
|
|
4
4
|
private fetchedSentences;
|
|
5
5
|
private lastLoading;
|
|
6
6
|
private voice;
|
|
7
7
|
private voiceBackend;
|
|
8
|
-
|
|
8
|
+
private cache;
|
|
9
|
+
constructor(voiceBackend: VoiceBackend, voice: string, cache?: boolean);
|
|
9
10
|
private getCompletedSentences;
|
|
10
11
|
handleNewText(currentText: string | undefined, isLoading: boolean): Promise<void>;
|
|
11
12
|
private generateSpeech;
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { ChunkedAudioPlayer } from './Player';
|
|
11
11
|
export class MessageSender {
|
|
12
|
-
constructor(voiceBackend, voice) {
|
|
12
|
+
constructor(voiceBackend, voice, cache = false) {
|
|
13
13
|
this.player = new ChunkedAudioPlayer();
|
|
14
14
|
this.fetchedSentences = new Set();
|
|
15
15
|
this.lastLoading = false;
|
|
@@ -18,6 +18,7 @@ export class MessageSender {
|
|
|
18
18
|
}
|
|
19
19
|
this.voiceBackend = voiceBackend;
|
|
20
20
|
this.voice = voice;
|
|
21
|
+
this.cache = cache;
|
|
21
22
|
}
|
|
22
23
|
getCompletedSentences(currentText, isLoading) {
|
|
23
24
|
// Split the text based on the following characters: .?!
|
|
@@ -62,7 +63,7 @@ export class MessageSender {
|
|
|
62
63
|
}
|
|
63
64
|
generateSpeech(sentence) {
|
|
64
65
|
return __awaiter(this, void 0, void 0, function* () {
|
|
65
|
-
const blob = yield this.voiceBackend(sentence, this.voice, 1.0);
|
|
66
|
+
const blob = yield this.voiceBackend(sentence, this.voice, 1.0, undefined, this.cache);
|
|
66
67
|
return yield blob.arrayBuffer();
|
|
67
68
|
});
|
|
68
69
|
}
|
|
@@ -14,7 +14,7 @@ import { useRimori } from '../../providers/PluginProvider';
|
|
|
14
14
|
import { EventBus } from '@rimori/client';
|
|
15
15
|
export const AudioPlayOptions = [0.8, 0.9, 1.0, 1.1, 1.2, 1.5];
|
|
16
16
|
let isFetchingAudio = false;
|
|
17
|
-
export const AudioPlayer = ({ text, voice, language, hide, playListenerEvent, initialSpeed = 1.0, playOnMount = false, enableSpeedAdjustment = false, }) => {
|
|
17
|
+
export const AudioPlayer = ({ text, voice, language, hide, playListenerEvent, initialSpeed = 1.0, playOnMount = false, enableSpeedAdjustment = false, cache = true, }) => {
|
|
18
18
|
const [audioUrl, setAudioUrl] = useState(null);
|
|
19
19
|
const [speed, setSpeed] = useState(initialSpeed);
|
|
20
20
|
const [isPlaying, setIsPlaying] = useState(false);
|
|
@@ -33,7 +33,7 @@ export const AudioPlayer = ({ text, voice, language, hide, playListenerEvent, in
|
|
|
33
33
|
// Function to generate audio from text using API
|
|
34
34
|
const generateAudio = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
35
35
|
setIsLoading(true);
|
|
36
|
-
const blob = yield ai.getVoice(text, voice || (language ? 'aws_default' : 'openai_alloy'), 1, language);
|
|
36
|
+
const blob = yield ai.getVoice(text, voice || (language ? 'aws_default' : 'openai_alloy'), 1, language, cache);
|
|
37
37
|
setAudioUrl(URL.createObjectURL(blob));
|
|
38
38
|
setIsLoading(false);
|
|
39
39
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rimori/react-client",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.8",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"format": "prettier --write ."
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
|
-
"@rimori/client": "^2.5.
|
|
26
|
+
"@rimori/client": "^2.5.13",
|
|
27
27
|
"react": "^18.1.0",
|
|
28
28
|
"react-dom": "^18.1.0"
|
|
29
29
|
},
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
36
|
"@eslint/js": "^9.37.0",
|
|
37
|
-
"@rimori/client": "^2.5.
|
|
37
|
+
"@rimori/client": "^2.5.13",
|
|
38
38
|
"@types/react": "^18.3.21",
|
|
39
39
|
"eslint-config-prettier": "^10.1.8",
|
|
40
40
|
"eslint-plugin-prettier": "^5.5.4",
|
|
@@ -11,6 +11,7 @@ import { useTheme } from '../../hooks/ThemeSetter';
|
|
|
11
11
|
|
|
12
12
|
interface Props {
|
|
13
13
|
voiceId: string;
|
|
14
|
+
cache?: boolean;
|
|
14
15
|
agentTools: Tool[];
|
|
15
16
|
avatarImageUrl: string;
|
|
16
17
|
circleSize?: string;
|
|
@@ -27,12 +28,16 @@ export function Avatar({
|
|
|
27
28
|
children,
|
|
28
29
|
circleSize = '300px',
|
|
29
30
|
className,
|
|
31
|
+
cache = false,
|
|
30
32
|
}: Props) {
|
|
31
33
|
const { ai, event, plugin } = useRimori();
|
|
32
34
|
const { isDark: isDarkThemeValue } = useTheme(plugin.theme);
|
|
33
35
|
const [agentReplying, setAgentReplying] = useState(false);
|
|
34
36
|
const [isProcessingMessage, setIsProcessingMessage] = useState(false);
|
|
35
|
-
const sender = useMemo(
|
|
37
|
+
const sender = useMemo(
|
|
38
|
+
() => new MessageSender((...args) => ai.getVoice(...args), voiceId, cache),
|
|
39
|
+
[voiceId, ai, cache],
|
|
40
|
+
);
|
|
36
41
|
const { messages, append, isLoading, lastMessage, setMessages } = useChat(agentTools);
|
|
37
42
|
|
|
38
43
|
useEffect(() => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { ChunkedAudioPlayer } from './Player';
|
|
2
2
|
|
|
3
|
-
type VoiceBackend = (text: string, voice?: string, speed?: number) => Promise<Blob>;
|
|
3
|
+
type VoiceBackend = (text: string, voice?: string, speed?: number, language?: string, cache?: boolean) => Promise<Blob>;
|
|
4
4
|
|
|
5
5
|
export class MessageSender {
|
|
6
6
|
private player = new ChunkedAudioPlayer();
|
|
@@ -8,13 +8,15 @@ export class MessageSender {
|
|
|
8
8
|
private lastLoading = false;
|
|
9
9
|
private voice: string;
|
|
10
10
|
private voiceBackend: VoiceBackend;
|
|
11
|
+
private cache: boolean;
|
|
11
12
|
|
|
12
|
-
constructor(voiceBackend: VoiceBackend, voice: string) {
|
|
13
|
+
constructor(voiceBackend: VoiceBackend, voice: string, cache = false) {
|
|
13
14
|
if (voice?.split('_').length !== 2) {
|
|
14
15
|
throw new Error("Invalid voice id format '" + voice + "'. Voice id needs to look like <provider>_<voice_id>");
|
|
15
16
|
}
|
|
16
17
|
this.voiceBackend = voiceBackend;
|
|
17
18
|
this.voice = voice;
|
|
19
|
+
this.cache = cache;
|
|
18
20
|
}
|
|
19
21
|
|
|
20
22
|
private getCompletedSentences(currentText: string, isLoading: boolean): string[] {
|
|
@@ -62,7 +64,7 @@ export class MessageSender {
|
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
private async generateSpeech(sentence: string): Promise<ArrayBuffer> {
|
|
65
|
-
const blob = await this.voiceBackend(sentence, this.voice, 1.0);
|
|
67
|
+
const blob = await this.voiceBackend(sentence, this.voice, 1.0, undefined, this.cache);
|
|
66
68
|
return await blob.arrayBuffer();
|
|
67
69
|
}
|
|
68
70
|
|
|
@@ -6,6 +6,7 @@ import { EventBus } from '@rimori/client';
|
|
|
6
6
|
type AudioPlayerProps = {
|
|
7
7
|
text: string;
|
|
8
8
|
voice?: string;
|
|
9
|
+
cache?: boolean;
|
|
9
10
|
language?: string;
|
|
10
11
|
hide?: boolean;
|
|
11
12
|
playOnMount?: boolean;
|
|
@@ -28,6 +29,7 @@ export const AudioPlayer: React.FC<AudioPlayerProps> = ({
|
|
|
28
29
|
initialSpeed = 1.0,
|
|
29
30
|
playOnMount = false,
|
|
30
31
|
enableSpeedAdjustment = false,
|
|
32
|
+
cache = true,
|
|
31
33
|
}) => {
|
|
32
34
|
const [audioUrl, setAudioUrl] = useState<string | null>(null);
|
|
33
35
|
const [speed, setSpeed] = useState(initialSpeed);
|
|
@@ -48,7 +50,7 @@ export const AudioPlayer: React.FC<AudioPlayerProps> = ({
|
|
|
48
50
|
const generateAudio = async () => {
|
|
49
51
|
setIsLoading(true);
|
|
50
52
|
|
|
51
|
-
const blob = await ai.getVoice(text, voice || (language ? 'aws_default' : 'openai_alloy'), 1, language);
|
|
53
|
+
const blob = await ai.getVoice(text, voice || (language ? 'aws_default' : 'openai_alloy'), 1, language, cache);
|
|
52
54
|
setAudioUrl(URL.createObjectURL(blob));
|
|
53
55
|
setIsLoading(false);
|
|
54
56
|
};
|