Skip to content

Commit

Permalink
Add speech
Browse files Browse the repository at this point in the history
  • Loading branch information
D7EAD authored May 30, 2024
1 parent fc04957 commit a7c9e08
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion liboai/components/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,53 @@ liboai::FutureResponse liboai::Audio::translate_async(const std::filesystem::pat
};

return std::async(std::launch::async, _fn, std::move(form));
}
}

liboai::Response liboai::Audio::speech(const std::string& model, const std::string& voice, const std::string& input, std::optional<std::string> response_format, std::optional<float> speed) const& noexcept(false) {
liboai::JsonConstructor jcon;
jcon.push_back("model", model);
jcon.push_back("voice", voice);
jcon.push_back("input", input);

if (response_format) { jcon.push_back("response_format", std::move(response_format.value())); }
if (speed) { jcon.push_back("speed", speed.value()); }

Response res;
res = this->Request(
Method::HTTP_POST, this->openai_root_, "/audio/speech", "application/json",
this->auth_.GetAuthorizationHeaders(),
netimpl::components::Body {
jcon.dump()
},
this->auth_.GetProxies(),
this->auth_.GetProxyAuth(),
this->auth_.GetMaxTimeout()
);

return res;
}

liboai::FutureResponse liboai::Audio::speech_async(const std::string& model, const std::string& voice, const std::string& input, std::optional<std::string> response_format, std::optional<float> speed) const& noexcept(false) {
liboai::JsonConstructor jcon;
jcon.push_back("model", model);
jcon.push_back("voice", voice);
jcon.push_back("input", input);

if (response_format) { jcon.push_back("response_format", std::move(response_format.value())); }
if (speed) { jcon.push_back("speed", speed.value()); }

auto _fn = [this](liboai::JsonConstructor&& jcon) -> liboai::Response {
return this->Request(
Method::HTTP_POST, this->openai_root_, "/audio/speech", "application/json",
this->auth_.GetAuthorizationHeaders(),
netimpl::components::Body {
jcon.dump()
},
this->auth_.GetProxies(),
this->auth_.GetProxyAuth(),
this->auth_.GetMaxTimeout()
);
};

return std::async(std::launch::async, _fn, std::move(jcon));
}

0 comments on commit a7c9e08

Please sign in to comment.