Skip to content

fix(streaming): accept bytearray and memoryview audio in stream() - #266

Open
RaphaelFakhri wants to merge 1 commit into
AssemblyAI:masterfrom
RaphaelFakhri:fix/stream-bytes-like-chunks
Open

RaphaelFakhri wants to merge 1 commit into
AssemblyAI:masterfrom
RaphaelFakhri:fix/stream-bytes-like-chunks

Conversation

@RaphaelFakhri

Copy link
Copy Markdown

Summary

RealTimeTranscriber.stream() and AsyncRealTimeTranscriber.stream() only recognize bytes as a single buffer. A bytearray or memoryview falls through to the iterable branch and is enqueued one int at a time. The write thread then raises ValueError: Attempted to send invalid message: <class 'int'>. In the sync client the thread dies silently and no audio is sent. In the async client the write task fails with an unretrieved exception.

Changes

  • stream() accepts bytes, bytearray and memoryview, and copies the latter two to bytes before enqueuing.
  • Iterables (and async iterables) of bytearray or memoryview chunks get the same conversion.
  • The conversion lives in a shared _as_bytes_chunk helper in streaming/v3/_base.py.

This matches how transcribe_live() and the dual-channel streamer already treat bytearray and memoryview.

Testing

  • Added sync tests (test_streaming.py) and async tests (test_streaming_async.py) for a single buffer and an iterable of chunks, parametrized over bytearray and memoryview.
  • Before the change: pytest tests/unit/test_streaming.py tests/unit/test_streaming_async.py -k bytes_like reports 6 failed.
  • After the change: 6 passed. pytest tests/unit reports 739 passed.
  • ruff format --check assemblyai/streaming is clean.

@RaphaelFakhri
RaphaelFakhri force-pushed the fix/stream-bytes-like-chunks branch from 4226746 to f2da806 Compare September 30, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant