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
@RaphaelFakhri
RaphaelFakhri force-pushed the fix/stream-bytes-like-chunks branch 2 times, most recently from ab9993b to 1ec5e65 Compare October 23, 2026 15:39
@RaphaelFakhri

Copy link
Copy Markdown
Author

Rebased onto current master to resolve the version conflict; the version is now 1.8.1. The streaming unit tests pass.

@RaphaelFakhri

Copy link
Copy Markdown
Author

Rebased onto current master again; the version is now 1.8.3, following the 1.8.2 release. The unit tests pass.

@RaphaelFakhri
RaphaelFakhri force-pushed the fix/stream-bytes-like-chunks branch from 1ec5e65 to 35310d0 Compare October 24, 2026 16:10
@RaphaelFakhri
RaphaelFakhri force-pushed the fix/stream-bytes-like-chunks branch from 35310d0 to 82693b3 Compare October 28, 2026 15:16
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