Skip to content

fix: client lost the last segment of audio in online mode#3301

Open
dio-del wants to merge 1 commit into
modelscope:mainfrom
dio-del:main
Open

fix: client lost the last segment of audio in online mode#3301
dio-del wants to merge 1 commit into
modelscope:mainfrom
dio-del:main

Conversation

@dio-del

@dio-del dio-del commented Jul 20, 2026

Copy link
Copy Markdown

Summary

Fixed the issue where the client lost the last segment of audio in online mode and ensured that the server no longer returns offline results in online mode. In online mode, you can see that in the figure, 2pass-online misses the character “型”, and the result can only be obtained using 2pass-offline. Also, offline results should not be returned in online mode.

Type of change

  • Bug fix
  • Documentation
  • Example or demo
  • Runtime or deployment
  • Benchmark or evaluation
  • Model/training change

Validation

before
before
after
after

  • python -m compileall funasr examples tests
  • Docs or links checked
  • Runtime/deployment command tested

User impact

New users and production deployers

Notes for reviewers

None

Fixed the issue where the client lost the last segment of audio in online mode and ensured that the server no longer returns offline results in online mode. In online mode, you can see that in the figure, 2pass-online misses the character “型”, and the result can only be obtained using 2pass-offline. Also, offline results should not be returned in online mode.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the handle_result function in websocket-server-2pass.cpp to accept a modetype parameter, allowing the server to skip offline results when in 'online' mode to prevent overwriting online results. The review feedback suggests two improvements: first, perform a null check on the return value of FunASRGetTpassResult before constructing a std::string to avoid potential undefined behavior and segmentation faults; second, pass the modetype parameter by const std::string& instead of by value to prevent unnecessary copy operations.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +100 to +101
std::string tmp_tpass_msg = FunASRGetTpassResult(result, 0);
if (tmp_tpass_msg != "") {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The C-style API function FunASRGetTpassResult returns a const char* which could potentially be nullptr. Constructing a std::string directly from a nullptr results in undefined behavior and can cause a segmentation fault. It is safer to perform a null check before constructing the std::string.

Suggested change
std::string tmp_tpass_msg = FunASRGetTpassResult(result, 0);
if (tmp_tpass_msg != "") {
const char* tpass_res = FunASRGetTpassResult(result, 0);
std::string tmp_tpass_msg = tpass_res ? tpass_res : "";
if (!tmp_tpass_msg.empty()) {

}

nlohmann::json handle_result(FUNASR_RESULT result, websocketpp::connection_hdl& hdl, std::map<websocketpp::connection_hdl, std::shared_ptr<FUNASR_MESSAGE>,std::owner_less<websocketpp::connection_hdl>>& data_map) {
nlohmann::json handle_result(FUNASR_RESULT result, websocketpp::connection_hdl& hdl, std::map<websocketpp::connection_hdl, std::shared_ptr<FUNASR_MESSAGE>,std::owner_less<websocketpp::connection_hdl>>& data_map, std::string modetype) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Passing std::string by value can result in unnecessary copy operations. It is more efficient to pass it by const std::string& to avoid copying the string on every call.

Suggested change
nlohmann::json handle_result(FUNASR_RESULT result, websocketpp::connection_hdl& hdl, std::map<websocketpp::connection_hdl, std::shared_ptr<FUNASR_MESSAGE>,std::owner_less<websocketpp::connection_hdl>>& data_map, std::string modetype) {
nlohmann::json handle_result(FUNASR_RESULT result, websocketpp::connection_hdl& hdl, std::map<websocketpp::connection_hdl, std::shared_ptr<FUNASR_MESSAGE>,std::owner_less<websocketpp::connection_hdl>>& data_map, const std::string& modetype) {

@dio-del dio-del changed the title fixed websocket-server-2pass.cpp fix: client lost the last segment of audio in online mode Jul 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant