Source code
Revision control
Copy as Markdown
// Copyright (C) 2026 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
// Qt-Security score:significant reason:default
#ifndef TEXTTOSPEECHPROXY_H
#define TEXTTOSPEECHPROXY_H
#include <QtCore/private/qexpected_p.h>
#include <cstdint>
#include <memory>
#include <optional>
#include <string>
#include <vector>
QT_BEGIN_NAMESPACE
namespace CoreSpeechKit {
enum class TtsCompletionType
{
SynthesisComplete,
SpeechComplete,
};
struct SpeakParams
{
std::string text;
double speed;
double volume;
double pitch;
std::string languageContext;
};
struct VoiceInfo
{
std::string language;
std::string style;
std::string gender;
std::string description;
int personTimbre;
std::optional<std::string> status;
};
class TextToSpeechProxy
{
Q_DISABLE_COPY_MOVE(TextToSpeechProxy)
public:
class EngineEventsListener
{
Q_DISABLE_COPY_MOVE(EngineEventsListener)
public:
virtual ~EngineEventsListener();
virtual void onStart(std::string utteranceId) = 0;
virtual void onComplete(std::string utteranceId, std::optional<TtsCompletionType> optCompletionType) = 0;
virtual void onStop(std::string utteranceId) = 0;
virtual void onError(
std::string utteranceId, std::uint32_t errorCode, std::string errorMessage) = 0;
protected:
EngineEventsListener();
};
virtual ~TextToSpeechProxy();
virtual void speak(const SpeakParams ¶ms) = 0;
virtual void stop() = 0;
virtual void setEngineEventsListener(std::shared_ptr<EngineEventsListener> engineEventsListener) = 0;
virtual std::string language() const = 0;
virtual int personTimbre() const = 0;
protected:
TextToSpeechProxy();
};
std::optional<std::vector<VoiceInfo>> tryListVoices();
q23::expected<std::shared_ptr<TextToSpeechProxy>, std::string> tryMakeTextToSpeechProxy(
const std::string &language, int personTimbre);
}
QT_END_NAMESPACE
#endif