Skip to content

Fix voice TTS for AI SDK textStream responses#1462

Merged
whoiskatrin merged 2 commits intomainfrom
fix-voice-ai-sdk-textstream
May 6, 2026
Merged

Fix voice TTS for AI SDK textStream responses#1462
whoiskatrin merged 2 commits intomainfrom
fix-voice-ai-sdk-textstream

Conversation

@whoiskatrin
Copy link
Copy Markdown
Contributor

Summary

Fixes withVoice handling of AI SDK streamText(...).textStream values returned from onTurn().

AI SDK textStream values are dual-protocol objects: they are ReadableStreams and also expose a custom Symbol.asyncIterator that yields string deltas. iterateText() previously checked instanceof ReadableStream first, so these streams could be consumed through the generic stream parser instead of the AI SDK string iterator. That meant assistant text could be persisted while no text reached the sentence chunker/TTS pipeline, producing no spoken audio.

This updates iterateText() to prefer a custom/source-owned async iterator before falling back to ReadableStream parsing, while preserving the existing native ReadableStream<string> and ReadableStream<Uint8Array> SSE/NDJSON paths.

Fixes #1364
Refs #1352

Changes

  • Prefer custom async iterators for dual-protocol text streams in @cloudflare/voice.
  • Keep native ReadableStream parsing behavior intact for string streams and SSE/NDJSON byte streams.
  • Add a regression test for an AI SDK-like dual-protocol stream.
  • Document that AI SDK result.textStream can be returned directly from onTurn().
  • Add a patch changeset for @cloudflare/voice.

Testing

  • npm test -w @cloudflare/voice
  • npm run build
  • npm run check

@changeset-bot
Copy link
Copy Markdown

changeset-bot Bot commented May 5, 2026

🦋 Changeset detected

Latest commit: e06978f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@cloudflare/voice Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Copy Markdown
Contributor

@devin-ai-integration devin-ai-integration Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented May 5, 2026

Open in StackBlitz

agents

npm i https://pkg.pr.new/agents@1462

@cloudflare/ai-chat

npm i https://pkg.pr.new/@cloudflare/ai-chat@1462

@cloudflare/codemode

npm i https://pkg.pr.new/@cloudflare/codemode@1462

hono-agents

npm i https://pkg.pr.new/hono-agents@1462

@cloudflare/shell

npm i https://pkg.pr.new/@cloudflare/shell@1462

@cloudflare/think

npm i https://pkg.pr.new/@cloudflare/think@1462

@cloudflare/voice

npm i https://pkg.pr.new/@cloudflare/voice@1462

@cloudflare/worker-bundler

npm i https://pkg.pr.new/@cloudflare/worker-bundler@1462

commit: e06978f

Copy link
Copy Markdown
Contributor

@mattzcarey mattzcarey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good and makes sense to me

@whoiskatrin whoiskatrin merged commit 5f6214d into main May 6, 2026
4 checks passed
@whoiskatrin whoiskatrin deleted the fix-voice-ai-sdk-textstream branch May 6, 2026 16:29
@github-actions github-actions Bot mentioned this pull request May 6, 2026
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.

withVoice: onTurn returning AI SDK result.textStream produces no TTS audio

2 participants