Documentation / guides
AudioBlock
Represent audio input with a MIME type and owned bytes.
AudioBlock is the binary audio variant in the core content vocabulary. It keeps the provider-neutral shape small: a MIME type and the bytes to encode.
API surface
type AudioBlock struct {
MediaType MediaType
Data []byte
}
Current named audio constants include MediaTypeAudioMPEG, MediaTypeAudioWAV, MediaTypeAudioOGG, MediaTypeAudioFLAC, MediaTypeAudioAAC, MediaTypeAudioMP4, and MediaTypeAudioWebM. MediaType is an open string type, so a future or provider-specific MIME value can be carried without changing the core package.
Example and ownership
package main
import "github.com/looprig/core/content"
func main() {
pcm := []byte{0x52, 0x49, 0x46, 0x46}
block := &content.AudioBlock{
MediaType: content.MediaTypeAudioWAV,
Data: pcm,
}
_ = content.Block(block)
}
The struct literal stores the slice header supplied by the caller. If the bytes must remain stable across an asynchronous request, copy them before constructing the block. MarshalBlock encodes and UnmarshalBlock allocates a fresh *AudioBlock; malformed bytes return a typed *content.BlockDecodeError.
Proof
Related: ImageBlock, DocumentBlock.