Skip to content

fix: detect actual audio format for TTS Content-Type instead of assuming mpeg - #39652

Open
SpiliosDimakopoulos wants to merge 11 commits into
langgenius:mainfrom
SpiliosDimakopoulos:fix/tts-content-type-sniff
Open

fix: detect actual audio format for TTS Content-Type instead of assuming mpeg#39652
SpiliosDimakopoulos wants to merge 11 commits into
langgenius:mainfrom
SpiliosDimakopoulos:fix/tts-content-type-sniff

Conversation

@SpiliosDimakopoulos

Copy link
Copy Markdown
Contributor

invoke_tts() returns Iterable[bytes] with no format metadata, but AudioService.transcript_tts always hardcoded content_type="audio/mpeg" on the streamed response, in both places it returns a Generator. If a model/plugin provider streams a different container (WAV, OGG, FLAC), the browser receives a Content-Type that doesn't match the actual bytes, which can break playback.

Added a best-effort sniff of the first response chunk's magic bytes (RIFF/WAVE, OggS, fLaC, ID3 tag or raw MP3 frame sync) to set the correct Content-Type, falling back to the previous audio/mpeg default when the format isn't recognized. This is purely additive — streams that were already being labeled correctly see no behavior change.

Note: I wasn't able to confirm from this repo alone whether a currently-shipped provider plugin returns non-MP3 audio in practice (provider implementations live in the separate plugin repos) — happy to narrow scope if a maintainer says this isn't currently reachable.

…ΘΜΟ>)

'Runing docker container' -> 'Running docker container'.
…ΘΜΟΣ>)

ar-SA: unescape the quick-start-guide link and point it at the real heading slug (#البداية-السريعة). hi-IN: point the community link at the real bilingual heading slug (#समुदाय-और-संपर्क-community--contact). Verified both slugs with github-slugger.
validate_credentials() -> _get_request() called httpx.get() with no explicit timeout, unlike the Jina/Firecrawl/Nacos/Marketplace auth providers which were recently hardened with bounded httpx.Timeout values. A slow or hanging WaterCrawl endpoint could block the worker indefinitely during credential validation.

Updated the existing unit test to assert the new timeout kwarg.
CursorResult.rowcount is sourced directly from the underlying DBAPI driver's cursor.rowcount. PEP 249 recommends -1 for 'unknown', but not all drivers follow that convention -- some return None. messages_deleted was added unguarded into stats['total_deleted'] (an int), which raises TypeError if rowcount comes back None.

Same class of issue already fixed for the workflow bulk-delete methods in langgenius#38054; applying the same 'or 0' guard here.

fixes #<ISSUE_NUMBER>
…ing mpeg

invoke_tts() returns Iterable[bytes] with no format metadata, but AudioService.transcript_tts always hardcoded content_type=audio/mpeg on the streamed response. If a provider streams a different container (WAV/OGG/FLAC), the browser gets a mismatched Content-Type.

Added a best-effort sniff of the first response chunk's magic bytes (RIFF/WAVE, OggS, fLaC, ID3/MP3 frame sync), falling back to the previous audio/mpeg default when unrecognized -- purely additive, no change for streams already labeled correctly.

fixes #<ISSUE_NUMBER>
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Pyrefly Type Coverage

Metric Base PR Delta
Type coverage 55.20% 55.19% -0.01%
Strict coverage 54.71% 54.70% -0.01%
Typed symbols 35,893 35,893 0
Untyped symbols 29,395 29,405 +10
Modules 3078 3078 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant