feat(voice): add audio cues for session lifecycle
Introduce VoiceCueService to play 'ready' and 'end' audio cues during voice stream sessions. This provides auditory feedback when a session starts and concludes.
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
VoiceSessionEnd,
|
||||
VoiceStreamState,
|
||||
} from './voice-stream.types';
|
||||
import { VoiceCueService } from './voice-cue.service';
|
||||
|
||||
export type VoiceStartFailure =
|
||||
| 'cancelled'
|
||||
@@ -115,6 +116,7 @@ export class VoiceStreamService {
|
||||
private readonly api = inject(VoiceApiService);
|
||||
private readonly config = inject(VOICE_STREAM_CONFIG);
|
||||
private readonly createTransport = inject(VOICE_TRANSPORT_FACTORY);
|
||||
private readonly cues = inject(VoiceCueService);
|
||||
|
||||
readonly state = signal<VoiceStreamState>('IDLE');
|
||||
readonly connection = signal<VoiceConnection>('disconnected');
|
||||
@@ -289,6 +291,8 @@ export class VoiceStreamService {
|
||||
this.connection.set('connected');
|
||||
this.state.set('LISTENING');
|
||||
this.streaming = true;
|
||||
// "You can speak now" — once per session, not per turn (a turn cue would be noise).
|
||||
this.cues.playReady();
|
||||
return { ok: true };
|
||||
}
|
||||
|
||||
@@ -805,6 +809,13 @@ export class VoiceStreamService {
|
||||
// Stop admitting new media BEFORE any await.
|
||||
this.streaming = false;
|
||||
|
||||
// "Call finished" — once per connected session, before local resources (including the
|
||||
// engine AudioContext) are released; every end path funnels through this single-flight
|
||||
// cleanup, so ordered and unordered teardown both trigger it exactly once.
|
||||
if (wasConnected) {
|
||||
this.cues.playEnd();
|
||||
}
|
||||
|
||||
const release = (): void => {
|
||||
// A newer session may have taken over during an await: never touch its resources.
|
||||
if (superseded()) return;
|
||||
|
||||
Reference in New Issue
Block a user