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 2b9d96c commit fc04957
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions documentation/audio/examples/create_speech_async.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include "liboai/include/liboai.h"

using namespace liboai;

int main() {
OpenAI oai;

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",
"Today is a wonderful day to build something people love!"
);
// do other work...

// check if the future is ready
fut.wait();

// get the contained response
auto res = fut.get();

ocout << res.content;
ocout.close();
std::cout << res.content.size() << std::endl;
}
catch (const std::exception& e) {
std::cout << e.what() << std::endl;
}
}
}

0 comments on commit fc04957

Please sign in to comment.