Skip to content

feat: support /v1/audio/speech api request.#1272

Open
wxh571001500 wants to merge 3 commits intojd-opensource:mainfrom
wxh571001500:speech-api
Open

feat: support /v1/audio/speech api request.#1272
wxh571001500 wants to merge 3 commits intojd-opensource:mainfrom
wxh571001500:speech-api

Conversation

@wxh571001500
Copy link
Copy Markdown
Contributor

No description provided.

@wxh571001500 wxh571001500 changed the title feat: support /v1/audio/speech api request feat: support /v1/audio/speech api request. Apr 14, 2026
Copy link
Copy Markdown
Contributor

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

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 implements a new speech service, adding the /v1/audio/speech endpoint and supporting infrastructure including SpeechServiceImpl, protobuf definitions, and request routing logic. Review feedback highlights several violations of the project's style guide, specifically the improper use of auto for primitive types, the lack of parameter annotations for constant arguments, and the use of push_back instead of emplace_back. Furthermore, a functional issue was identified in the speech processing logic where the service fails to return audio data upon completion, instead returning a placeholder error message.

done_guard.release(),
const_cast<proto::SpeechRequest*>(request),
response,
true);
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

Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors to improve readability.

                                   /*use_arena=*/true);
References
  1. Annotate constant arguments with a comment indicating the parameter name when calling functions or constructors. (link)

json2pb::Json2PbOptions options;
butil::IOBuf& buf = ctrl->request_attachment();
butil::IOBufAsZeroCopyInputStream iobuf_stream(buf);
auto st = json2pb::JsonToProtoMessage(&iobuf_stream, req_pb, options, &error);
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

Do not use auto for simple/primitive types like bool. Explicitly state the type to maintain clarity.

  bool st = json2pb::JsonToProtoMessage(&iobuf_stream, req_pb, options, &error);
References
  1. Do not use auto for simple/primitive types (int32_t, float, bool, std::string, etc.). (link)

segments.reserve(seg_list.segments_size());
for (const auto& proto_seg : seg_list.segments()) {
segments.emplace_back(proto_seg.offset(), proto_seg.size());
segments.push_back({proto_seg.offset(), proto_seg.size()});
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

Prefer emplace_back over push_back to construct elements in-place and avoid unnecessary copies or temporary objects.

          segments.emplace_back(proto_seg.offset(), proto_seg.size());
References
  1. Prefer emplace_back over push_back to construct elements in-place and avoid unnecessary copies. (link)

RequestParams request_params(
request, call->get_x_request_id(), call->get_x_request_time());

auto prompt = request.input();
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

Do not use auto for std::string. Use the explicit type to adhere to the project's coding style.

Suggested change
auto prompt = request.input();
std::string prompt = request.input();
References
  1. Do not use auto for simple/primitive types (int32_t, float, bool, std::string, etc.). (link)

Comment on lines +143 to +146
if (req_output.finished || req_output.cancelled) {
return call->finish_with_error(StatusCode::UNAVAILABLE,
kRuntimeUnavailableMessage);
}
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 current implementation does not extract audio data from req_output and always returns an error when the request is finished. This prevents the API from actually delivering speech output. Please ensure the audio data is correctly extracted and populated in the response.

Comment thread xllm/api_service/api_service.cpp Outdated

const char* kSampleNotSupportedError = "/v1/sample is only supported for LLM";
std::string build_sample_backend_error_message() {
return "Current backend '" + FLAGS_backend +
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这个FLAGS_backend已经全局删除了

@wxh571001500 wxh571001500 force-pushed the speech-api branch 2 times, most recently from 667caf5 to b80901f Compare April 23, 2026 09:51
::google::protobuf::Closure* done) {
xllm::ClosureGuard done_guard(
done,
std::bind(request_in_metric, nullptr),
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

use lambda func instead of std::bind

xllm::ClosureGuard done_guard(
done,
std::bind(request_in_metric, nullptr),
std::bind(request_out_metric, (void*)controller));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

ditto

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.

3 participants