Add playback acknowledgement from bot to gateway.
Send ttsPlaybackAck events (queued/completed/failed) from bot and forward them as ttsDeliveryStatus SSE updates for session diagnostics. Made-with: Cursor
This commit is contained in:
parent
5caa5a047e
commit
4437576acc
2 changed files with 42 additions and 3 deletions
|
|
@ -7,7 +7,7 @@ import WebSocket from 'ws';
|
|||
|
||||
import { config } from '../config';
|
||||
import { createSessionLogger } from '../utils/logger';
|
||||
import { BotSession, BotState, TranscriptEntry, StatusMessage, TranscriptMessage, PlayAudioMessage, ChatMessage, SendChatMessage, AudioChunkMessage } from '../types';
|
||||
import { BotSession, BotState, TranscriptEntry, StatusMessage, TranscriptMessage, PlayAudioMessage, ChatMessage, SendChatMessage, AudioChunkMessage, TtsPlaybackAckMessage } from '../types';
|
||||
import { JoinProcedure } from './joinProcedure';
|
||||
import { CaptionsProcedure } from './captionsProcedure';
|
||||
import { AudioProcedure } from './audioProcedure';
|
||||
|
|
@ -843,7 +843,34 @@ export class BotOrchestrator {
|
|||
}
|
||||
}
|
||||
|
||||
await this._audioProcedure.playAudio(audioData, format);
|
||||
this._sendTtsPlaybackAck('queued', format, audioData.length, 'Audio queued for playback');
|
||||
try {
|
||||
await this._audioProcedure.playAudio(audioData, format);
|
||||
this._sendTtsPlaybackAck('completed', format, audioData.length, 'Audio playback completed');
|
||||
} catch (error) {
|
||||
this._sendTtsPlaybackAck('failed', format, audioData.length, String(error));
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
private _sendTtsPlaybackAck(
|
||||
status: 'queued' | 'completed' | 'failed',
|
||||
format: 'mp3' | 'wav' | 'pcm',
|
||||
bytesBase64?: number,
|
||||
message?: string,
|
||||
): void {
|
||||
const ack: TtsPlaybackAckMessage = {
|
||||
type: 'ttsPlaybackAck',
|
||||
sessionId: this._sessionId,
|
||||
playback: {
|
||||
status,
|
||||
format,
|
||||
bytesBase64,
|
||||
message,
|
||||
timestamp: new Date().toISOString(),
|
||||
},
|
||||
};
|
||||
this._sendToGateway(ack);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -73,8 +73,20 @@ export interface AudioChunkMessage {
|
|||
};
|
||||
}
|
||||
|
||||
export interface TtsPlaybackAckMessage {
|
||||
type: 'ttsPlaybackAck';
|
||||
sessionId: string;
|
||||
playback: {
|
||||
status: 'queued' | 'completed' | 'failed';
|
||||
format: 'mp3' | 'pcm' | 'wav';
|
||||
bytesBase64?: number;
|
||||
message?: string;
|
||||
timestamp: string;
|
||||
};
|
||||
}
|
||||
|
||||
export type GatewayToBot = PlayAudioMessage | JoinMeetingMessage | LeaveMeetingMessage | SendChatMessage;
|
||||
export type BotToGateway = TranscriptMessage | StatusMessage | ChatMessage | AudioChunkMessage;
|
||||
export type BotToGateway = TranscriptMessage | StatusMessage | ChatMessage | AudioChunkMessage | TtsPlaybackAckMessage;
|
||||
|
||||
// Bot State
|
||||
export type BotState =
|
||||
|
|
|
|||
Loading…
Reference in a new issue