Coder Social home page Coder Social logo

fugashy / voicevox_client_cpp Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 375 KB

A client library for VOICEVOX implemented with C++

Home Page: https://fugashy.github.io/voicevox_client_cpp/

License: BSD 3-Clause "New" or "Revised" License

CMake 5.48% C++ 93.65% Dockerfile 0.87%
cpp cpp17 cpprestsdk rest-api voicevox

voicevox_client_cpp's Introduction

voicevox_client_cpp

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 "voicevox_client_cpp/client.hpp"
#include "voicevox_client_cpp/post.hpp"

#include <iostream>

using ReqAudioQueryBuilder = voicevox_client_cpp::request::post::audio_query::Builder;
using ReqSynthesisBuilder = voicevox_client_cpp::request::post::synthesis::Builder;

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")
    .Request<voicevox_client_cpp::Client::OptionalJson>(req_audio_query);

  // Build a request for speech synthesis then send it.
  const web::http::http_request req_synthesis = ReqSynthesisBuilder()
      .speaker(3)
      .enable_interrogative_upspeak(false)
      .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;
}

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.

voicevox_client_cpp's People

Contributors

fugashy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.