Codex.Voice.Input.StreamedAudioInput (Codex SDK v0.7.2)

Copy Markdown View Source

A streaming audio input that can be appended to.

Uses an Agent-backed queue for audio chunks. This allows you to push audio data to the input while the pipeline consumes it.

Example

input = StreamedAudioInput.new()

# Producer task
Task.async(fn ->
  for chunk <- audio_source do
    StreamedAudioInput.add(input, chunk)
  end
  StreamedAudioInput.close(input)
end)

# Consumer
for chunk <- StreamedAudioInput.stream(input) do
  process(chunk)
end

Summary

Functions

Add an audio chunk to the stream.

Close the stream, signaling no more data will be added.

Get the next chunk from the stream.

Create a new streamed audio input.

Stream audio chunks until the stream is closed.

Types

t()

@type t() :: %Codex.Voice.Input.StreamedAudioInput{queue: pid()}

Functions

add(streamed_audio_input, data)

@spec add(t(), binary()) :: :ok

Add an audio chunk to the stream.

Examples

iex> input = Codex.Voice.Input.StreamedAudioInput.new()
iex> Codex.Voice.Input.StreamedAudioInput.add(input, <<0, 0>>)
:ok

close(streamed_audio_input)

@spec close(t()) :: :ok

Close the stream, signaling no more data will be added.

After calling close, consumers will receive :eof after consuming all remaining chunks.

get(streamed_audio_input)

@spec get(t()) :: {:ok, binary()} | :eof | :empty

Get the next chunk from the stream.

Returns:

  • {:ok, binary} - The next audio chunk
  • :eof - The stream has been closed
  • :empty - No data currently available (try again later)

new()

@spec new() :: t()

Create a new streamed audio input.

Starts a stream queue process to manage the audio chunk queue.

stream(input)

@spec stream(t()) :: Enumerable.t()

Stream audio chunks until the stream is closed.

This returns a Stream that yields audio chunks as they become available, completing when the stream is closed.

Note: If the stream is empty and not closed, this will poll with a 10ms delay. For high-performance use cases, consider using get/1 directly with your own polling strategy.