Read-aloud paces synthesis by segments in the Client
朗读在 Client 侧按段控制合成节奏
Users asked for assistant replies to be read aloud. DeepSeek publishes speech synthesis as `POST /v1/tools/tts` and as a WebSocket on the same path. The API bills every character it is given, where a Chinese character counts two, and synthesizes many times faster than a voice reads. A reading that submits a whole reply and is stopped after a few sentences therefore pays for the entire reply. The DeepSeek chat service
Source compatibility: Chinese title uses a compatible non-canonical header; Chinese status uses a compatible non-canonical header
English
Problem
Users asked for assistant replies to be read aloud. DeepSeek publishes speech synthesis as POST /v1/tools/tts and as a WebSocket on the same path. The API bills every character it is given, where a Chinese character counts two, and synthesizes many times faster than a voice reads. A reading that submits a whole reply and is stopped after a few sentences therefore pays for the entire reply.
The DeepSeek chat service avoids this in its own backend: its Client reports playback progress, and the backend submits text to the synthesis vendor only as playback advances. The public API has no progress report, so it submits whatever it receives at once. Its backend documentation states that text handed to the vendor is billed even when the request is cancelled. The backend team decided not to change the public protocol and asked DSH to pace on its side with the public API.
Decision
DSH paces by segments, and the browser decides when the next one is due. The Host cuts a reply's read-aloud text into segments and synthesizes exactly one segment per request with POST /v1/tools/tts. The Client requests the next segment once the audio it has received has at most dispatchBelowSeconds left to play. Stopping cancels the request in flight and submits nothing further, so the cost of an early stop is bounded by the segments already requested: at most one segment plus dispatchBelowSeconds of audio beyond what was heard.
This is the chat backend's current scheme, segment dispatch, moved to where the playback position is known. That backend gives every segment its own vendor session, closes a segment at a sentence end by estimated spoken length, and dispatches the next one when unplayed audio falls to a low watermark. One public API call is one vendor session, so one request per segment is the same unit. DSH keeps that backend's estimate (200 ms for an ideograph or digit, 70 ms for another letter, 300 ms for a sentence end, 150 ms for a clause mark), its closing rule (a sentence end at the target, a clause mark at 1.5 times, anywhere at twice, a short remainder absorbed) and its low watermark of 15 seconds.
Segments target 30 seconds each by default, where the chat backend uses 30 seconds for the first segment and 60 for later ones. One value is one setting to explain, and a shorter later segment lowers the cost of a late stop at the price of more requests. segmentSeconds and dispatchBelowSeconds are configuration of the read-aloud row.
The Host owns text and credentials. It finds the reply by message identity in the stored Session log, converts Markdown to speech text itself, and sends that text with filter_markdown: false. The Host must know exactly which characters are spoken to estimate length, and a segment made only of a code block would otherwise be billed as a request that the service rejects for having nothing to read. The Client receives ranges and audio, never text, and the Host accepts only ranges that are segments of the named message.
The interface is one control in the message action row, as in the chat app: a speaker, a loading mark until sound, and a waveform while reading. It appears only while a credential is available. Failures are reported in a toast, and a failure that may pass leaves the reading resumable at the failed segment, so the listener does not pay again for what was already heard.
The voice is a saved preference. The synthesis API offers two voices; the bundle's details list them beside a control that plays a fixed sample sentence. The choice is saved in the registry's profile entry, as voice input saves its language, and a plan fixes the voice for its whole reading, so a reply is never read in two voices.
Alternatives considered
Submitting the whole reply in one request is the simplest use of the API and is the case the pacing exists to avoid.
Feeding one WebSocket session sentence by sentence was rejected. The session ends after 60 seconds without text, so a wait between sentences has a deadline. With the service's Markdown filter a paragraph is released only at a blank line, and fragments without punctuation wait for later text. The chat backend itself keeps continuous submission into one session only as a fallback that configuration enables per vendor.
Pacing in the Host was rejected because the playback position exists only in the browser; it would need the progress reports that the chat protocol carries and the public API was not given.
Automatic reconnection and resumption after a network drop, which the chat backend supports with frame sequence numbers and a retention window, were left out: a failed segment is requested again by the next click.
Consequences
A segment border is a new synthesis request, so intonation restarts there. A reading makes several requests, each counted against the account's concurrency limit of the synthesis API one at a time. The segment estimate is not measured audio; real segment lengths differ by voice and language. A reply that the service ends cleanly before all audio was sent cannot be detected, because the PCM stream carries no length. Reading while a reply is still streaming, automatic reading of new replies, pause and speed are not part of this decision. The API accepts neither a language nor a speech rate, so the interface offers neither.
中文
问题
用户希望能朗读助手回复。DeepSeek 以 POST /v1/tools/tts 和同一路径上的 WebSocket 提供语音合成。接口对收到的每个字符计费,一个汉字计 2,而合成速度是朗读速度的许多倍。因此,把整条回复一次提交、听了几句就停止的朗读,要为整条回复付费。
DeepSeek chat 服务在自己的后端避免了这个问题:它的 Client 上报播放进度,后端只随播放进度向合成供应商提交文本。公开接口没有进度上报,收到多少文本就立即提交多少。其后端文档写明,已交给供应商的文本即使请求被取消也会计费。后端团队决定不调整公开协议,并要求 DSH 基于公开接口在自己这一侧控速。
决策
DSH 按段控速,由浏览器决定下一段何时到期。Host 把回复的朗读文本切成段,每次请求用 POST /v1/tools/tts 恰好合成一段。Client 在已收到的音频剩余可播放时长不超过 dispatchBelowSeconds 时请求下一段。停止会取消进行中的请求,并且不再提交任何内容,所以提前停止的代价以已请求的段为限:超出已听部分的音频至多是一段加上 dispatchBelowSeconds。
这就是 chat 后端当前的方案「按段调度」,只是移到了知道播放位置的地方。该后端为每一段使用独立的供应商会话,按估算朗读时长在句末收段,并在未播放的音频降到低水位时派发下一段。公开接口的一次调用就是一个供应商会话,所以每段一次请求是同一个单位。DSH 沿用该后端的估算(表意文字或数字 200 毫秒,其他字母 70 毫秒,句末 300 毫秒,分句标点 150 毫秒)、收段规则(达到目标后在句末收段,1.5 倍后在分句标点处,2 倍后在任意位置,较短的剩余部分并入前一段)和 15 秒的低水位。
每段的目标时长默认都是 30 秒,而 chat 后端第一段用 30 秒、之后用 60 秒。只有一个值就只需要解释一项设置;后面的段更短,较晚停止时的代价更低,换来的是更多的请求。segmentSeconds 与 dispatchBelowSeconds 是 read-aloud 行的配置。
Host 拥有文本和凭据。它按消息标识在已存储的 Session 日志中找到回复,自己把 Markdown 转成朗读文本,并以 filter_markdown: false 发送。Host 必须确切知道哪些字符会被读出来才能估算时长;否则,只含代码块的一段会被当作一次请求计费,却因没有可读内容被服务拒绝。Client 收到的是区间和音频,从不收到文本;Host 只接受属于所指消息的段的区间。
界面是消息操作栏中的一个按钮,与 chat 应用一致:喇叭、出声前的加载标记,以及朗读时的波形。只有凭据可用时才显示。失败通过弹出提示报告;可能恢复的失败会让朗读保持可从失败的那一段继续,听者不必为已经听过的部分再次付费。
音色是保存的偏好。合成接口提供两个音色;Bundle 详情列出它们,旁边的按钮用一句固定的话试听。选择保存在注册表的 profile 条目里,和语音输入保存语言的方式相同;朗读计划在生成时确定整次朗读的音色,所以一条回复不会用两种声音读出。
考虑过的替代方案
把整条回复放在一次请求里提交,是接口最简单的用法,也正是控速要避免的情况。
用一条 WebSocket 会话逐句发送被否决。会话在 60 秒没有文本后结束,所以句与句之间的等待有期限。开启服务端的 Markdown 过滤时,段落要到空行才被释放,没有标点的片段要等后续文本。chat 后端自己也只把持续向一个会话提交文本的方式保留为回退,由配置按供应商启用。
在 Host 侧控速被否决,因为播放位置只存在于浏览器;这需要 chat 协议携带、而公开接口没有的进度上报。
断网后的自动重连和续传没有纳入,chat 后端通过帧序号和保留窗口支持它:失败的段由下一次点击重新请求。
影响
段的边界是一次新的合成请求,所以语调在那里重新起头。一次朗读会发出多个请求,它们逐个计入账号在合成接口上的并发限制。段的估算不是实测音频,实际段长随音色和语种变化。服务在音频没有发完时正常结束响应,这种情况无法检测,因为 PCM 流不带长度。回复仍在流式生成时朗读、自动朗读新回复、暂停和语速,都不属于这项决策。合成接口不接受语种,也不接受语速,所以界面不提供这两项。