# MicrophoneAudio

One 20 ms slice of a player's microphone, handed to a MicrophoneTap.

Source: https://socketsvc.vercel.app/zh-TW/api/shared/MicrophoneAudio
<Callout title="Generated from source">
  Record `com.socketsvc.api.MicrophoneAudio` — generated from [MicrophoneAudio.java](https://github.com/HippoDev03/SocketSVC/blob/main/common/core/src/main/java/com/socketsvc/api/MicrophoneAudio.java). Edit the Javadoc in the Java source, then run `pnpm gen:api`.
</Callout>

```java
package com.socketsvc.api;

public record MicrophoneAudio(UUID speaker, long stream, long sequence, boolean startOfStream, byte[] opus, short[] pcm) { ... }
```

One 20 ms slice of a player's microphone, handed to a [`MicrophoneTap`](/api/shared/MicrophoneTap).

**The arrays belong to SocketSVC, not to the tap.** The same instance is passed to every
subscriber and to the relay's own spatial path in turn, so writing into `#opus()` or
`#pcm()` corrupts what the next subscriber - and every listening player - receives. Copy
before keeping either beyond the call. For the same reason this type is a carrier rather than a
value: its generated `equals` and `hashCode` compare the arrays by identity, and
comparing two of these is not a question worth asking.

## Components

| Component | Description |
| --- | --- |
| `UUID speaker` | the player who spoke. Preserved exactly as the relay knows them, so a consumer can attribute audio without a second lookup |
| `long stream` | the sender's stream id; changes when they stop and start talking again |
| `long sequence` | the frame's position within `stream`, counting from zero |
| `boolean startOfStream` | whether this is the first frame of `stream` - a decoder that keeps per-speaker state should reset on it |
| `byte[] opus` | one 20 ms, 48 kHz mono Opus frame, exactly as the client encoded it. Never null |
| `short[] pcm` | the same frame decoded to 960 signed 16-bit samples, or null when this tap subscribed with `MicrophoneTap.Format#OPUS`. SocketSVC decodes once and shares the result with every PCM subscriber rather than each shipping its own decoder |

## Constants

| Constant | Description |
| --- | --- |
| `public static final int FRAME_SAMPLES = 960` | Samples in one 20 ms frame at 48 kHz, mono - the size of `#pcm()` when present. |