Doly C++ SDK v1.00
Loading...
Searching...
No Matches
TtsControl/main.cpp

Demonstrates:

  • Initializing TtsControl
  • Converting text to speech output
#include <chrono>
#include <thread>
#include <spdlog/spdlog.h>
#include "TtsControl.h"
#include "SoundControl.h"
#include "Helper.h"
int main()
{
// Setup spdlog
spdlog::set_level(spdlog::level::info); // Set as needed
spdlog::flush_on(spdlog::level::trace); // flush everything
// *** IMPORTANT ***
// Stop doly service if running,
// otherwise instance of libraries cause conflict
spdlog::error("Doly service stop failed");
return -1;
}
// Initialize Touch Control
spdlog::info("Initialize and load voice model...");
if (TtsControl::init(VoiceModel::MODEL_1, "output.wav") < 0)
{
spdlog::error("TtsControl init failed");
return -2;
}
// get TtsControl version
spdlog::info("TtsControl Version:{:.3f}", TtsControl::getVersion());
// Generate speech sound file from text
spdlog::info("Produce Text to Speech");
TtsControl::produce("Hello, this is a text to speech test example.");
// initialize Sound Control to test sound file
if (SoundControl::init() < 0)
{
spdlog::error("SoundControl init failed");
return -3;
}
// play generated sound file
SoundControl::play("output.wav", 1);
// wait for sound to complete
std::this_thread::sleep_for(std::chrono::seconds(5));
// Cleanup
return 0;
}
Shared helper utilities and common types used across the Doly SDK.
Public API for Doly sound playback control.
Public API for Doly TTS (Text-to-Speech) control.
@ MODEL_1
Definition TtsControl.h:32
int8_t stopDolyService()
Stop the background Doly service (if running).
int8_t dispose()
Dispose/stop the sound subsystem and release resources.
int8_t init()
Initialize sound control.
int8_t play(std::string file_name, uint16_t id)
Start playing a sound file (non-blocking).
float getVersion()
Get the TTS subsystem/library version.
int8_t dispose()
Dispose the TTS system and release resources.
int8_t produce(std::string text)
Produce a speech audio output from text.
int8_t init(VoiceModel model, std::string output_path="")
Initialize the TTS system.