mirror of
https://github.com/modelscope/FunASR
synced 2025-09-15 14:48:36 +08:00
* add cmakelist * add paraformer-torch * add debug for funasr-onnx-offline * fix redefinition of jieba StdExtension.hpp * add loading torch models * update funasr-onnx-offline * add SwitchArg for wss-server * add SwitchArg for funasr-onnx-offline * update cmakelist * update funasr-onnx-offline-rtf * add define condition * add gpu define for offlne-stream * update com define * update offline-stream * update cmakelist * update func CompileHotwordEmbedding * add timestamp for paraformer-torch * add C10_USE_GLOG for paraformer-torch * update paraformer-torch * fix func FunASRWfstDecoderInit * update model.h * fix func FunASRWfstDecoderInit * fix tpass_stream * update paraformer-torch * add bladedisc for funasr-onnx-offline * update comdefine * update funasr-wss-server * add log for torch * fix GetValue BLADEDISC * fix log * update cmakelist * update warmup to 10 * update funasrruntime * add batch_size for wss-server * add batch for bins * add batch for offline-stream * add batch for paraformer * add batch for offline-stream * fix func SetBatchSize * add SetBatchSize for model * add SetBatchSize for model * fix func Forward * fix padding * update funasrruntime * add dec reset for batch * set batch default value * add argv for CutSplit * sort frame_queue * sorted msgs * fix FunOfflineInfer * add dynamic batch for fetch * fix FetchDynamic * update run_server.sh * update run_server.sh * cpp http post server support (#1739) * add cpp http server * add some comment * remove some comments * del debug infos * restore run_server.sh * adapt to new model struct * 修复了onnxruntime在macos下编译失败的错误 (#1748) * Add files via upload 增加macos的编译支持 * Add files via upload 增加macos支持 * Add files via upload target_link_directories(funasr PUBLIC ${ONNXRUNTIME_DIR}/lib) target_link_directories(funasr PUBLIC ${FFMPEG_DIR}/lib) 添加 if(APPLE) 限制 --------- Co-authored-by: Yabin Li <wucong.lyb@alibaba-inc.com> * Delete docs/images/wechat.png * Add files via upload * fixed the issues about seaco-onnx timestamp * fix bug (#1764) 当语音识别结果包含 `http` 时,标点符号预测会把它会被当成 url * fix empty asr result (#1765) 解码结果为空的语音片段,text 用空字符串 * docs * docs * docs * docs * docs * keep empty speech result (#1772) * docs * docs * update wechat QRcode * Add python funasr api support for websocket srv (#1777) * add python funasr_api supoort * change little to README.md * add core tools stream * modified a little * fix bug for timeout * support for buffer decode * add ffmpeg decode for buffer * auto frontend * auto frontend --------- Co-authored-by: 雾聪 <wucong.lyb@alibaba-inc.com> Co-authored-by: zhaomingwork <61895407+zhaomingwork@users.noreply.github.com> Co-authored-by: szsteven008 <97944818+szsteven008@users.noreply.github.com> Co-authored-by: Ephemeroptera <605686962@qq.com> Co-authored-by: 彭震东 <zhendong.peng@qq.com> Co-authored-by: Shi Xian <40013335+R1ckShi@users.noreply.github.com> Co-authored-by: 维石 <shixian.shi@alibaba-inc.com>
246 lines
7.5 KiB
C++
246 lines
7.5 KiB
C++
/**
|
|
* Copyright FunASR (https://github.com/alibaba-damo-academy/FunASR). All Rights
|
|
* Reserved. MIT License (https://opensource.org/licenses/MIT)
|
|
*/
|
|
/* 2023-2024 by zhaomingwork@qq.com */
|
|
// reply.cpp
|
|
// ~~~~~~~~~
|
|
//
|
|
// copy some codes from http://www.boost.org/
|
|
|
|
#include "reply.hpp"
|
|
|
|
#include <iostream>
|
|
#include <string>
|
|
namespace http {
|
|
namespace server2 {
|
|
|
|
namespace status_strings {
|
|
|
|
const std::string ok = "HTTP/1.0 200 OK\r\n";
|
|
const std::string created = "HTTP/1.0 201 Created\r\n";
|
|
const std::string accepted = "HTTP/1.0 202 Accepted\r\n";
|
|
const std::string no_content = "HTTP/1.0 204 No Content\r\n";
|
|
const std::string multiple_choices = "HTTP/1.0 300 Multiple Choices\r\n";
|
|
const std::string moved_permanently = "HTTP/1.0 301 Moved Permanently\r\n";
|
|
const std::string moved_temporarily = "HTTP/1.0 302 Moved Temporarily\r\n";
|
|
const std::string not_modified = "HTTP/1.0 304 Not Modified\r\n";
|
|
const std::string bad_request = "HTTP/1.0 400 Bad Request\r\n";
|
|
const std::string unauthorized = "HTTP/1.0 401 Unauthorized\r\n";
|
|
const std::string forbidden = "HTTP/1.0 403 Forbidden\r\n";
|
|
const std::string not_found = "HTTP/1.0 404 Not Found\r\n";
|
|
const std::string internal_server_error =
|
|
"HTTP/1.0 500 Internal Server Error\r\n";
|
|
const std::string not_implemented = "HTTP/1.0 501 Not Implemented\r\n";
|
|
const std::string bad_gateway = "HTTP/1.0 502 Bad Gateway\r\n";
|
|
const std::string service_unavailable = "HTTP/1.0 503 Service Unavailable\r\n";
|
|
|
|
asio::const_buffer to_buffer(reply::status_type status) {
|
|
switch (status) {
|
|
case reply::ok:
|
|
return asio::buffer(ok);
|
|
case reply::created:
|
|
return asio::buffer(created);
|
|
case reply::accepted:
|
|
return asio::buffer(accepted);
|
|
case reply::no_content:
|
|
return asio::buffer(no_content);
|
|
case reply::multiple_choices:
|
|
return asio::buffer(multiple_choices);
|
|
case reply::moved_permanently:
|
|
return asio::buffer(moved_permanently);
|
|
case reply::moved_temporarily:
|
|
return asio::buffer(moved_temporarily);
|
|
case reply::not_modified:
|
|
return asio::buffer(not_modified);
|
|
case reply::bad_request:
|
|
return asio::buffer(bad_request);
|
|
case reply::unauthorized:
|
|
return asio::buffer(unauthorized);
|
|
case reply::forbidden:
|
|
return asio::buffer(forbidden);
|
|
case reply::not_found:
|
|
return asio::buffer(not_found);
|
|
case reply::internal_server_error:
|
|
return asio::buffer(internal_server_error);
|
|
case reply::not_implemented:
|
|
return asio::buffer(not_implemented);
|
|
case reply::bad_gateway:
|
|
return asio::buffer(bad_gateway);
|
|
case reply::service_unavailable:
|
|
return asio::buffer(service_unavailable);
|
|
default:
|
|
return asio::buffer(internal_server_error);
|
|
}
|
|
}
|
|
|
|
} // namespace status_strings
|
|
|
|
namespace misc_strings {
|
|
|
|
const char name_value_separator[] = {':', ' '};
|
|
const char crlf[] = {'\r', '\n'};
|
|
|
|
} // namespace misc_strings
|
|
|
|
std::vector<::asio::const_buffer> reply::to_buffers() {
|
|
std::vector<::asio::const_buffer> buffers;
|
|
buffers.push_back(status_strings::to_buffer(status));
|
|
for (std::size_t i = 0; i < headers.size(); ++i) {
|
|
header &h = headers[i];
|
|
buffers.push_back(asio::buffer(h.name));
|
|
buffers.push_back(asio::buffer(misc_strings::name_value_separator));
|
|
buffers.push_back(asio::buffer(h.value));
|
|
buffers.push_back(asio::buffer(misc_strings::crlf));
|
|
}
|
|
buffers.push_back(asio::buffer(misc_strings::crlf));
|
|
buffers.push_back(asio::buffer(content));
|
|
|
|
return buffers;
|
|
}
|
|
|
|
namespace stock_replies {
|
|
|
|
const char ok[] = "";
|
|
const char created[] =
|
|
"<html>"
|
|
"<head><title>Created</title></head>"
|
|
"<body><h1>201 Created</h1></body>"
|
|
"</html>";
|
|
const char accepted[] =
|
|
"<html>"
|
|
"<head><title>Accepted</title></head>"
|
|
"<body><h1>202 Accepted</h1></body>"
|
|
"</html>";
|
|
const char no_content[] =
|
|
"<html>"
|
|
"<head><title>No Content</title></head>"
|
|
"<body><h1>204 Content</h1></body>"
|
|
"</html>";
|
|
const char multiple_choices[] =
|
|
"<html>"
|
|
"<head><title>Multiple Choices</title></head>"
|
|
"<body><h1>300 Multiple Choices</h1></body>"
|
|
"</html>";
|
|
const char moved_permanently[] =
|
|
"<html>"
|
|
"<head><title>Moved Permanently</title></head>"
|
|
"<body><h1>301 Moved Permanently</h1></body>"
|
|
"</html>";
|
|
const char moved_temporarily[] =
|
|
"<html>"
|
|
"<head><title>Moved Temporarily</title></head>"
|
|
"<body><h1>302 Moved Temporarily</h1></body>"
|
|
"</html>";
|
|
const char not_modified[] =
|
|
"<html>"
|
|
"<head><title>Not Modified</title></head>"
|
|
"<body><h1>304 Not Modified</h1></body>"
|
|
"</html>";
|
|
const char bad_request[] =
|
|
"<html>"
|
|
"<head><title>Bad Request</title></head>"
|
|
"<body><h1>400 Bad Request</h1></body>"
|
|
"</html>";
|
|
const char unauthorized[] =
|
|
"<html>"
|
|
"<head><title>Unauthorized</title></head>"
|
|
"<body><h1>401 Unauthorized</h1></body>"
|
|
"</html>";
|
|
const char forbidden[] =
|
|
"<html>"
|
|
"<head><title>Forbidden</title></head>"
|
|
"<body><h1>403 Forbidden</h1></body>"
|
|
"</html>";
|
|
const char not_found[] =
|
|
"<html>"
|
|
"<head><title>Not Found</title></head>"
|
|
"<body><h1>404 Not Found</h1></body>"
|
|
"</html>";
|
|
const char internal_server_error[] =
|
|
"<html>"
|
|
"<head><title>Internal Server Error</title></head>"
|
|
"<body><h1>500 Internal Server Error</h1></body>"
|
|
"</html>";
|
|
const char not_implemented[] =
|
|
"<html>"
|
|
"<head><title>Not Implemented</title></head>"
|
|
"<body><h1>501 Not Implemented</h1></body>"
|
|
"</html>";
|
|
const char bad_gateway[] =
|
|
"<html>"
|
|
"<head><title>Bad Gateway</title></head>"
|
|
"<body><h1>502 Bad Gateway</h1></body>"
|
|
"</html>";
|
|
const char service_unavailable[] =
|
|
"<html>"
|
|
"<head><title>Service Unavailable</title></head>"
|
|
"<body><h1>503 Service Unavailable</h1></body>"
|
|
"</html>";
|
|
|
|
std::string to_string(reply::status_type status) {
|
|
switch (status) {
|
|
case reply::ok:
|
|
return ok;
|
|
case reply::created:
|
|
return created;
|
|
case reply::accepted:
|
|
return accepted;
|
|
case reply::no_content:
|
|
return no_content;
|
|
case reply::multiple_choices:
|
|
return multiple_choices;
|
|
case reply::moved_permanently:
|
|
return moved_permanently;
|
|
case reply::moved_temporarily:
|
|
return moved_temporarily;
|
|
case reply::not_modified:
|
|
return not_modified;
|
|
case reply::bad_request:
|
|
return bad_request;
|
|
case reply::unauthorized:
|
|
return unauthorized;
|
|
case reply::forbidden:
|
|
return forbidden;
|
|
case reply::not_found:
|
|
return not_found;
|
|
case reply::internal_server_error:
|
|
return internal_server_error;
|
|
case reply::not_implemented:
|
|
return not_implemented;
|
|
case reply::bad_gateway:
|
|
return bad_gateway;
|
|
case reply::service_unavailable:
|
|
return service_unavailable;
|
|
default:
|
|
return internal_server_error;
|
|
}
|
|
}
|
|
|
|
} // namespace stock_replies
|
|
reply reply::stock_reply(std::string jsonresult) {
|
|
reply rep;
|
|
rep.status = reply::ok;
|
|
rep.content = jsonresult+"\n";
|
|
rep.headers.resize(2);
|
|
rep.headers[0].name = "Content-Length";
|
|
rep.headers[0].value = std::to_string(rep.content.size());
|
|
rep.headers[1].name = "Content-Type";
|
|
rep.headers[1].value = "text/html;charset=utf-8";
|
|
return rep;
|
|
}
|
|
reply reply::stock_reply(reply::status_type status) {
|
|
reply rep;
|
|
rep.status = status;
|
|
rep.content = stock_replies::to_string(status);
|
|
rep.headers.resize(2);
|
|
rep.headers[0].name = "Content-Length";
|
|
rep.headers[0].value = std::to_string(rep.content.size());
|
|
rep.headers[1].name = "Content-Type";
|
|
rep.headers[1].value = "text/html";
|
|
return rep;
|
|
}
|
|
|
|
} // namespace server2
|
|
} // namespace http
|