如何診斷語音合成延遲 303 秒
How to Diagnose 303-Second Speech Synthesis Delays
語音合成在部分測試中只需 0.7–1.3 秒,另一些則耗時 48–303 秒;作者將語音合成模型切回先前使用的版本後,約 40 次實測均在 0.8–2.2 秒內完成。另一問題是模型連續拒絕兩個設定欄位後,重試次數不足令首句沒有回覆;修正後,測試確認移除兩個欄位並在第三次請求取得回覆。
📝 Originally published (in Japanese) at forge.workstyle.tech.
TL;DR The reply text arrived quickly, but speech synthesis took as long as 303 seconds. Measurements that day ranged from 0.7–1.3 seconds to 48–303 seconds, with slow runs making up more than half. After reverting to the previous model, about 40 runs took 0.8–2.2 seconds.
Summary
Speech synthesis took 0.7–1.3 seconds in some runs and 48–303 seconds in others, even when measured on the same day; more than half of the runs were slow. After switching back to the model I had used before, about 40 runs took 0.8–2.2 seconds. In a separate issue, retries stopped after two consecutive rejections of unsupported settings fields. After fixing the issue, tests confirmed that a response arrived on the third attempt.
Why Was Text Fast While Audio Lagged?
I compared the time taken by speech synthesis with the time taken to recognize speech and generate a reply. The sentences I measured were 90–175 bytes long (a unit of data size). During the same period, speech recognition took 0.6–1.0 seconds, and reply generation took 0.7–1.9 seconds. After the reply text arrived, speech synthesis was the only step that made me wait a long time before hearing the audio.
I sent a request to the speech synthesis service from within the app and waited for a response. There was no record of the app slowing things down while I waited. I had no evidence that I could reduce the wait time on the app side.
The service status page showed normal operations that day, but that didn’t match the delays I was experiencing on my device. So I reverted the settings and decided to measure again on the actual device.
How Many Seconds Did Speech Synthesis Take After I Switched Back to the Old Model?
I switched my speech synthesis model back to one I had used before. In the roughly 40 runs after switching, every result was between 0.8 and 2.2 seconds. Based on those results, I also reverted the settings I use for conversation. In this round of measurements, the experience went from waiting several minutes to getting back to a normal conversational pace.
However, these were real-world measurements taken on the same device, with the same key, on the same day. These results alone don’t show that the speed will be the same in every environment.
I thought I had resolved one cause of pauses in conversation. But later that same day, I noticed another kind of silence. This one wasn’t caused by speech synthesis latency.
Why Didn’t the First Utterance Get a Response?
When I spoke to the conversation model with two unusable settings fields configured, it didn’t respond to my first utterance. When I sent it, the model rejected the first field as unusable. The app removed that field and sent the request again. Sending a failed request again is called a retry.
Next, the model rejected the other field too. The previous mechanism only retried once, so processing stopped there. The first utterance was still met with silence.
At first, I almost thought this was the same problem as when audio is delayed. But this happens before text-to-speech is called: the response itself hasn’t been generated. The two silences occurred at different stages.
The fix retries the request after removing each field the model rejects. In the issue I reproduced on a real device, retrying after both the first and second rejections lets the app respond to the first utterance.
For the test, I used a mock server that rejects the two fields in sequence. The first field is rejected on the initial request, and the second field on the next. On the third request, both fields have been removed, and a response comes back. If a request fails after any text has already been returned, the app doesn’t retry, to avoid displaying the same text twice. Retries are capped at eight.
How to Tell Slow Audio from a Stalled Reply
This time, I nearly treated two kinds of “no response” as the same thing. In one case, speech synthesis took time even after the text reply arrived. In the other, generation stopped midway after two consecutive rejections of unavailable fields.
After restoring the speech synthesis settings, I measured about 0.8–2.2 seconds across roughly 40 runs on the actual device. After fixing the retry logic, tests confirmed that a reply came through on the third send, with the two fields removed. The speed measured on the actual device and the response confirmed by tests are separate records.
When a conversation stalls, I look separately at how long it takes for the text to arrive and how long it takes for the audio to arrive. If the reply itself was never generated, I check how many retries happened after the send was rejected.
I restored the speech synthesis settings and fixed the retry count. The silence looked similar, but the point where things stalled was different.
Key takeaways
- Compare the time until reply text arrives with the time until audio arrives.
- If speech synthesis is slow, revert to the previous model and measure again.
- If there is no reply, check whether a settings field was rejected and whether the app retried.
- Test retries by rejecting two fields in sequence and checking whether the third send returns a reply.
來源:DEV Community · dev.to