Streaming Reasoning
I tried to add a new interface for v1/audio/speech-stream to the AI. The process worked, but there was a current sound at the junction of each returned audio data packet. I hope the official version will be released soon
I understand. There are still a few minor bugs on my side, and I’ve already fixed them. I’ll publish a release first, then start working on streaming support. I haven’t begun that work yet. If you’ve already implemented streaming support and it works but still has some issues, please share the code showing the feature or open a PR. That would help me move faster.
I've added initial streaming TTS support in PR #23. Note that this is still a work-in-progress draft; stability especially with longer inputs is being improved. Please follow PR #23 for progress and updates.
谢谢大佬,流式推理是合并到main了吗,是server端的流式推理吗,tool_zh.md还没看到有调用方法
还没呢,我还在优化性能。目前只有 cli 的交互模式支持这个,server 的流式支持会在优化后添加,文档也会在全部完成后更新。可以跟踪 PR #23 查看进度。
我打算等流式出来后把http升级为websocket,配合funasr就可以接agent做到实时对话啦
我让AI部署了你的流式代码,10个字短文本是没问题得,但是50+的长文本会报错,我把报错信息贴出来看看你能不能修复
======================================== FATAL: Caught signal 11 (SIGSEGV) Backtrace (13 frames):
./build-cuda/bin/cosyvoice-server(+0xf9be)[0x638e762f39be] /lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7b5cb7c42520] /home/csrobot/chenmc/cosyvoice.cpp/build-cuda/bin/../lib/libcosyvoice.so(+0x120e51)[0x7b5cb8520e51] /home/csrobot/chenmc/cosyvoice.cpp/build-cuda/bin/../lib/libcosyvoice.so(cosyvoice_tts_instruct_stream+0x1a)[0x7b5cb851e01a] ./build-cuda/bin/cosyvoice-server(+0x1b8a6)[0x638e762ff8a6] ./build-cuda/bin/cosyvoice-server(+0x29f43)[0x638e7630df43] ./build-cuda/bin/cosyvoice-server(+0x51d0b)[0x638e76335d0b] ./build-cuda/bin/cosyvoice-server(+0x7571a)[0x638e7635971a] ./build-cuda/bin/cosyvoice-server(+0x762de)[0x638e7635a2de] ./build-cuda/bin/cosyvoice-server(+0x3c3ae)[0x638e763203ae] /lib/x86_64-linux-gnu/libstdc++.so.6(+0xf6ca6)[0x7b5cb80f6ca6] /lib/x86_64-linux-gnu/libc.so.6(+0x94ac3)[0x7b5cb7c94ac3] /lib/x86_64-linux-gnu/libc.so.6(+0x1268d0)[0x7b5cb7d268d0]
(py310) csrobot@csrobot-DGX-Station:~/chenmc/cosyvoice.cpp$ nm -C /home/csrobot/chenmc/cosyvoice.cpp/build-cuda/lib/libcosyvoice.so | grep -E "^0+11[ef]|^0+120[0-9a-f]|^0+121[0-9a-f]|^0+122[0-9a-f]" | sort
000000000011e000 T cosyvoice_tts_instruct_stream
000000000011e020 T cosyvoice_tts_cross_lingual_stream
000000000011e040 T cosyvoice_tts_context_new
000000000011e600 t std::_Function_handler<unsigned long (std::basic_string_view<char, std::char_traits
我刚刚提交修复代码,你试试现在呢。
很棒,流式真的实现了,首字很快的而且能播放长文本了。现在发现一个Bug也不知道是AI写的不好还是怎么样,就是server端请求的时候如果播放完整音频再进行下次请求是没问题的,但是如果中途终止程序再请求的话服务端会崩掉
[2026-07-28 10:57:38.220] [REQ] id=1 start endpoint=/v1/audio/speech remote=10.0.30.9
/home/csrobot/chenmc/cosyvoice.cpp/vendor/ggml/src/ggml-cuda/fattn.cu:579: fatal error
[New LWP 1853000]
[New LWP 1853013]
[New LWP 1853014]
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
0x00007f52f1127db0 in accept4 (fd=23, addr=..., addr_len=0x0, flags=524288) at ../sysdeps/unix/sysv/linux/accept4.c:31
31 ../sysdeps/unix/sysv/linux/accept4.c: No such file or directory.
#0 0x00007f52f1127db0 in accept4 (fd=23, addr=..., addr_len=0x0, flags=524288) at ../sysdeps/unix/sysv/linux/accept4.c:31
31 in ../sysdeps/unix/sysv/linux/accept4.c
#1 0x000061937ce574fd in httplib::Server::listen_internal() ()
#2 0x000061937ce4d869 in cosyvoice_server_backend_run(server_runtime&) ()
#3 0x000061937ce3dab6 in tool_entry(int, char**) ()
#4 0x00007f52f1029d90 in __libc_start_call_main (main=main@entry=0x61937ce386e0
======================================== FATAL: Caught signal 6 (SIGABRT) Backtrace (24 frames):
./build-cuda/bin/cosyvoice-server(+0xf82e)[0x61937ce3882e] /lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7f52f1042520] /lib/x86_64-linux-gnu/libc.so.6(pthread_kill+0x12c)[0x7f52f10969fc] /lib/x86_64-linux-gnu/libc.so.6(raise+0x16)[0x7f52f1042476] /lib/x86_64-linux-gnu/libc.so.6(abort+0xd3)[0x7f52f10287f3] /home/csrobot/chenmc/cosyvoice.cpp/build-cuda/bin/../lib/libggml-base.so.0(ggml_abort+0x12e)[0x7f52f134f7de] /home/csrobot/chenmc/cosyvoice.cpp/build-cuda/bin/../lib/libggml-cuda.so.0(_Z24ggml_cuda_flash_attn_extR25ggml_backend_cuda_contextP11ggml_tensor+0x26f3)[0x7f52ed206b83] /home/csrobot/chenmc/cosyvoice.cpp/build-cuda/bin/../lib/libggml-cuda.so.0(+0x251904)[0x7f52ed251904] /home/csrobot/chenmc/cosyvoice.cpp/build-cuda/bin/../lib/libggml-base.so.0(ggml_backend_sched_graph_compute_async+0x827)[0x7f52f136cf37] /home/csrobot/chenmc/cosyvoice.cpp/build-cuda/bin/../lib/libggml-base.so.0(ggml_backend_sched_graph_compute+0x12)[0x7f52f136d212] /home/csrobot/chenmc/cosyvoice.cpp/build-cuda/bin/../lib/libcosyvoice.so(+0xe6565)[0x7f52f18e6565] /home/csrobot/chenmc/cosyvoice.cpp/build-cuda/bin/../lib/libcosyvoice.so(+0x11ab7e)[0x7f52f191ab7e] /home/csrobot/chenmc/cosyvoice.cpp/build-cuda/bin/../lib/libcosyvoice.so(cosyvoice_tts_stream+0x171)[0x7f52f1922cb1] /home/csrobot/chenmc/cosyvoice.cpp/build-cuda/bin/../lib/libcosyvoice.so(+0x121c77)[0x7f52f1921c77] /home/csrobot/chenmc/cosyvoice.cpp/build-cuda/bin/../lib/libcosyvoice.so(cosyvoice_tts_zero_shot_stream+0x18)[0x7f52f191df58] ./build-cuda/bin/cosyvoice-server(+0x1b063)[0x61937ce44063] ./build-cuda/bin/cosyvoice-server(+0x29053)[0x61937ce52053] ./build-cuda/bin/cosyvoice-server(+0x50d7b)[0x61937ce79d7b] ./build-cuda/bin/cosyvoice-server(+0x747ab)[0x61937ce9d7ab] ./build-cuda/bin/cosyvoice-server(+0x7537e)[0x61937ce9e37e] ./build-cuda/bin/cosyvoice-server(+0x3b48e)[0x61937ce6448e] /lib/x86_64-linux-gnu/libstdc++.so.6(+0xf6ca6)[0x7f52f14f6ca6] /lib/x86_64-linux-gnu/libc.so.6(+0x94ac3)[0x7f52f1094ac3] /lib/x86_64-linux-gnu/libc.so.6(+0x1268d0)[0x7f52f11268d0]
Aborted (core dumped) (py310) csrobot@csrobot-DGX-Station:~/chenmc/cosyvoice.cpp$
然后我本地是V100,一个是不支持flatn的,添加命令--llm-flash-attn 0 --flow-flash-attn 0后才能运行,不过速度层面是没影响的,但是中途打断再运行也是报这个错就有点奇怪,哈哈哈
看着好像是因为关闭了 fattn 但又走 fattn 算子了。你是怎么打断了?是不是请求 server 响应过程中 client 断开连接?
就是流式播放的时候直接杀掉python程序啊,应该是还在生成,然后再调用的时候AI说是服务被占用什么的
我刚刚添加了 server 检测到断开连接自动停止的机制,应该能迅速响应后续请求了