Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions libs/react-client/src/useChatSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ import {
firstUserInteraction,
isAiSpeakingState,
loadingState,
modesState,
mcpState,
messagesState,
modesState,
resumeThreadErrorState,
sessionIdState,
sessionState,
Expand All @@ -40,8 +40,8 @@ import {
IAction,
ICommand,
IElement,
IMode,
IMessageElement,
IMode,
IStep,
ITasklistElement,
IThread
Expand Down Expand Up @@ -217,20 +217,31 @@ const useChatSession = () => {
let isFirstChunk = true;
const startTime = Date.now();
const mimeType = 'pcm16';
// Connect to microphone
await wavRecorder.begin();
await wavStreamPlayer.connect();
await wavRecorder.record(async (data) => {
const elapsedTime = Date.now() - startTime;
socket.emit('audio_chunk', {
isStart: isFirstChunk,
mimeType,
elapsedTime,
data: data.mono
try {
await wavRecorder.begin();
await wavStreamPlayer.connect();
await wavRecorder.record(async (data) => {
const elapsedTime = Date.now() - startTime;
socket.emit('audio_chunk', {
isStart: isFirstChunk,
mimeType,
elapsedTime,
data: data.mono
});
isFirstChunk = false;
});
isFirstChunk = false;
});
wavStreamPlayer.onStop = () => setIsAiSpeaking(false);
wavStreamPlayer.onStop = () => setIsAiSpeaking(false);
} catch {
try {
await wavRecorder.end();
} catch {
// ignored
}
await wavStreamPlayer.interrupt();
socket.emit('audio_end');
setAudioConnection('off');
return;
}
} else {
await wavRecorder.end();
await wavStreamPlayer.interrupt();
Expand Down
Loading