Skip to content

Commit

Permalink
Merge branch 'main' into psalas/fixie-cli-default-parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
petersalas authored Nov 20, 2023
2 parents 6c1f2c6 + 16869b1 commit 8a33a09
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions packages/voice/src/app/agent/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,8 @@ export class WebRtcChatManager implements ChatManager {
console.log('[chat] got mic stream');
this.inAnalyzer = new StreamAnalyzer(this.audioContext, this.localAudioTrack!.mediaStream!);
this.pinger = setInterval(() => {
var obj = { type: 'ping', timestamp: performance.now() };
this.room?.localParticipant.publishData(this.textEncoder.encode(JSON.stringify(obj)), DataPacket_Kind.RELIABLE);
const obj = { type: 'ping', timestamp: performance.now() };
this.sendData(obj);
}, 5000);
this.maybePublishLocalAudio();
this.changeState(ChatManagerState.LISTENING);
Expand All @@ -608,7 +608,9 @@ export class WebRtcChatManager implements ChatManager {
this.changeState(ChatManagerState.IDLE);
}
interrupt() {
throw new Error('Method not implemented.');
console.log('[chat] interrupting');
const obj = { type: 'interrupt' };
this.sendData(obj);
}
private changeState(state: ChatManagerState) {
if (state != this._state) {
Expand All @@ -624,6 +626,9 @@ export class WebRtcChatManager implements ChatManager {
this.room.localParticipant.publishTrack(this.localAudioTrack, opts);
}
}
private sendData(obj: any) {
this.room?.localParticipant.publishData(this.textEncoder.encode(JSON.stringify(obj)), DataPacket_Kind.RELIABLE);
}
private handleSocketOpen() {
console.log('[chat] socket opened');
const obj = {
Expand Down Expand Up @@ -678,6 +683,13 @@ export class WebRtcChatManager implements ChatManager {
if (data.type === 'pong') {
const elapsed_ms = performance.now() - data.timestamp;
console.debug(`[chat] worker RTT: ${elapsed_ms.toFixed(0)} ms`);
} else if (data.type === 'state') {
const newState = data.state;
this.changeState(newState);
} else if (data.type === 'transcript') {
console.log(`[chat] transcript: ${data.text}`);
} else if (data.type === 'output') {
console.log(`[chat] output: ${data.text}`);
}
}
}
Expand Down

0 comments on commit 8a33a09

Please sign in to comment.