You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
TTS WebSocket session mutates flush_id/cancel state on failed sends, lacks async send lock, and allows encoding="mp3" #304
Three issues found while auditing assemblyai.tts.v1 WebSocket sessions (TTSSession and AsyncTTSSession):
flush() and cancel() mutate session state before _send() succeeds
assemblyai/tts/v1/session.py:330-350 and assemblyai/tts/v1/async_session.py:260-275 increment _next_flush_id and update _cancel_ids / _cancelled_beforebefore calling _send(...).
If _send() raises (for example, RuntimeError or ConnectionClosed), the mutated counters stay corrupted. (By contrast, assemblyai-node-sdk calls this.send(...) first so a refused send changes nothing.)
Sync TTSSession guards sends and flush_id allocation with self._send_lock (session.py:155) so flush_ids follow wire order.
AsyncTTSSession (async_session.py:254-275) has no asyncio.Lock, so concurrent coroutines calling generate() / flush() / cancel() can assign flush_ids out of wire order.
check_session_config() accepts encoding="mp3" for /v1/ws
assemblyai/tts/_base_ws.py:163-170 rejects container="wav" and bit_rate with a message stating sessions stream "raw pcm_s16le, pcm_mulaw or pcm_alaw", but does not reject encoding=TTSEncoding.mp3 / "mp3".
build_uri(...) builds wss://tts.us.assemblyai.com/v1/ws?encoding=mp3&word_boundaries=false, which /v1/ws rejects.
(Minor docs note)assemblyai/tts/v1/models.py:141,150,230 states the default voice is aai-jane, while live POST /v1/speech defaults to aai-kyla.
Suggested Fix
Send the WebSocket frame before mutating _next_flush_id, _cancel_ids, and _cancelled_before.
Add an asyncio.Lock to AsyncTTSSession mirroring TTSSession._send_lock.
Reject config.encoding in (TTSEncoding.mp3, "mp3") in check_session_config().
Activity
test(tts): cover failed sends and mp3 rejection