From 977d51473fe8fccbfead4e874dabf19036cd66ed Mon Sep 17 00:00:00 2001 From: Yang Zhou Date: Fri, 27 May 2022 17:51:12 +0800 Subject: [PATCH] fix websocket key, mv websocket into protocol, test=doc --- speechx/examples/ds2_ol/websocket/path.sh | 2 +- speechx/speechx/CMakeLists.txt | 4 ++-- speechx/speechx/protocol/CMakeLists.txt | 3 +++ speechx/speechx/{ => protocol}/websocket/CMakeLists.txt | 0 speechx/speechx/{ => protocol}/websocket/websocket_client.cc | 2 +- speechx/speechx/{ => protocol}/websocket/websocket_client.h | 4 ++-- .../speechx/{ => protocol}/websocket/websocket_client_main.cc | 0 speechx/speechx/{ => protocol}/websocket/websocket_server.cc | 2 +- speechx/speechx/{ => protocol}/websocket/websocket_server.h | 0 .../speechx/{ => protocol}/websocket/websocket_server_main.cc | 0 10 files changed, 10 insertions(+), 7 deletions(-) rename speechx/speechx/{ => protocol}/websocket/CMakeLists.txt (100%) rename speechx/speechx/{ => protocol}/websocket/websocket_client.cc (97%) rename speechx/speechx/{ => protocol}/websocket/websocket_client.h (93%) rename speechx/speechx/{ => protocol}/websocket/websocket_client_main.cc (100%) rename speechx/speechx/{ => protocol}/websocket/websocket_server.cc (98%) rename speechx/speechx/{ => protocol}/websocket/websocket_server.h (100%) rename speechx/speechx/{ => protocol}/websocket/websocket_server_main.cc (100%) diff --git a/speechx/examples/ds2_ol/websocket/path.sh b/speechx/examples/ds2_ol/websocket/path.sh index 3ad03203..d25e88a2 100755 --- a/speechx/examples/ds2_ol/websocket/path.sh +++ b/speechx/examples/ds2_ol/websocket/path.sh @@ -10,5 +10,5 @@ TOOLS_BIN=$SPEECHX_TOOLS/valgrind/install/bin export LC_AL=C -SPEECHX_BIN=$SPEECHX_BUILD/websocket +SPEECHX_BIN=$SPEECHX_BUILD/protocol/websocket export PATH=$PATH:$SPEECHX_BIN:$TOOLS_BIN diff --git a/speechx/speechx/CMakeLists.txt b/speechx/speechx/CMakeLists.txt index a9a8a398..c8e21d48 100644 --- a/speechx/speechx/CMakeLists.txt +++ b/speechx/speechx/CMakeLists.txt @@ -34,9 +34,9 @@ add_subdirectory(decoder) include_directories( ${CMAKE_CURRENT_SOURCE_DIR} -${CMAKE_CURRENT_SOURCE_DIR}/websocket +${CMAKE_CURRENT_SOURCE_DIR}/protocol ) -add_subdirectory(websocket) +add_subdirectory(protocol) include_directories( ${CMAKE_CURRENT_SOURCE_DIR} diff --git a/speechx/speechx/protocol/CMakeLists.txt b/speechx/speechx/protocol/CMakeLists.txt index e69de29b..98b2f38b 100644 --- a/speechx/speechx/protocol/CMakeLists.txt +++ b/speechx/speechx/protocol/CMakeLists.txt @@ -0,0 +1,3 @@ +cmake_minimum_required(VERSION 3.14 FATAL_ERROR) + +add_subdirectory(websocket) diff --git a/speechx/speechx/websocket/CMakeLists.txt b/speechx/speechx/protocol/websocket/CMakeLists.txt similarity index 100% rename from speechx/speechx/websocket/CMakeLists.txt rename to speechx/speechx/protocol/websocket/CMakeLists.txt diff --git a/speechx/speechx/websocket/websocket_client.cc b/speechx/speechx/protocol/websocket/websocket_client.cc similarity index 97% rename from speechx/speechx/websocket/websocket_client.cc rename to speechx/speechx/protocol/websocket/websocket_client.cc index 3a852305..60e06db6 100644 --- a/speechx/speechx/websocket/websocket_client.cc +++ b/speechx/speechx/protocol/websocket/websocket_client.cc @@ -68,7 +68,7 @@ void WebSocketClient::ReadLoopFunc() { result_ = obj["result"].as_string().c_str(); } if (obj["type"] == "partial_result") { - partial_result_ = obj["partial_result"].as_string().c_str(); + partial_result_ = obj["result"].as_string().c_str(); } if (obj["type"] == "speech_end") { done_ = true; diff --git a/speechx/speechx/websocket/websocket_client.h b/speechx/speechx/protocol/websocket/websocket_client.h similarity index 93% rename from speechx/speechx/websocket/websocket_client.h rename to speechx/speechx/protocol/websocket/websocket_client.h index 7d05448e..8635501a 100644 --- a/speechx/speechx/websocket/websocket_client.h +++ b/speechx/speechx/protocol/websocket/websocket_client.h @@ -40,8 +40,8 @@ class WebSocketClient { void SendEndSignal(); void SendDataEnd(); bool Done() const { return done_; } - std::string GetResult() { return result_; } - std::string GetPartialResult() { return partial_result_; } + std::string GetResult() const { return result_; } + std::string GetPartialResult() const { return partial_result_;} private: void Connect(); diff --git a/speechx/speechx/websocket/websocket_client_main.cc b/speechx/speechx/protocol/websocket/websocket_client_main.cc similarity index 100% rename from speechx/speechx/websocket/websocket_client_main.cc rename to speechx/speechx/protocol/websocket/websocket_client_main.cc diff --git a/speechx/speechx/websocket/websocket_server.cc b/speechx/speechx/protocol/websocket/websocket_server.cc similarity index 98% rename from speechx/speechx/websocket/websocket_server.cc rename to speechx/speechx/protocol/websocket/websocket_server.cc index 569f5378..a1abd98e 100644 --- a/speechx/speechx/websocket/websocket_server.cc +++ b/speechx/speechx/protocol/websocket/websocket_server.cc @@ -78,7 +78,7 @@ void ConnectionHandler::OnSpeechData(const beast::flat_buffer& buffer) { std::string partial_result = recognizer_->GetPartialResult(); json::value rv = { - {"status", "ok"}, {"type", "partial_result"}, {"partial_result", partial_result}}; + {"status", "ok"}, {"type", "partial_result"}, {"result", partial_result}}; ws_.text(true); ws_.write(asio::buffer(json::serialize(rv))); } diff --git a/speechx/speechx/websocket/websocket_server.h b/speechx/speechx/protocol/websocket/websocket_server.h similarity index 100% rename from speechx/speechx/websocket/websocket_server.h rename to speechx/speechx/protocol/websocket/websocket_server.h diff --git a/speechx/speechx/websocket/websocket_server_main.cc b/speechx/speechx/protocol/websocket/websocket_server_main.cc similarity index 100% rename from speechx/speechx/websocket/websocket_server_main.cc rename to speechx/speechx/protocol/websocket/websocket_server_main.cc