Repository navigation
feat: return_text on /v1/audio/speech/live - #805
Merged
Merged
Conversation
With return_text=true (or 1), the live speech route also streams the text a model writes as it speaks, such as a spoken reply's words. speech.text.delta events carry the text written since the previous event, before that event's audio, and speech.text.done carries the whole text before speech.audio.done. Without it the stream is audio only, as before. return_text needs stream_format=sse, since raw PCM has no place for text, and takes true, 1, false or 0; other values are rejected. A model that writes no text ends the stream with an error event after its audio, as the transcription route fails when a model gives no text. Checked end to end through audiocpp_server on an A10 with a streaming speech-to-speech model that emits text with its audio (LFM2.5-Audio from the lfm2_audio port): the text deltas join to speech.text.done, which matches the offline reply for the same seed; the audio is identical with and without return_text; Japanese text arrives in whole characters; and the two invalid requests return 400.
The live route now streams a spoken reply's text with return_text=true, so the page shows it in the example and drops the old limitation.
The parallel runtime split off from the legacy server after return_text was added to /v1/audio/speech/live and has its own live handler, so under --parallel-jobs return_text was ignored and the stream stayed audio only. Give that handler the same change: return_text takes true, 1, false or 0 and needs stream_format=sse, speech.text.delta events carry each event's text ahead of its audio, speech.text.done carries the whole text before speech.audio.done, and a model that writes no text ends the stream with an error after its audio. The checks run after the request has bound its slot, as the stream_format check does, so a rejected request gets a 400 and releases the slot. Apart from the existing lease and busy handling the two handlers are now the same. The parallel lifecycle test now drives the live route at 1, 2 and 4 slots, with a fixture session that can read the request body, write no text, or give no final text or one other than its streamed text: the text and event order with return_text, no text events without it or with false or 0, both 400s, speech.text.done with the final text or, when the model gives none, the joined deltas, the no-text error after the audio, and no slot left held. It fails without the change, with the text written after the audio, with other values accepted, with the joined deltas always in speech.text.done, or with a missing final text treated as no text. The fixture changes stay on existing lines, so the line links in the parallel server contract still land on their tests. A CPU build on Linux passes the server, http, streaming, session pool, lfm2_audio and model spec tests. Through audiocpp_server, LFM2.5-Audio answers the same English and Japanese questions with the same seed with identical text, text deltas and audio with and without --parallel-jobs, and its audio is the same with and without return_text.
Owner
|
@ykhrustalev PR merged. Thanks! |
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the last part of the plan in #683:
return_textonPOST /v1/audio/speech/live, agreed there as?return_text=true, audio only by default. It builds on #798 (LFM2.5-Audio speech-to-speech).Problem
LFM2.5-Audio's speech-to-speech entry writes its reply's words as it speaks, and its streaming events carry the new text as it is written, but the live route sends only the audio. A client that wants the words has to run the question again through
/v1/tasks/runor transcribe the reply.What this PR adds
return_textquery parameter:true,1,falseor0(case sensitive). Absent, empty or bare (&return_textwith no value) meansfalse. Other values get a 400 (live speech return_text must be true or false)return_text=true, each event's new text goes out asspeech.text.deltabefore that event's audio, andspeech.text.donecarries the whole text beforespeech.audio.done:speech.text.doneis the model's final text, or the joined deltas if it gives nonereturn_textneedsstream_format=sse, since raw PCM has no place for text; otherwise it gets a 400 (live speech return_text needs stream_format=sse)return_text=truegives with any other model, for example PersonaPlex or a TTS entry--parallel-jobsruntime (server: separate legacy and experimental parallel jobs runtimes #715) split off after this change was written and has its own live handler, so this PR changes it the same way, as server: add include_params to GET /v1/models, read from the model spec #787 did for its change--helpanddocs/community_models/lfm2_audio.mddescribe the parameter; the docs page drops its limitation that this route returns no textWhat does not change
Without
return_text, or withfalse,0or an empty value, the stream is the same as on main 8fa20ff in both runtimes. On an A10 (four package and backend setups), 199 of 200 audio-only live requests matched main in every event apart from timing and in PCM bytes. In the other one, a TTS request, main's own server reset the connection; 10 repeats per runtime then matched. On an M3 Ultra all 20 S2S requests matched main the same way. Its TTS requests often hit the connection reset described under Known limitations, on main and this branch alike (in the legacy comparison main got the stream and this branch the reset); read with a client that takes the whole response, they matched main in both runtimes.Testing
server_parallel_lifecycle_testcovers the--parallel-jobsroute at 1, 2 and 4 slots: text and event order, no text when off, both 400s,speech.text.donewith the final text or the joined deltas, the no-text error, and no slot left held. Handlers without the change, with text after audio, accepting other values, always sending the joined deltas, or treating a missing final text as no text fail it. The fixture edits change existing lines instead of adding new ones, so the#Llinks indocs/maintainers/parallel_server_behavior_contract.mdstill land on their testsaudiocpp_server, branch and main, both runtimes, on an A10 (EN F16, EN Q8_0 and JP F16 on CUDA, EN Q8_0 on the CPU) and an M3 Ultra (EN and JP Q8_0 on Metal)return_textstreams start with a text delta, have audio after every text delta, and end withspeech.text.done,speech.audio.doneand[DONE]. The deltas join tospeech.text.done. Each event is valid UTF-8 on its own, so Japanese comes in whole characters. Byte tokens that make no character come out as U+FFFD, as in/v1/tasks/run(seen in some Thai replies)/v1/tasks/runfor the same seed andmax_tokensin every pair checked, including 203 replies cut atmax_tokens(a cut inside a Thai character drops it). The audio is byte for byte the same as withoutreturn_textin every pair checked--parallel-jobsno slot is left heldreturn_text=trueor1it gave HTTP 200, its audio, then the error eventlive speech model wrote no text; return_text needs a model that writes text, with nospeech.text.done,speech.audio.doneor[DONE]. Withoutreturn_textthe same audio ends withlive streaming response did not observe input end, as on mainBuild and run
As tested on the A10, which also passed
-DCMAKE_C_COMPILER=gcc-12 -DCMAKE_CXX_COMPILER=g++-12 -DCMAKE_CUDA_HOST_COMPILER=g++-12; on macOS use-DENGINE_ENABLE_METAL=ON -DENGINE_ENABLE_OPENMP=OFF -DGGML_OPENMP=OFFinstead of the CUDA flags.-DENGINE_BUILD_EXTENDED_TESTS=ONadds the http and streaming tests.With an S2S streaming entry as in the docs page, run
audiocpp_serverwith or without--parallel-jobs:Known limitations
stream_format=audio) has no textlive streaming response did not observe input end, and the server then closes with the body unread. A client still sending PCM may get a connection reset, or wait until its timeout, instead of the stream or a 400. On the M3 Ultra that happened to 16 or 17 of 20 TTS requests per server with Python'shttp.client, on main and this branch alike. The TTS results above come from clients that read the whole response