voicevox_client_cpp  0.0.0
A client library for VOICEVOX implemented in C++.

build-document run-tests

An Unofficial client library for VOICEVOX implemented in C++.

It also provides an interface for calling from other languages. Still under testing

Link to the Document

Required

  • C++ 17
  • cpprestsdk

Supported OS

  • Ubuntu 24.04
  • masOS Sonoma 14.5

How to build and install

# for Ubuntu
sudo apt install libcpprest-dev
# for macOS
brew install cpprestsdk
mkdir build
cd build
cmake ..
# build
make
# install
sudo make install

How to build the docker image

docker build -t vvccpp:latest .

A sample code for speech synthesis

#include <iostream>
int main(int argc, char** argv)
{
// default text to synthesis
std::string text = "こんにちは";
if (argc > 1)
{
text = argv[1];
}
std::cout << "input: " << text << std::endl;
// Here's an example using a synchronous interface to obtain responses.
// It sends requests in the following order: speech query creation request,
// followed by a speech synthesis request.
// Build a request to create a speech query then send it.
const web::http::http_request req_audio_query = ReqAudioQueryBuilder()
.text(text)
.speaker(3)
.get();
const auto json = voicevox_client_cpp::Client::GetInstance("http://localhost:50021")
// Build a request for speech synthesis then send it.
const web::http::http_request req_synthesis = ReqSynthesisBuilder()
.speaker(3)
.accent_phrases(json.value())
.get();
const auto string = voicevox_client_cpp::Client::GetInstance("http://localhost:50021")
.Request<voicevox_client_cpp::Client::OptionalString>(req_synthesis);
std::cout << "saved audio file path: " << string.value() << std::endl;
// Please refer to the file below for information on the interface for obtaining responses asynchronously.
// - src/voicevox_client_cpp/sample/post_audio_query_then_synthesis.cpp
return EXIT_SUCCESS;
}
pplx::task< void > Request(const web::http::http_request &req, const CallbackType< OptionalJson > callback_json)
An interface for sending supplies to the server and receiving responses asynchronously.
std::optional< web::json::value > OptionalJson
Responses from the client (in JSON format).
Definition: client.hpp:29
static Client & GetInstance(const std::string &uri)
The only interface for obtaining the client.
web::http::http_request get() noexcept
Create and provide a request based on the settings provided so far.
Definition: request.hpp:42
Builder & speaker(const int speaker)
Set the speaker ID to be used for the query to synthesize Japanese speech.
Definition: post.hpp:52
Builder & text(const utility::string_t &text)
Set the text to be used for the query to synthesize Japanese speech.
Definition: post.hpp:39
A builder for creating requests to obtain audio_query.
Definition: post.hpp:22
Builder & speaker(const int speaker)
Set the speaker ID to be used for the query to synthesize Japanese speech.
Definition: post.hpp:152
Builder & accent_phrases(const web::json::value &accent_phrases)
Set the query for speech synthesis included in the response body of the audio_query request.
Definition: post.hpp:185
Builder & enable_interrogative_upspeak(const bool enable_interrogative_upspeak)
Set a flag to control whether to raise the intonation at the end when it's a question.
Definition: post.hpp:165
A builder for creating requests to obtain audio_query.
Definition: post.hpp:132
voicevox_client_cpp::request::post::synthesis::Builder ReqSynthesisBuilder
Definition: post_audio_query_then_synthesis.cpp:6
int main(int argc, char **argv)
Definition: post_audio_query_then_synthesis.cpp:40
voicevox_client_cpp::request::post::audio_query::Builder ReqAudioQueryBuilder
Definition: post_audio_query_then_synthesis.cpp:5

How to use samples

# Please run the voicevox server before execution of following commands.
docker run \
-it \
--rm \
--net host \
--volume /tmp:/tmp:rw \
vvccpp:24.04 voicevox_client_cpp_sample_post_audio_query_then_synthesis
> input: こんにちは
> received audio size: 50732
> audio file size: 50732
# Please see /tmp then you can find wav files named like yyyymmddhhMMss-koNnichiwa.wav
# 2 files are output because the sample requests 2 queries using sync method and async method.