End-side large model tts first frame low delay generation method and device
By listening to LLM streaming prefix events, triggering TTS background prefetching and synthesis, and utilizing a multi-level caching mechanism and synthesis lock, the problem of high latency in the first frame of TTS in the edge voice robot was solved, achieving fast and complete voice output and improving the user experience.
Patent Information
- Application Number
- CN202611512609.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-09-28
- Publication Date
- 2026-11-27
AI Technical Summary
In existing edge-side voice robot technologies, the first frame generation delay of TTS is relatively long, the first sentence prefix generated in the early stage of LLM is not utilized, and the overhead of resource preemption and cold start is high, resulting in excessively long user waiting time.
By listening to LLM streaming prefix events, the TTS backend prefetch synthesis is triggered. A multi-level caching mechanism and synthesis lock are used, along with priority hit judgment, to achieve parallel inference of TTS prefix audio and subsequent LLM token generation. This avoids the processing logic of waiting for the complete text to arrive before starting synthesis in traditional solutions.
It significantly reduces the time required to generate the first frame of TTS, improves the probability of cache hits, ensures the speed and completeness of voice output, and improves the user's waiting experience.
Smart Images

Figure CN123182671A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of edge voice interaction technology, and in particular to a method and apparatus for generating the first frame of a large-scale edge TTS with low latency. Background Technology
[0002] Edge-based voice robots typically consist of three sequential stages: speech recognition, language model generation, and speech synthesis. As the capabilities of edge-based large models have improved, language models can output the first batch of tokens earlier in a streaming manner. However, TTS still often only begins synthesis after receiving a complete sentence, resulting in a longer time for users to hear the first audio frame.
[0003] Existing streaming TTS technologies mainly focus on splitting complete text into multiple substrings for synthesis, or using ordinary buffering for playback during the synthesis process.
[0004] These include: The patent number is CN116018639B. This solution discloses a streaming text molecular string synthesis (TTS) method, which mainly solves the problems of text segmentation and streaming synthesis.
[0005] The patent number is CN113129861B. This solution discloses the use of offline audio after the first frame times out, and its core is the timeout fallback.
[0006] The patent number is CN101114446B. This solution discloses an embedded TTS dual-buffered playback, which focuses on playback buffering.
[0007] The patent number is CN111179973A. This scheme discloses the evaluation of TTS quality using the delayed frame ratio. This document involves evaluation metrics.
[0008] This type of solution can reduce the time required to generate the entire audio segment, but it still has the following problems in edge robot scenarios: 1. LLM had already generated predictable first-sentence prefixes in its early stages, but TTS did not utilize these prefixes to start synthesis in advance.
[0009] 2. In the robot's spoken responses, complete sentences are not necessarily repeated, but the opening phrases or fixed beginnings of stories are highly repeated, and the cache hit rate of ordinary complete text is low.
[0010] 3. On the client side, LLM and TTS usually share the same GPU, and there is resource contention in the first sentence stage, with obvious jitter in the first packet of TTS.
[0011] 4. When using file-block streaming TTS, reading audio blocks by polling at fixed intervals will introduce additional waiting time.
[0012] 5. For large model TTS or TensorRTTTS, if the model or process is started with each request, the initial cold start overhead is relatively high.
[0013] Therefore, a low-latency TTS first frame generation method is needed for the actual link of the end-side voice robot, so that the first playable audio block of TTS can reach the playback queue or remote client as early as possible without changing the semantic quality of LLM. Summary of the Invention
[0014] The purpose of this invention is to at least address one of the shortcomings of the prior art by providing a method and apparatus for generating the first frame of a large-scale TTS model on the end side with low latency.
[0015] To achieve the above objectives, the present invention adopts the following technical solution: Specifically, a low-latency generation method for the first frame of a large-scale TTS model on the device side is proposed, including the following: Step 110: Obtain the text chunks generated by the LLM streaming method, and continuously append the text chunks to the sentence buffer (sentence_buffer); Step 120: Determine whether the current sentence_buffer meets the prefix triggering condition. If it meets the prefix triggering condition, publish the first event. If it does not meet the prefix triggering condition, return to step 110 for execution. The first event carries the task_id task identifier, the user_id user identifier, and the first sentence text after removing leading and trailing whitespace. Step 130: When the first event is detected, read the text keys of the static phrase audio cache and the dynamic prefix audio cache as candidate phrases, and perform normalized longest prefix matching on the first sentence text and each candidate phrase; if a match is found, use the matched text key as a prefetchable phrase, perform TTS synthesis on the prefetchable phrase in advance, and write the obtained prefix audio into the prefetch cache in the task with task_id as the key; if no match is found, return to step 110 to execute. Step 140: Determine whether the current sentence_buffer meets the TTS segmentation conditions. If it does not meet the TTS segmentation conditions, return to step 110. If it meets the TTS segmentation conditions, publish a second event. The second event carries task_id, user_id, segmented text to be synthesized, streaming tag, segment number, and whether it is the final segment tag. Step 150: When the second event is detected, the priority of the full text audio cache, the in-task prefetch cache, the static phrase audio cache, and the dynamic prefix audio cache is determined in sequence, and multiple audio block events are processed and output according to the determination results. Each audio block event carries at least the task_id, the PCM audio sample array, and the output sampling rate. Step 160: Send all audio block event inputs to the playback queue or remote audio transmission link for output playback.
[0016] Furthermore, specifically, the prefix triggering conditions include, The current LLM output is characterized by the following conditions: the first sentence is 0, the sentence_count == 0 is true, the sentence_buffer has not yet detected any punctuation at the end of the sentence, the length of the prefix text after removing whitespace reaches the preset minimum event length, and the release cycle condition is met. The punctuation at the end of the sentence includes Chinese punctuation and English punctuation. Decimal points after numbers are not recognized as punctuation at the end of the sentence. The release cycle condition is that the length of the prefix text is an integer multiple of the preset step size.
[0017] Furthermore, specifically, the normalized longest prefix matching includes, Remove the trailing punctuation from the text keys of the first sentence text, the static phrase audio cache, and the dynamic prefix audio cache, and then perform the longest prefix matching. When multiple text keys match successfully, select the text key with the longest character length as the prefetchable phrase, and verify that the same task_id task is submitted only once to avoid the same dialogue task from repeatedly initiating prefetch synthesis.
[0018] Furthermore, the method also includes acquiring a TTS synthesis lock before obtaining the prefix audio based on the prefetchable phrase. The TTS synthesis lock is used to ensure that only one prefix audio synthesis task is allowed to enter GPU inference at any given time.
[0019] Furthermore, specifically, the TTS segmentation conditions include, sentence_buffer recognizes sentence-ending punctuation or newline characters; Or, for the first sentence, the sentence_buffer reaches the preset minimum segmentation length and can be segmented at the preset segmentable punctuation. If no segmentable punctuation is found, the text continues to accumulate until a segmentable punctuation is found. Or for subsequent segments that are not the first sentence, if the segmented text is too short and does not reach the preset minimum segment length and is not a newline or the final segment, then the text continues to accumulate until the preset minimum segment length is reached. After all LLM streaming output has finished, for any remaining text, if it is not empty, it will be sent as the last segment; if all segments are filtered out because they are too short but the complete reply is not empty, the complete reply will be sent as the fallback segment.
[0020] Furthermore, the method also includes a GPU scheduling step: LLM and TTS share the edge GPU resources. In the first sentence stage, after the second event is published, the LLM thread suspends subsequent token generation and waits for the first audio block event to be received or for a timeout before resuming LLM generation. During this period, control is achieved through the TTS synthesis lock. The update synthesis of the dynamic prefix audio cache is only performed in the background when the system is idle and does not preempt real-time dialogue GPU resources.
[0021] Furthermore, specifically, the system prioritizes and determines which audio block events are cached in the order of full text audio cache, in-task prefetch cache, static phrase audio cache, and dynamic prefix audio cache, and then processes and outputs multiple audio block events based on the determination results. Step 151: First, determine whether the complete text audio buffer is hit. If the complete text audio buffer is hit, read the complete PCM audio, output the audio block event, and go to step 160. Step 152: If the complete text audio cache is not hit, determine whether there is a prefetch item corresponding to the current task_id in the prefetch cache within the task, and verify whether the current segmented text starts with the prefix text recorded by the prefetch item; only if both are satisfied is it determined that the prefetch cache within the task has been hit, read and output the prefix audio, extract the remaining text from the segmented text after removing the matching prefix text, perform streaming synthesis on the remaining text and output the corresponding audio block event, and go to step 160; if the verification fails, discard the prefetch item and continue to step 153; Step 153: If the prefetch cache within the task is not hit, determine whether the static phrase audio cache or the dynamic prefix audio cache is hit; if the static phrase audio cache or the dynamic prefix audio cache is hit, read the prefix audio in the cache, first output the audio block event corresponding to the prefix audio, extract the remaining text from the segmented text after removing the matching prefix text, perform streaming synthesis on the remaining text to generate the remaining audio block, output the audio block event corresponding to the remaining audio block, and go to step 160. Step 154: If the complete text audio cache, in-task prefetch cache, static phrase audio cache, and dynamic prefix audio cache are all missed, then call the resident TTS inference service to perform regular streaming synthesis on the current segmented text, generate all audio blocks, and output the audio block events corresponding to all audio blocks.
[0022] Furthermore, specifically, methods for determining whether a static phrase audio cache or a dynamic prefix audio cache has been hit include: First, determine if the static phrase audio cache has been hit. The process is as follows: If the segmented text is exactly the same as the static cache key, then a full hit occurs; Otherwise, iterate through the static cache phrases and perform the longest prefix match with suffix removed and normalized. Select the audio corresponding to the phrase with the longest matching length as the static phrase audio cache hit result; If the above process fails to match, the static phrase audio cache is not hit, and the following dynamic prefix audio cache hit judgment is performed: The dynamic prefix audio cache is queried in the manner described above. If a hit result is found, the audio corresponding to the hit result is taken as the dynamic prefix audio cache hit result. If no hit result is found, the dynamic prefix audio cache is determined to have missed.
[0023] Furthermore, specifically, the resident TTS inference service includes any of the following methods: The first type is a persistent model object within the Python process: the model remains resident on the GPU after loading and the streaming synthesis interface is called directly. The second type is Tensor RT TTS daemon: The TTS engine, vocoder, and speaker encoder are started as resident processes, and the main application submits synthesis tasks through request files, standard input / output, or local communication interfaces.
[0024] The third type is g RPC resident service: the main application sends synthesis requests and receives streaming audio responses via Unix domain sockets or local ports.
[0025] This invention also proposes a device for low-latency generation of the first frame of a large-scale end-to-end TTS model, comprising the following: The data acquisition module is used to acquire text chunks generated by LLM streaming and continuously append the text chunks to the sentence buffer (sentence_buffer). The first judgment module is used to determine whether the current sentence_buffer meets the prefix triggering condition. If the prefix triggering condition is met, the first event is published. If the prefix triggering condition is not met, the data acquisition module is returned to execute. The first event carries the task_id task identifier, the user_id user identifier, and the first sentence text after removing leading and trailing whitespace. The second judgment module, when the first event is detected, reads the text keys of the static phrase audio cache and the dynamic prefix audio cache as candidate phrases, and performs normalized longest prefix matching on the first sentence text and each candidate phrase; if a match is found, the matched text key is used as a prefetchable phrase, TTS synthesis is performed on the prefetchable phrase in advance, and the obtained prefix audio is written into the prefetch cache in the task with task_id as the key; if no match is found, the process returns to the data acquisition module for execution. The third judgment module is used to determine whether the current sentence_buffer meets the TTS segmentation conditions. If it does not meet the TTS segmentation conditions, it returns to step 110 for execution. If it meets the TTS segmentation conditions, it publishes a second event. The second event carries task_id, user_id, segmented text to be synthesized, streaming tag, segmentation number and whether it is the final segmentation tag. The fourth judgment module is used to, when the second event is detected, perform priority hit judgment in the order of complete text audio cache, task prefetch cache, static phrase audio cache, and dynamic prefix audio cache, and process and output multiple audio block events according to the judgment results. Each audio block event carries at least task_id, PCM audio sample array and output sampling rate. The audio output module is used to send all audio block event inputs to the playback queue or a remote audio transmission link for output playback.
[0026] The beneficial effects of this invention are as follows: This invention proposes a method and apparatus for low-latency generation of the first frame of a large-scale end-to-end TTS model. Before the LLM generates a complete sentence, the TTS background prefetch synthesis is triggered by listening to the LLM streaming prefix event. The reasoning process of the TTS prefix audio and the subsequent generation of LLM tokens are executed in parallel. This changes the traditional solution that must wait for the complete TTS segment text to arrive before starting the synthesis process. It effectively compresses the generation time of the first TTS frame and reduces the end-to-end response latency of the terminal voice interaction. A multi-level caching routing mechanism is adopted, which includes full text audio caching, in-task prefetching caching, static prefix audio caching, and dynamic prefix audio caching, no longer relying solely on full response text caching. In response to the business characteristics of robot dialogue where the overall response is not repeated but the opening phrases of the dialogue are frequently repeated, the probability of cache hit is greatly improved. In the case of cache hit, the synthesized audio can be directly reused, avoiding the overhead of repeated TTS inference and further reducing the latency of the first frame output. When a prefix-type cache is hit, a two-stage output mode is adopted: "output the cached prefix audio first, and then continue to synthesize the remaining text in a streaming manner". This not only enables the rapid output of the first frame of audio, but also continues to synthesize the subsequent text in a streaming manner, ensuring the correctness and completeness of the complete speech output content, and will not truncate the broadcast content in pursuit of low latency. In summary, this invention can significantly improve the user's waiting experience when hearing the first voice without reducing the semantic output quality of large models. Attached Figure Description
[0027] The above and other features of this disclosure will become more apparent from the detailed description of the embodiments illustrated in conjunction with the accompanying drawings. In the accompanying drawings, the same reference numerals denote the same or similar elements. Obviously, the drawings described below are merely some embodiments of this disclosure. For those skilled in the art, other drawings can be obtained from these drawings without any creative effort. In the drawings: Figure 1 The flowchart shown is a low-latency generation method for the first frame of a large-scale TTS model on the end side according to the present invention. Detailed Implementation
[0028] The following will provide a clear and complete description of the concept, specific structure, and technical effects of the present invention in conjunction with embodiments and accompanying drawings, so as to fully understand the purpose, solution, and effects of the present invention. It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. The same reference numerals used throughout the accompanying drawings indicate the same or similar parts.
[0029] Example 1, referring to Figure 1 This invention proposes a low-latency generation method for the first frame of a large-scale end-to-end TTS model, comprising the following: Step 110: Obtain the text chunks generated by the LLM streaming method, and continuously append the text chunks to the sentence buffer (sentence_buffer); Step 120: Determine whether the current sentence_buffer meets the prefix triggering condition. If it meets the prefix triggering condition, publish the first event. If it does not meet the prefix triggering condition, return to step 110 for execution. The first event (LLM_STREAMING_PREFIX event) carries the task_id task identifier, user_id user identifier, and the first sentence text after removing leading and trailing whitespace. Step 130: When the first event is detected, read the text keys of the static phrase audio cache and the dynamic prefix audio cache as candidate phrases, and perform normalized longest prefix matching on the first sentence text and each candidate phrase; if a match is found, use the matched text key as a prefetchable phrase, perform TTS synthesis on the prefetchable phrase in advance, and write the obtained prefix audio into the prefetch cache in the task with task_id as the key; if no match is found, return to step 110 to execute. Step 140: Determine whether the current sentence_buffer meets the TTS segmentation conditions. If it does not meet the TTS segmentation conditions, return to step 110. If it meets the TTS segmentation conditions, publish a second event. The second event carries task_id, user_id, segmented text to be synthesized, streaming tag, segment number, and whether it is the final segment tag. Step 150: When the second event (TSS_STREAM event) is detected, the priority of the full text audio cache, the in-task prefetch cache, the static phrase audio cache, and the dynamic prefix audio cache is determined in sequence, and multiple audio block events are processed and output according to the determination results. Each audio block event carries at least the task_id, the PCM audio sample array, and the output sampling rate. Step 160: Send all audio block event inputs to the playback queue or remote audio transmission link for output playback.
[0030] In this embodiment 1, before the LLM generates a complete sentence, the TTS background prefetch synthesis is triggered by listening to the LLM streaming prefix event. The reasoning process of the TTS prefix audio and the subsequent generation of LLM tokens are executed in parallel. This changes the traditional solution's processing logic that must wait for the complete TTS segment text to arrive before starting the synthesis, effectively compressing the generation time of the first TTS frame and reducing the end-to-end response latency of the terminal voice interaction. A multi-level caching routing mechanism is adopted, which includes full text audio caching, in-task prefetching caching, static prefix audio caching, and dynamic prefix audio caching, no longer relying solely on full response text caching. In response to the business characteristics of robot dialogue where the overall response is not repeated but the opening phrases of the dialogue are frequently repeated, the probability of cache hit is greatly improved. In the case of cache hit, the synthesized audio can be directly reused, avoiding the overhead of repeated TTS inference and further reducing the latency of the first frame output. When a prefix-type cache is hit, a two-stage output mode is adopted: "output the cached prefix audio first, and then continue to synthesize the remaining text in a streaming manner". This not only enables the rapid output of the first frame of audio, but also continues to synthesize the subsequent text in a streaming manner, ensuring the correctness and completeness of the complete speech output content, and will not truncate the broadcast content in pursuit of low latency. In summary, this invention can significantly improve the user's waiting experience when hearing the first voice without reducing the semantic output quality of large models.
[0031] The following is a description of the data structures used in this invention: Prefix events can be represented as: ```text LLM_STREAMING_PREFIX = { task_id: Identifier of the current dialogue task. user_id: The identifier of the current user. prefix: LLM Current first sentence cumulative text prefix } ``` Here, `task_id` is used to distinguish between concurrent tasks and canceled tasks, and `prefix` is the prefix text of the first sentence after removing leading and trailing whitespace.
[0032] TTS segmented events can be represented as: ```text TTS_STREAM = { task_id: Identifier of the current dialogue task. user_id: The identifier of the current user. text: The text segments to be synthesized. is_stream: true, stream_index: Current segment number, is_final: Whether it is the last segment } ``` Audio block events can be represented as: ```text TTS_AUDIO = { task_id: Identifier of the current dialogue task. audio_data: PCM audio sample array, sample_rate: Output sampling rate } ``` This invention uses the following cache: ```text Full text audio cache: key = complete segmented text value = Full PCM audio Static phrase audio cache: key = Pre-configured high-frequency starting phrases value = Corresponding PCM audio Dynamic prefix audio caching: key = 2 to 6 word prefixes extracted from the actual first sentence value = Corresponding PCM audio In-task prefetch cache: key = task_id value = {text: Prefetched prefix text, audio: Pre-synthesized PCM audio} ``` In a preferred embodiment of the present invention, the prefix triggering condition specifically includes: The current LLM output is characterized by the following conditions: the first sentence is 0, the sentence_count == 0 is true, the sentence_buffer has not yet detected any punctuation at the end of the sentence, the length of the prefix text after removing whitespace reaches the preset minimum event length, and the release cycle condition is met. The punctuation at the end of the sentence includes Chinese punctuation and English punctuation. Decimal points after numbers are not recognized as punctuation at the end of the sentence. The release cycle condition is that the length of the prefix text is an integer multiple of the preset step size.
[0033] In this preferred embodiment, the LLM module receives model output chunks in a streaming manner. Upon receiving each chunk, the following processing is performed: 1. Append the chunk to the full response cache.
[0034] 2. Append the chunk to the first / current sentence buffer `sentence_buffer`.
[0035] 3. Determine if the current text is the first sentence, i.e., `sentence_count == 0`.
[0036] 4. Determine if `sentence_buffer` has not yet encountered a Chinese or English sentence-ending punctuation mark. Chinese sentence-ending punctuation marks include `。`, `!`, `?`, and `;`; English sentence-ending punctuation marks include `.`, `!`, and `?`, but `.` immediately following a number is recognized as a decimal point and is not treated as the end of the sentence.
[0037] 5. If the current sentence is still the first sentence, has not yet reached the end, the length of the prefix after removing whitespace is greater than or equal to the preset minimum event length, and the release cycle condition is met, then release the `LLM_STREAMING_PREFIX` event.
[0038] In one embodiment, the release cycle condition is: the prefix length is greater than or equal to 2 and is an integer multiple of 2. This condition ensures that the prefix event occurs early enough while avoiding an event storm caused by each token triggering a match.
[0039] In a preferred embodiment of the present invention, specifically, the normalized longest prefix matching includes... Remove the trailing punctuation from the text keys of the first sentence text, the static phrase audio cache, and the dynamic prefix audio cache, and then perform the longest prefix matching. When multiple text keys match successfully, select the text key with the longest character length as the prefetchable phrase, and verify that the same task_id task is submitted only once to avoid the same dialogue task from repeatedly initiating prefetch synthesis.
[0040] In this preferred embodiment, after listening for the `LLM_STREAMING_PREFIX` event, the following processing is performed: 1. Read the `task_id` and `prefix` from the event.
[0041] 2. If a prefetch task has already been submitted for this `task_id`, return directly to avoid repeatedly synthesizing multiple prefixes for the same task.
[0042] 3. Search for a matchable phrase in the static short speech audio cache.
[0043] 4. Search for a matchable phrase in the dynamic prefix audio cache.
[0044] 5. When multiple matchable phrases exist, select the longest phrase as the prefetch target.
[0045] 6. If no matching phrase is found, do not submit a prefetch.
[0046] 7. If a matching phrase is found, place `(task_id, matched_text)` into the background synthesis queue.
[0047] The matchable phrase needs to satisfy the following conditions: 1. The cached phrase is non-empty.
[0048] 2. The length of the cached phrase is greater than or equal to `min_prefix_length`.
[0049] 3. The first several characters of the `prefix` are consistent with the beginning of the cached phrase.
[0050] 4. If the beginning contains Chinese or English trailing punctuation, remove the trailing punctuation before comparison, so that "好的" can match "好的," or "好的!".
[0051] In one embodiment, `min_prefix_length` is 4. This value is used to prevent overly short prefixes from being mistakenly triggered, while ensuring that common openings such as "好的," and "对不起," can be hit as early as possible.
[0052] After the background prefetch thread obtains `(task_id, matched_text)` from the queue, the following processing is performed: 1. Attempt to acquire the TTS synthesis lock `_synth_lock`, so that prefetch synthesis and main TTS synthesis are serialized, avoiding concurrent execution of two TTS inferences on the same GPU.
[0053] 2. Call the resident TTS streaming synthesis interface to synthesize `matched_text`.
[0054] 3. Concatenate the multiple audio chunks returned by the streaming into a single PCM audio array.
[0055] 4. Write `{text: matched_text, audio: audio}` to the prefetch cache within the task, with the key `task_id`.
[0056] 5. If the synthesis fails or there is no audio chunk, the current prefetch is discarded without affecting the main process.
[0057] This step enables the TTS first-segment prefill or acoustic model first-packet decoding to be performed in parallel with the LLM subsequent sentence generation.
[0058] In a preferred embodiment of the present invention, the method further includes acquiring a TTS synthesis lock before obtaining the prefix audio based on the prefetchable phrase, wherein the TTS synthesis lock is used to ensure that only one prefix audio synthesis task is allowed to enter GPU inference at any given time.
[0059] In a preferred embodiment of the present invention, the TTS segmentation conditions specifically include: sentence_buffer recognizes sentence-ending punctuation or newline characters; Or, for the first sentence, the sentence_buffer reaches the preset minimum segmentation length and can be segmented at the preset segmentable punctuation. If no segmentable punctuation is found, the text continues to accumulate until a segmentable punctuation is found. Or for subsequent segments that are not the first sentence, if the segmented text is too short and does not reach the preset minimum segment length and is not a newline or the final segment, then the text continues to accumulate until the preset minimum segment length is reached. After all LLM streaming output has finished, for any remaining text, if it is not empty, it will be sent as the last segment; if all segments are filtered out because they are too short but the complete reply is not empty, the complete reply will be sent as the fallback segment.
[0060] In this preferred embodiment, the LLM module is also responsible for determining when to send text segments to the TTS during streaming generation. The determination logic includes: 1. If `sentence_buffer` ends with Chinese sentence-end punctuation, English sentence-end punctuation, or a line break, then a TTS segment can be formed.
[0061] 2. For the first sentence acceleration scenario, when the length of `sentence_buffer` reaches `first_sentence_min_chars` and has not yet reached the end of the complete sentence, prioritize finding the nearest segmentation punctuation; if segmentation punctuation exists, then split at that punctuation; if no punctuation exists, continue to wait for subsequent chunks to avoid hard-slicing in nouns or semantic fragments.
[0062] 3. For subsequent segments, if the segment length is less than `follow_segment_min_chars` and it is not a newline or final segment, it will not be sent yet, and will continue to be merged with the subsequent text to avoid generating excessively short segments that would cause multiple TTS prefills.
[0063] 4. For digital fragments or short segments with a length of 2 or less, do not send them temporarily, but continue to accumulate them.
[0064] 5. The remaining text after the stream ends, if not empty, will be sent as the last segment; if all segments are filtered out because they are too short but the complete reply is not empty, the complete reply will be sent as the fallback segment.
[0065] In one embodiment, `first_sentence_min_chars` is 8, `first_sentence_hard_cut_chars` is 14, and `follow_segment_min_chars` is 6. These values can be adjusted based on model speed and business communication style.
[0066] In addition, to improve the first-sentence prefix cache hit rate, the LLM module can perform prefix injection before the first TTS segment is sent: 1. Check if the current segment is the first sentence and if the prefix injection switch is enabled.
[0067] 2. If the LLM output itself begins with a cached phrase or a synonymous function word, then remove that phrase first to avoid repeated beginnings such as "okay, okay," etc.
[0068] 3. If the stripped text is empty, do not send TTS for now, and continue to wait for subsequent actual text.
[0069] 4. If the first sentence begins with a negative, apologetic, or unavoidable semantic, and the negative skip strategy is enabled, then affirmative prefixes such as "okay," will not be injected to avoid semantic contradictions.
[0070] 5. Otherwise, select the injection prefix based on the language and scenario. For general Chinese scenarios, select from the Chinese short prefix pool; for English scenarios, select from the English short prefix pool; for story scenarios, select from the longer story prefix pool.
[0071] 6. The selection strategy can be random, but the prefix of the previous selection should be excluded to avoid consecutive repetition.
[0072] 7. Append the selected prefix to the beginning of the first sentence and update the complete reply text simultaneously.
[0073] This step does not involve regenerating the LLM, but rather performs lightweight preprocessing on the text to be broadcast, making the first sentence heard by the user more natural and making it easier to hit the TTS static phrase cache.
[0074] As a preferred embodiment of the present invention, the method further includes a GPU scheduling step: LLM and TTS share the edge GPU resources. In the first sentence stage, after the second event is published, the LLM thread suspends subsequent token generation and waits for the first audio block event to be received or for the timeout to occur before resuming LLM generation. During this period, control is performed through the TTS synthesis lock. The update synthesis of the dynamic prefix audio cache is only performed in the background when the system is idle and does not preempt real-time dialogue GPU resources.
[0075] In this preferred embodiment, when the LLM and TTS share the GPU on the edge device, the present invention can adopt the following scheduling strategy: 1. TTS Synthesis Lock: Only one TTS synthesis task is allowed to enter GPU inference at a time, avoiding multiple TTS tasks from competing with each other.
[0076] 2. Background prefetch serialization: The prefetch thread also needs to acquire the same synthesis lock, and the prefetch waits or skips while the main path is being synthesized.
[0077] 3. Dynamic prefix cache execution during idle periods: The dynamic prefix background worker only synthesizes the cache after the system is idle, without preempting real-time user requests.
[0078] 4. First-Sentence LLM Pause: After the first TTS segment is sent, the LLM thread can wait for the first audio chunk of the TTS to arrive or wait for a timeout before continuing generation. This waiting allows the first TTS packet to receive a GPU time slice first, reducing jitter in the first frame.
[0079] 5. In long story scenarios, the first sentence serialization can be forced, because the first paragraph of the story response is longer and the subsequent token generation will have a more significant impact on GPU usage.
[0080] In a preferred embodiment of the present invention, specifically, priority matching is performed on the complete text audio cache, in-task prefetch cache, static phrase audio cache, and dynamic prefix audio cache, and multiple audio block events are processed and output according to the matching results, including: Step 151: First, determine whether the complete text audio buffer is hit. If the complete text audio buffer is hit, read the complete PCM audio, output the audio block event, and go to step 160. Step 152: If the complete text audio cache is not hit, determine whether there is a prefetch item corresponding to the current task_id in the prefetch cache within the task, and verify whether the current segmented text starts with the prefix text recorded by the prefetch item; only if both are satisfied is it determined that the prefetch cache within the task has been hit, read and output the prefix audio, extract the remaining text from the segmented text after removing the matching prefix text, perform streaming synthesis on the remaining text and output the corresponding audio block event, and go to step 160; if the verification fails, discard the prefetch item and continue to step 153; Step 153: If the prefetch cache within the task is not hit, determine whether the static phrase audio cache or the dynamic prefix audio cache is hit; if the static phrase audio cache or the dynamic prefix audio cache is hit, read the prefix audio in the cache, first output the audio block event corresponding to the prefix audio, extract the remaining text from the segmented text after removing the matching prefix text, perform streaming synthesis on the remaining text to generate the remaining audio block, output the audio block event corresponding to the remaining audio block, and go to step 160. Step 154: If the complete text audio cache, in-task prefetch cache, static phrase audio cache, and dynamic prefix audio cache are all missed, then call the resident TTS inference service to perform regular streaming synthesis on the current segmented text, generate all audio blocks, and output the audio block events corresponding to all audio blocks.
[0081] In this preferred embodiment, upon receiving `TTS_STREAM`, routing is performed according to the following priority: Full text audio cache hit Judgment conditions: ```text text in full_audio_cache ``` If true, the complete PCM audio will be read directly and `TTS_AUDIO` will be published, completely skipping this TTS inference.
[0082] Applicable scenarios include deterministic, high-frequency, short responses such as identity verification, fixed game feedback, and skill confirmation phrases. In one embodiment, only short texts with a length not exceeding 80 characters are written to the full audio cache and evicted using LRU.
[0083] In-task prefetch cache hit Judgment conditions: ```text prefetch_cache[task_id] exists And text.startswith(prefetch_cache[task_id].text) ``` If true, read the prefetched audio from the task and publish it immediately. If `text` no longer starts with the prefix text, it means that subsequent LLM output has changed or the prefetch prefix is no longer suitable, so discard the prefetch item and continue checking the next level of cache.
[0084] This condition ensures that the prefetched audio is only used when it matches the final first sentence, avoiding the playback of incorrect prefixes.
[0085] Static prefix cache hit Judgment conditions: 1. If `text` is exactly the same as the static cache key, then it is a full hit.
[0086] 2. Otherwise, iterate through the static cache phrases and perform the longest prefix match with punctuation removed and normalized.
[0087] 3. Select the audio corresponding to the longest matching phrase.
[0088] Static prefix cache is pre-synthesized based on high-frequency phrases at startup or model loading time, including phrases such as "okay," "okay!", "I don't know," "sorry," and long beginnings of story classes.
[0089] Dynamic prefix cache hit If the static cache is not found, the dynamic prefix cache is queried using the same exact match and normalized longest prefix match methods. The dynamic prefix cache is derived from the actual first sentence output and can cover actual high-frequency beginnings beyond the configured phrase.
[0090] miss If none of the above caches are hit, then the resident TTS service is invoked to perform regular streaming synthesis on the current segment `text`.
[0091] The remaining text after the prefix hit is continued When the in-task prefetch cache, static prefix cache, or dynamic prefix cache is hit, the TTS module performs a two-stage output: Phase 1: Immediately release cached prefix audio.
[0092] ```text publish TTS_AUDIO(cached_audio) ``` Second stage: Calculate the remaining text and synthesize it in a streaming manner.
[0093] ```text remaining = text[cached_len:] if remaining is not empty: for audio_chunk in synthesize_streaming(remaining): publish TTS_AUDIO(audio_chunk) ``` Here, `cached_len` represents the actual length of the original text characters consumed after normalized longest prefix matching. This design avoids errors in truncating the remaining text due to punctuation differences.
[0094] If `remaining` is empty, it means that the cache has covered the entire segment, and the TTS module will no longer call the synthesis model.
[0095] In a preferred embodiment of the present invention, the method for determining whether a static phrase audio cache or a dynamic prefix audio cache has been hit includes: First, determine if the static phrase audio cache has been hit. The process is as follows: If the segmented text is exactly the same as the static cache key, then a full hit occurs; Otherwise, iterate through the static cache phrases and perform the longest prefix match with suffix removed and normalized. Select the audio corresponding to the phrase with the longest matching length as the static phrase audio cache hit result; If the above process fails to match, the static phrase audio cache is not hit, and the following dynamic prefix audio cache hit judgment is performed: The dynamic prefix audio cache is queried in the manner described above. If a hit result is found, the audio corresponding to the hit result is taken as the dynamic prefix audio cache hit result. If no hit result is found, the dynamic prefix audio cache is determined to have missed.
[0096] As a preferred embodiment of the present invention, the persistent TTS inference service specifically includes any of the following methods: The first type is a persistent model object within the Python process: the model remains resident on the GPU after loading and the streaming synthesis interface is called directly. The second type is Tensor RT TTS daemon: The TTS engine, vocoder, and speaker encoder are started as resident processes, and the main application submits synthesis tasks through request files, standard input / output, or local communication interfaces.
[0097] The third type is g RPC resident service: the main application sends synthesis requests and receives streaming audio responses via Unix domain sockets or local ports.
[0098] In this preferred embodiment, in a file-chunk streaming output scenario, the TTS service can write audio chunks to a shared memory directory. The main application maintains a set of read files `seen`, and immediately reads and publishes `TTS_AUDIO` for any newly added chunk file. The polling interval can be configured to a small value; in a more preferred embodiment, file system events or server-side streaming responses are used instead of fixed-period polling.
[0099] Furthermore, considering that the native output sampling rate of the TTS model may differ from the sampling rate of the robot playback or remote protocol, this invention performs the following processing on each TTS segment to ensure audio continuity: 1. Calculate the resampling ratio (up, down) in the simplest fractional form based on the source sampling rate and the target sampling rate.
[0100] 2. Use the polyphase resampling method to convert each chunk to the target sampling rate.
[0101] 3. Maintain the input tail sample within the same segment as the filtering context for the next chunk to reduce chunk boundary artifacts.
[0102] 4. Reset the resampling tail state before each new segment begins to avoid the filtering state of the previous segment from polluting the next segment.
[0103] 5. A short fade-in can be applied to the first chunk to reduce the zero-state startup transient of the filter.
[0104] Dynamic prefix cache generation After a sentence is synthesized using standard TTS (Text-to-Speech) techniques, the system can submit it to a dynamic prefix cache background queue. Background thread execution: 1. If the text length is less than `dynamic_prefix_min_len`, then no processing is performed.
[0105] 2. Wait for the system to enter an idle state.
[0106] 3. Extract prefixes from the beginning of the text, with lengths from `dynamic_prefix_min_len` to `dynamic_prefix_max_len`.
[0107] 4. If a prefix is already in the cache, only its LRU position is promoted.
[0108] 5. If not cached, attempt to acquire the TTS synthesis lock in a non-blocking manner.
[0109] 6. After successful acquisition, synthesize the prefixed audio, trim the trailing mute, and write it to the dynamic prefix cache.
[0110] 7. If the number of cached entries exceeds `dynamic_prefix_max_entries`, the oldest entry will be evicted using the LRU algorithm.
[0111] In one embodiment, the dynamic prefix length is 2 to 6 characters, and the maximum number of entries is 300.
[0112] This invention also proposes a device for low-latency generation of the first frame of a large-scale end-to-end TTS model, comprising the following: The data acquisition module is used to acquire text chunks generated by LLM streaming and continuously append the text chunks to the sentence buffer (sentence_buffer). The first judgment module is used to determine whether the current sentence_buffer meets the prefix triggering condition. If the prefix triggering condition is met, the first event is published. If the prefix triggering condition is not met, the data acquisition module is returned to execute. The first event carries the task_id task identifier, the user_id user identifier, and the first sentence text after removing leading and trailing whitespace. The second judgment module, when the first event is detected, reads the text keys of the static phrase audio cache and the dynamic prefix audio cache as candidate phrases, and performs normalized longest prefix matching on the first sentence text and each candidate phrase; if a match is found, the matched text key is used as a prefetchable phrase, TTS synthesis is performed on the prefetchable phrase in advance, and the obtained prefix audio is written into the prefetch cache in the task with task_id as the key; if no match is found, the process returns to the data acquisition module for execution. The third judgment module is used to determine whether the current sentence_buffer meets the TTS segmentation conditions. If it does not meet the TTS segmentation conditions, it returns to step 110 for execution. If it meets the TTS segmentation conditions, it publishes a second event. The second event carries task_id, user_id, segmented text to be synthesized, streaming tag, segmentation number and whether it is the final segmentation tag. The fourth judgment module is used to, when the second event is detected, perform priority hit judgment in the order of complete text audio cache, task prefetch cache, static phrase audio cache, and dynamic prefix audio cache, and process and output multiple audio block events according to the judgment results. Each audio block event carries at least task_id, PCM audio sample array and output sampling rate. The audio output module is used to send all audio block event inputs to the playback queue or a remote audio transmission link for output playback.
[0113] Furthermore, the functional modules in the various embodiments of the present invention can be integrated into one processing module, or each module can exist physically separately, or two or more modules can be integrated into one module. The integrated modules described above can be implemented in hardware or as software functional modules.
[0114] If the integrated module is implemented as a software functional module and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, all or part of the processes in the above embodiments of the present invention can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or system capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc.
[0115] Although the description of the invention has been quite detailed and particularly of several described embodiments, it is not intended to limit it to any of these details or embodiments or any particular embodiment, but should be considered as providing a broad possible interpretation of the claims by referring to the appended claims and taking into account the prior art, thereby effectively covering the intended scope of the invention. Furthermore, the invention has been described above with respect to embodiments foreseeable by the inventors in order to provide a useful description, and non-substantial modifications to the invention that have not yet been foreseen may still represent equivalent modifications.
[0116] The above description is merely a preferred embodiment of the present invention. The present invention is not limited to the above-described embodiments. Any embodiment that achieves the technical effects of the present invention using the same means should fall within the protection scope of the present invention. Within the protection scope of the present invention, various modifications and variations can be made to the technical solutions and / or implementation methods.
Claims
1. A method for generating the first frame of a large-scale end-to-end TTS with low latency, characterized in that, Including the following: Step 110: Obtain the text chunks generated by the LLM streaming method, and continuously append the text chunks to the sentence buffer (sentence_buffer); Step 120: Determine whether the current sentence_buffer meets the prefix triggering condition. If it meets the prefix triggering condition, publish the first event. If it does not meet the prefix triggering condition, return to step 110 for execution. The first event carries the task_id task identifier, the user_id user identifier, and the first sentence text after removing leading and trailing whitespace. Step 130: When the first event is detected, read the text keys of the static phrase audio cache and the dynamic prefix audio cache as candidate phrases, and perform normalized longest prefix matching on the first sentence text and each candidate phrase; if a match is found, use the matched text key as a prefetchable phrase, perform TTS synthesis on the prefetchable phrase in advance, and write the obtained prefix audio into the prefetch cache in the task with task_id as the key; if no match is found, return to step 110 to execute. Step 140: Determine whether the current sentence_buffer meets the TTS segmentation conditions. If it does not meet the TTS segmentation conditions, return to step 110. If it meets the TTS segmentation conditions, publish a second event. The second event carries task_id, user_id, segmented text to be synthesized, streaming tag, segment number, and whether it is the final segment tag. Step 150: When the second event is detected, the priority of the full text audio cache, the in-task prefetch cache, the static phrase audio cache, and the dynamic prefix audio cache is determined in sequence, and multiple audio block events are processed and output according to the determination results. Each audio block event carries at least the task_id, the PCM audio sample array, and the output sampling rate. Step 160: Send all audio block event inputs to the playback queue or remote audio transmission link for output playback.
2. The method for generating the first frame of a large-scale end-to-end TTS with low latency according to claim 1, characterized in that, Specifically, the prefix triggering conditions include, The current LLM output is characterized by the following conditions: the first sentence is 0, the sentence count is 0, the sentence buffer has not yet detected any punctuation at the end of the sentence, the length of the prefix text after removing whitespace reaches the preset minimum event length, and the release cycle condition is met. The punctuation at the end of the sentence includes Chinese punctuation and English punctuation. Decimal points after numbers are not recognized as punctuation at the end of the sentence. The release cycle condition is that the length of the prefix text is an integer multiple of the preset step size.
3. The method for generating the first frame of a large-scale end-to-end TTS with low latency according to claim 1, characterized in that, Specifically, the normalized longest prefix matching includes, Remove the trailing punctuation from the text keys of the first sentence text, the static phrase audio cache, and the dynamic prefix audio cache, and then perform the longest prefix matching. When multiple text keys match successfully, select the text key with the longest character length as the prefetchable phrase, and verify that the same task_id task is submitted only once to avoid the same dialogue task from repeatedly initiating prefetch synthesis.
4. The method for generating the first frame of a large-scale end-to-end TTS with low latency according to claim 1, characterized in that, The method further includes acquiring a TTS synthesis lock before obtaining the prefix audio based on the prefetchable phrase. The TTS synthesis lock is used to ensure that only one prefix audio synthesis task is allowed to enter GPU inference at any given time.
5. The method for generating the first frame of a large-scale end-to-end TTS with low latency according to claim 1, characterized in that, Specifically, the TTS segmentation conditions include, sentence_buffer recognizes sentence-ending punctuation or newline characters; Or, for the first sentence, the sentence_buffer reaches the preset minimum segmentation length and can be segmented at the preset segmentable punctuation. If no segmentable punctuation is found, the text continues to accumulate until a segmentable punctuation is found. Or for subsequent segments that are not the first sentence, if the segmented text is too short and does not reach the preset minimum segment length and is not a newline or the final segment, then the text continues to accumulate until the preset minimum segment length is reached. After all LLM streaming output has finished, for any remaining text, if it is not empty, it will be sent as the last segment; if all segments are filtered out because they are too short but the complete reply is not empty, the complete reply will be sent as the fallback segment.
6. The method for generating the first frame of a large-scale end-to-end TTS with low latency according to claim 4, characterized in that, The method also includes a GPU scheduling step: LLM and TTS share the edge GPU resources. In the first sentence stage, after the second event is published, the LLM thread suspends subsequent token generation and waits for the first audio block event to be received or for a timeout before resuming LLM generation. During this period, control is achieved through the TTS synthesis lock. The update synthesis of the dynamic prefix audio cache is only performed in the background when the system is idle and does not preempt real-time dialogue GPU resources.
7. The method for generating the first frame of a large-scale end-to-end TTS with low latency according to claim 1, characterized in that, Specifically, the system prioritizes and determines which audio blocks are cached in order: full text audio cache, in-task prefetch cache, static phrase audio cache, and dynamic prefix audio cache. Based on the results, it processes and outputs multiple audio block events, including... Step 151: First, determine whether the complete text audio buffer is hit. If the complete text audio buffer is hit, read the complete PCM audio, output the audio block event, and go to step 160. Step 152: If the complete text audio cache is not hit, determine whether there is a prefetch item corresponding to the current task_id in the prefetch cache within the task, and verify whether the current segmented text starts with the prefix text recorded by the prefetch item; only if both are satisfied is it determined that the prefetch cache within the task has been hit, read and output the prefix audio, extract the remaining text from the segmented text after removing the matching prefix text, perform streaming synthesis on the remaining text and output the corresponding audio block event, and go to step 160; if the verification fails, discard the prefetch item and continue to step 153; Step 153: If the prefetch cache within the task is not hit, determine whether the static phrase audio cache or the dynamic prefix audio cache is hit; if the static phrase audio cache or the dynamic prefix audio cache is hit, read the prefix audio in the cache, first output the audio block event corresponding to the prefix audio, extract the remaining text from the segmented text after removing the matching prefix text, perform streaming synthesis on the remaining text to generate the remaining audio block, output the audio block event corresponding to the remaining audio block, and go to step 160. Step 154: If the complete text audio cache, in-task prefetch cache, static phrase audio cache, and dynamic prefix audio cache are all missed, then call the resident TTS inference service to perform regular streaming synthesis on the current segmented text, generate all audio blocks, and output the audio block events corresponding to all audio blocks.
8. The method for generating the first frame of a large-scale end-to-end TTS with low latency according to claim 7, characterized in that, Specifically, methods for determining whether a static phrase audio cache or a dynamic prefix audio cache has been hit include: First, determine if the static phrase audio cache has been hit. The process is as follows: If the segmented text is exactly the same as the static cache key, then a full hit occurs; Otherwise, iterate through the static cache phrases and perform the longest prefix match with suffix removed and normalized. Select the audio corresponding to the phrase with the longest matching length as the static phrase audio cache hit result; If the above process fails to match, the static phrase audio cache is not hit, and the following dynamic prefix audio cache hit judgment is performed: The dynamic prefix audio cache is queried in the manner described above. If a hit result is found, the audio corresponding to the hit result is taken as the dynamic prefix audio cache hit result. If no hit result is found, the dynamic prefix audio cache is determined to have missed.
9. The method for generating the first frame of a large-scale end-to-end TTS with low latency according to claim 7, characterized in that, Specifically, the resident TTS inference service includes any of the following methods: The first type is a Python process-resident model object: the model remains resident on the GPU after loading and the streaming synthesis interface is called directly. The second type is Tensor RT TTS daemon: The TTS engine, vocoder, and speaker encoder are started as resident processes, and the main application submits synthesis tasks through request files, standard input / output, or local communication interfaces. The third type is g RPC resident service: the main application sends synthesis requests and receives streaming audio responses via Unix domain sockets or local ports.
10. A device for low-latency generation of the first frame of a large-scale end-to-end TTS model, characterized in that, Including the following: The data acquisition module is used to acquire text chunks generated by LLM streaming and continuously append the text chunks to the sentence buffer (sentence_buffer). The first judgment module is used to determine whether the current sentence_buffer meets the prefix triggering condition. If the prefix triggering condition is met, the first event is published. If the prefix triggering condition is not met, the data acquisition module is returned to execute. The first event carries the task_id task identifier, the user_id user identifier, and the first sentence text after removing leading and trailing whitespace. The second judgment module, when the first event is detected, reads the text keys of the static phrase audio cache and the dynamic prefix audio cache as candidate phrases, and performs normalized longest prefix matching on the first sentence text and each candidate phrase; if a match is found, the matched text key is used as a prefetchable phrase, TTS synthesis is performed on the prefetchable phrase in advance, and the obtained prefix audio is written into the prefetch cache in the task with task_id as the key; if no match is found, the process returns to the data acquisition module for execution. The third judgment module is used to determine whether the current sentence_buffer meets the TTS segmentation conditions. If it does not meet the TTS segmentation conditions, it returns to step 110 for execution. If it meets the TTS segmentation conditions, it publishes a second event. The second event carries task_id, user_id, segmented text to be synthesized, streaming tag, segmentation number and whether it is the final segmentation tag. The fourth judgment module is used to, when the second event is detected, perform priority hit judgment in the order of complete text audio cache, task prefetch cache, static phrase audio cache, and dynamic prefix audio cache, and process and output multiple audio block events according to the judgment results. Each audio block event carries at least task_id, PCM audio sample array and output sampling rate. The audio output module is used to send all audio block event inputs to the playback queue or a remote audio transmission link for output playback.
Citation Information
Patent Citations
Built-in platform voice synthetic system and method thereof
CN101114446B
Speech synthesis quality evaluation method and system
CN111179973A
A text-to-speech processing method, terminal and server
CN113129861B
