64 lines
1.9 KiB
C++
64 lines
1.9 KiB
C++
#pragma once
|
|||
|
|
|
||
|
|
// The two speech seams of a voice pipeline. Backends implement them:
|
||
|
|
// classic Cloud TTS/STT (TextToSpeech, SpeechToText) or Gemini audio
|
||
|
|
// (GeminiSynthesizer, GeminiRecognizer). Callers never know which.
|
||
|
|
|
||
|
|
#include <string>
|
||
|
|
|
||
|
|
namespace molo::google {
|
||
|
|
|
||
|
|
enum class AudioEncoding { kMp3, kLinear16, kOggOpus };
|
||
|
|
|
||
|
|
const char* audio_encoding_name(AudioEncoding encoding); // Google enum name.
|
||
|
|
const char* audio_encoding_mime(AudioEncoding encoding);
|
||
|
|
|
||
|
|
struct SynthesisRequest {
|
||
|
|
std::string text;
|
||
|
|
bool ssml = false; // Classic Cloud TTS only.
|
||
|
|
std::string language = "nl-NL";
|
||
|
|
std::string voice; // Empty: backend default.
|
||
|
|
AudioEncoding encoding = AudioEncoding::kMp3; // Classic Cloud TTS only.
|
||
|
|
double speaking_rate = 1.0; // 0.25 .. 4.0, classic Cloud TTS only.
|
||
|
|
};
|
||
|
|
|
||
|
|
struct Audio {
|
||
|
|
std::string bytes;
|
||
|
|
std::string mime;
|
||
|
|
};
|
||
|
|
|
||
|
|
enum class SpeechEncoding { kWebmOpus, kOggOpus, kFlac, kLinear16, kMp3 };
|
||
|
|
|
||
|
|
const char* speech_encoding_name(SpeechEncoding encoding); // Google enum name.
|
||
|
|
const char* speech_encoding_mime(SpeechEncoding encoding); // Content type.
|
||
|
|
// Maps a browser/content type ("audio/webm;codecs=opus", "audio/ogg", ...)
|
||
|
|
// to an encoding. Returns false when unknown.
|
||
|
|
bool speech_encoding_from_mime(const std::string& mime, SpeechEncoding& out);
|
||
|
|
|
||
|
|
struct RecognitionRequest {
|
||
|
|
std::string audio; // Raw bytes.
|
||
|
|
SpeechEncoding encoding = SpeechEncoding::kWebmOpus;
|
||
|
|
std::string language = "nl-NL";
|
||
|
|
int sample_rate_hz = 0; // 0: taken from the container header.
|
||
|
|
bool punctuation = true;
|
||
|
|
};
|
||
|
|
|
||
|
|
struct Transcript {
|
||
|
|
std::string text;
|
||
|
|
double confidence = 0.0; // 0 when the backend does not report one.
|
||
|
|
};
|
||
|
|
|
||
|
|
class Synthesizer {
|
||
|
|
public:
|
||
|
|
virtual ~Synthesizer() = default;
|
||
|
|
virtual Audio synthesize(const SynthesisRequest& request) const = 0;
|
||
|
|
};
|
||
|
|
|
||
|
|
class Recognizer {
|
||
|
|
public:
|
||
|
|
virtual ~Recognizer() = default;
|
||
|
|
virtual Transcript recognize(const RecognitionRequest& request) const = 0;
|
||
|
|
};
|
||
|
|
|
||
|
|
} // namespace molo::google
|