Workspace/Coding labs
Loading progress

Reduce interrupted audio playback events

Intermediate45 min

Implement replay_audio(events), a teaching reducer returning active, queued, and heard state for start, chunk, play, and interrupt events.

Your task

  1. start sets a non-None response ID and clears unplayed queued chunks.
  2. chunk appends text only when its response matches the active non-None response.
  3. play moves up to count queued chunks to heard; reject negative count.
  4. interrupt clears queued chunks and active response but preserves heard chunks. Reject unknown event types.

Examples

EXAMPLE 1

Inputstart r1; chunk hello; play 1; interrupt; late chunk r1

Output{'active': None, 'queued': [], 'heard': ['hello']}

Playback history survives; old response data cannot re-enter the queue.
solution.pyPython 3.12