Documentation
¶
Overview ¶
Package media defines operation-neutral image, audio, and video value types. It deliberately does not depend on the parent inference package.
Index ¶
- func AudioDurationMillis(data []byte, format AudioFormat) (int64, bool)
- type AspectRatio
- type AudioChunk
- type AudioEncoding
- type AudioFormat
- type AudioSource
- func (s AudioSource) BaseMediaType() string
- func (s AudioSource) Bytes() []byte
- func (s AudioSource) Clone() AudioSource
- func (s AudioSource) Kind() SourceKind
- func (s AudioSource) MarshalJSON() ([]byte, error)
- func (s AudioSource) MediaType() string
- func (s AudioSource) Stream() any
- func (s AudioSource) URL() string
- func (s *AudioSource) UnmarshalJSON(data []byte) error
- func (s AudioSource) Validate() error
- type ImageFormat
- type ImageSize
- type ImageSource
- func (s ImageSource) BaseMediaType() string
- func (s ImageSource) Bytes() []byte
- func (s ImageSource) Clone() ImageSource
- func (s ImageSource) Kind() SourceKind
- func (s ImageSource) MarshalJSON() ([]byte, error)
- func (s ImageSource) MediaType() string
- func (s ImageSource) Stream() any
- func (s ImageSource) URL() string
- func (s *ImageSource) UnmarshalJSON(data []byte) error
- func (s ImageSource) Validate() error
- type Pipe
- type SourceKind
- type Stream
- type VideoFrame
- type VideoSource
- func (s VideoSource) BaseMediaType() string
- func (s VideoSource) Bytes() []byte
- func (s VideoSource) Clone() VideoSource
- func (s VideoSource) Kind() SourceKind
- func (s VideoSource) MarshalJSON() ([]byte, error)
- func (s VideoSource) MediaType() string
- func (s VideoSource) Stream() any
- func (s VideoSource) URL() string
- func (s *VideoSource) UnmarshalJSON(data []byte) error
- func (s VideoSource) Validate() error
- type VoiceSpec
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AudioDurationMillis ¶ added in v0.1.3
func AudioDurationMillis(data []byte, format AudioFormat) (int64, bool)
AudioDurationMillis derives the duration of an encoded audio payload in milliseconds when it can be computed without a full decoder. Raw PCM families are exact from the byte count; MPEG audio (mp3) is estimated from its frame headers. ok reports false for encodings that require a real decoder (opus, aac, flac) or for malformed payloads, so callers can distinguish "unknown" from a real zero.
Types ¶
type AspectRatio ¶
type AspectRatio string
func (AspectRatio) Validate ¶
func (r AspectRatio) Validate() error
type AudioChunk ¶
func (AudioChunk) Clone ¶
func (c AudioChunk) Clone() AudioChunk
func (AudioChunk) Validate ¶
func (c AudioChunk) Validate() error
type AudioEncoding ¶
type AudioEncoding string
const ( AudioEncodingPCM16 AudioEncoding = "pcm16" AudioEncodingPCM24 AudioEncoding = "pcm24" AudioEncodingFloat32 AudioEncoding = "float32" AudioEncodingMP3 AudioEncoding = "mp3" AudioEncodingOpus AudioEncoding = "opus" AudioEncodingAAC AudioEncoding = "aac" AudioEncodingFLAC AudioEncoding = "flac" )
func (AudioEncoding) MediaType ¶
func (e AudioEncoding) MediaType() string
type AudioFormat ¶
type AudioFormat struct {
Encoding AudioEncoding `json:"encoding"`
SampleRateHz int `json:"sample_rate_hz,omitempty"`
Channels int `json:"channels,omitempty"`
}
func (AudioFormat) Validate ¶
func (f AudioFormat) Validate() error
type AudioSource ¶
type AudioSource struct {
// contains filtered or unexported fields
}
func NewAudioBytes ¶
func NewAudioBytes(data []byte, mediaType string) (AudioSource, error)
func NewAudioStream ¶ added in v0.1.17
func NewAudioStream[T any](stream Stream[T], mediaType string) (AudioSource, error)
NewAudioStream wraps a live, pull-based stream as an audio source. The stream's item type is caller-defined (the message package instantiates it as message.Stream, i.e. media.Stream[Part]); mediaType declares the audio codec family and is required.
func NewAudioURL ¶
func NewAudioURL(rawURL, mediaType string) (AudioSource, error)
func (AudioSource) BaseMediaType ¶
func (s AudioSource) BaseMediaType() string
func (AudioSource) Clone ¶
func (s AudioSource) Clone() AudioSource
func (AudioSource) Kind ¶
func (s AudioSource) Kind() SourceKind
func (AudioSource) MarshalJSON ¶
func (AudioSource) Stream ¶ added in v0.1.17
func (s AudioSource) Stream() any
Stream returns the live item stream carried by a stream-kind source, or nil for URL and inline sources. The concrete item type is caller-defined; a message.Stream caller asserts the returned handle to message.Stream.
func (*AudioSource) UnmarshalJSON ¶
func (s *AudioSource) UnmarshalJSON(data []byte) error
func (AudioSource) Validate ¶
func (s AudioSource) Validate() error
type ImageFormat ¶
type ImageFormat string
const ( ImageFormatPNG ImageFormat = "png" ImageFormatJPEG ImageFormat = "jpeg" ImageFormatWebP ImageFormat = "webp" ImageFormatGIF ImageFormat = "gif" ImageFormatAVIF ImageFormat = "avif" )
func (ImageFormat) MediaType ¶
func (f ImageFormat) MediaType() string
func (ImageFormat) Validate ¶
func (f ImageFormat) Validate() error
type ImageSource ¶
type ImageSource struct {
// contains filtered or unexported fields
}
func NewImageBytes ¶
func NewImageBytes(data []byte, mediaType string) (ImageSource, error)
func NewImageURL ¶
func NewImageURL(rawURL, mediaType string) (ImageSource, error)
func (ImageSource) BaseMediaType ¶
func (s ImageSource) BaseMediaType() string
func (ImageSource) Clone ¶
func (s ImageSource) Clone() ImageSource
func (ImageSource) Kind ¶
func (s ImageSource) Kind() SourceKind
func (ImageSource) MarshalJSON ¶
func (ImageSource) Stream ¶ added in v0.1.17
func (s ImageSource) Stream() any
Stream returns the live item stream carried by a stream-kind source, or nil for URL and inline sources. The concrete item type is caller-defined; a message.Stream caller asserts the returned handle to message.Stream.
func (*ImageSource) UnmarshalJSON ¶
func (s *ImageSource) UnmarshalJSON(data []byte) error
func (ImageSource) Validate ¶
func (s ImageSource) Validate() error
type Pipe ¶ added in v0.1.17
type Pipe[T any] struct { // contains filtered or unexported fields }
Pipe is the standard implementation of Stream[T]: a typed, bounded pipe with explicit normal-close and interrupt semantics.
Producers call Send; it blocks when the buffer is full, which is how backpressure propagates from a slow consumer. Consumers call Read. Close ends the stream normally (Read drains buffered items, then returns io.EOF). Interrupt aborts the stream: Read returns context.Canceled immediately, even when buffered items remain.
func NewPipe ¶ added in v0.1.17
NewPipe creates a buffered Pipe with the given capacity. bufferSize must be non-negative.
func (*Pipe[T]) Close ¶ added in v0.1.17
func (p *Pipe[T]) Close()
Close signals normal end of stream. After all buffered values are consumed, Read returns io.EOF. Safe to call multiple times (idempotent via sync.Once).
func (*Pipe[T]) Interrupt ¶ added in v0.1.17
func (p *Pipe[T]) Interrupt()
Interrupt signals abnormal end of stream. Read returns context.Canceled immediately, even if buffered values remain. Idempotent.
func (*Pipe[T]) Read ¶ added in v0.1.17
Read returns the next value from the pipe.
- Returns io.EOF after Close once all buffered values are consumed.
- Returns context.Canceled immediately after Interrupt, skipping buffered values.
- Returns ctx.Err() when the caller's context is canceled. This is a per-call cancellation: the stream itself stays usable.
After Read returns a stream-level error (io.EOF or context.Canceled), all subsequent Read calls return the same error.
type SourceKind ¶
type SourceKind string
const ( SourceURL SourceKind = "url" SourceInline SourceKind = "inline" // SourceStream marks a live, pull-based source of typed items (see // [Stream]). It is the transport form of a media part: valid while a // message is in flight, never in durable context or history — callers // materialize it (message.MaterializeContent) before storage. SourceStream SourceKind = "stream" )
func (SourceKind) Validate ¶
func (k SourceKind) Validate() error
type Stream ¶ added in v0.1.17
Stream is a pull-based source of typed items.
Contract:
- Read returns (value, nil) for each available item.
- Read returns (zero, io.EOF) when the stream ends normally.
- Read returns (zero, err) when the stream is interrupted or the caller's context is canceled.
- After returning a non-nil error caused by the stream itself (EOF or interrupt), all subsequent Read calls return the same error.
The item type is instantiated by the owner of the stream: the message package exposes Stream[Part] as the canonical live-content transport.
type VideoFrame ¶
type VideoFrame struct {
Source ImageSource `json:"source"`
TimestampMillis int64 `json:"timestamp_millis,omitempty"`
}
VideoFrame is a timestamped image frame for live multimodal input. Complete video-generation request and response types are intentionally out of scope.
func (VideoFrame) Clone ¶
func (f VideoFrame) Clone() VideoFrame
func (VideoFrame) Validate ¶
func (f VideoFrame) Validate() error
type VideoSource ¶
type VideoSource struct {
// contains filtered or unexported fields
}
func NewVideoBytes ¶
func NewVideoBytes(data []byte, mediaType string) (VideoSource, error)
func NewVideoStream ¶ added in v0.1.17
func NewVideoStream[T any](stream Stream[T], mediaType string) (VideoSource, error)
NewVideoStream wraps a live, pull-based stream as a video source. The stream's item type is caller-defined; mediaType declares the video container family and is required.
func NewVideoURL ¶
func NewVideoURL(rawURL, mediaType string) (VideoSource, error)
func (VideoSource) BaseMediaType ¶
func (s VideoSource) BaseMediaType() string
func (VideoSource) Clone ¶
func (s VideoSource) Clone() VideoSource
func (VideoSource) Kind ¶
func (s VideoSource) Kind() SourceKind
func (VideoSource) MarshalJSON ¶
func (VideoSource) Stream ¶ added in v0.1.17
func (s VideoSource) Stream() any
Stream returns the live item stream carried by a stream-kind source, or nil for URL and inline sources. The concrete item type is caller-defined; a message.Stream caller asserts the returned handle to message.Stream.
func (*VideoSource) UnmarshalJSON ¶
func (s *VideoSource) UnmarshalJSON(data []byte) error
func (VideoSource) Validate ¶
func (s VideoSource) Validate() error