Skip to content
Merged
Show file tree
Hide file tree
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
14 changes: 10 additions & 4 deletions src/websocket/bot-conversation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ export class BotConversationWebSocket extends EventEmitter2 implements BotConver
case VaicToBotMessageName.userStreamStart:
this.userAudio = new PassThrough();
this.emit('userStream', this.userAudio, { message: msgJson });
await this.send(BotToVaicMessageName.userStreamStarted);
await this.send(BotToVaicMessageName.userStreamStarted, { participant: msgJson.participant });
break;
case VaicToBotMessageName.userStreamChunk:
this.userAudio?.write(Buffer.from(msgJson.audioChunk!, 'base64'));
break;
case VaicToBotMessageName.userStreamStop:
this.#log('user stream stopped');
this.userAudio?.end();
await this.send(BotToVaicMessageName.userStreamStopped);
await this.send(BotToVaicMessageName.userStreamStopped, { participant: msgJson.participant });
delete this.userAudio;
break;
case VaicToBotMessageName.activities:
Expand Down Expand Up @@ -191,23 +191,29 @@ export class BotConversationWebSocket extends EventEmitter2 implements BotConver
}
}

sendHypothesis(text: string) {
sendHypothesis(text: string, participant?: string) {
return this.send(BotToVaicMessageName.userStreamSpeechHypothesis, {
participant,
alternatives: [{
text: text.toLowerCase()
}]
});
}

sendRecognition(text: string, confidence: number) {
sendRecognition(text: string, confidence: number, participant?: string) {
return this.send(BotToVaicMessageName.userStreamSpeechRecognition, {
participant,
alternatives: [{
text: text.toLowerCase(),
confidence
}]
});
}

sendCommitted(participant?: string) {
return this.send(BotToVaicMessageName.userStreamSpeechCommitted, { participant });
}

async playTextMessage(text: string, params?: Record<string, unknown>) {
return this.sendActivity({
type: BotActivityType.message,
Expand Down
1 change: 1 addition & 0 deletions src/websocket/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export interface ProtocolMessage extends PlayAudioOptions {
expectAudioMessages?: boolean;
supportedMediaFormats?: string[];
caller?: string;
participant?: string
activities?: BotActivity[];
audioChunk?: string;
[key: string]: unknown;
Expand Down