diff --git a/documentation/audio/README.md b/documentation/audio/README.md index 0588974..793c6e7 100644 --- a/documentation/audio/README.md +++ b/documentation/audio/README.md @@ -3,6 +3,7 @@ This class and its associated liboai::OpenAI interface allow access to the Audio endpoint of the OpenAI API; this endpoint's functionality can be found below.

- Turn audio to text. +- Turn text to audio.

Methods

@@ -62,6 +63,32 @@ liboai::FutureResponse translate_async( ) const& noexcept(false); ``` +

Text to speech

+

Turn text into lifelike spoken audio. Returns a liboai::Response containing response data. The audio data is in the content field of the liboai::Response

+ +```cpp +liboai::Response speech( + const std::string& model, + const std::string& voice, + const std::string& input, + std::optional response_format = std::nullopt, + std::optional speed = std::nullopt +) const& noexcept(false); +``` + +

Text to speech (async)

+

Asynchronously turn text into lifelike spoken audio. Returns a liboai::FutureResponse containing response data. The audio data is in the content field of the liboai::Response

+ +```cpp +liboai::FutureResponse speech_async( + const std::string& model, + const std::string& voice, + const std::string& input, + std::optional response_format = std::nullopt, + std::optional speed = std::nullopt +) const& noexcept(false); +``` +

All function parameters marked optional are not required and are resolved on OpenAI's end if not supplied.


diff --git a/documentation/audio/examples/create_speech.cpp b/documentation/audio/examples/create_speech.cpp index 959ec84..306bf9f 100644 --- a/documentation/audio/examples/create_speech.cpp +++ b/documentation/audio/examples/create_speech.cpp @@ -5,8 +5,6 @@ using namespace liboai; int main() { OpenAI oai; - std::ofstream ocout("demo.mp3", std::ios::binary); - if (oai.auth.SetKeyEnv("OPENAI_API_KEY")) { try { Response res = oai.Audio->speech( @@ -14,6 +12,7 @@ int main() { "alloy", "Today is a wonderful day to build something people love!" ); + std::ofstream ocout("demo.mp3", std::ios::binary); ocout << res.content; ocout.close(); std::cout << res.content.size() << std::endl; diff --git a/documentation/audio/examples/create_speech_async.cpp b/documentation/audio/examples/create_speech_async.cpp index cc60ad1..cd404cb 100644 --- a/documentation/audio/examples/create_speech_async.cpp +++ b/documentation/audio/examples/create_speech_async.cpp @@ -7,7 +7,6 @@ int main() { if (oai.auth.SetKeyEnv("OPENAI_API_KEY")) { try { - std::ofstream ocout("demo.mp3", std::ios::binary); auto fut = oai.Audio->speech_async( "tts-1", "alloy", @@ -20,7 +19,7 @@ int main() { // get the contained response auto res = fut.get(); - + std::ofstream ocout("demo.mp3", std::ios::binary); ocout << res.content; ocout.close(); std::cout << res.content.size() << std::endl;