87 lines
2.9 KiB
C++
87 lines
2.9 KiB
C++
#pragma once
|
|
|
|
// Audio: transcription (POST /v1/audio/transcriptions, multipart), speech
|
|
// (POST /v1/audio/speech, JSON) and voices (/v2/audio/voices and /v1/...).
|
|
// Streamed transcription (SSE over a multipart request) is not offered: the
|
|
// shared ApiClient streams JSON bodies only (SPEC.md ## Gaps).
|
|
|
|
#include <optional>
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
#include "vendors/mistral/types.h"
|
|
|
|
namespace molo::mistral {
|
|
|
|
struct TranscriptionParams {
|
|
static constexpr const char* kDefaultModel = "voxtral-mini-latest";
|
|
std::string model = kDefaultModel;
|
|
// Exactly one source: uploaded bytes, a URL, or a Files API id.
|
|
std::string file_data, file_name; // bytes <= 128 MiB
|
|
std::string file_url; // http(s), <= 2083 chars (spec maxLength)
|
|
std::string file_id;
|
|
std::string language; // "" or ISO code word
|
|
std::optional<double> temperature;
|
|
bool diarize = false;
|
|
std::vector<std::string> context_bias; // <= 100 words
|
|
std::vector<std::string> timestamp_granularities; // segment | word
|
|
void validate() const;
|
|
};
|
|
|
|
struct TranscriptionSegment {
|
|
std::string text, speaker_id;
|
|
double start = 0, end = 0;
|
|
};
|
|
|
|
struct TranscriptionResult {
|
|
std::string model, text, language;
|
|
std::vector<TranscriptionSegment> segments;
|
|
TokenUsage usage;
|
|
Json raw;
|
|
static TranscriptionResult parse(const Json& doc);
|
|
};
|
|
|
|
struct SpeechParams {
|
|
std::string model; // "" lets the server choose
|
|
std::string input; // text, 1..32768 chars
|
|
std::string voice_id; // either voice_id or ref_audio
|
|
std::string ref_audio; // base64 audio
|
|
std::string response_format; // "", pcm, wav, mp3, flac, opus
|
|
void validate() const;
|
|
Json to_json() const;
|
|
};
|
|
|
|
struct VoiceCreateParams {
|
|
std::string name; // 1..128
|
|
std::string slug;
|
|
std::vector<std::string> languages;
|
|
std::string gender, description;
|
|
std::optional<int> age;
|
|
std::vector<std::string> tags;
|
|
std::string sample_audio; // base64
|
|
std::string sample_filename;
|
|
void validate() const;
|
|
Json to_json() const;
|
|
};
|
|
|
|
struct VoiceListParams {
|
|
int page_size = 50; // 1..100
|
|
std::string page_token, type, gender, language, query;
|
|
void validate() const;
|
|
};
|
|
|
|
class Audio : public MistralService {
|
|
public:
|
|
explicit Audio(std::shared_ptr<llm::ApiClient> client) : MistralService(std::move(client)) {}
|
|
TranscriptionResult transcribe(const TranscriptionParams& params);
|
|
Json speech(const SpeechParams& params);
|
|
Json voices(const VoiceListParams& params = {});
|
|
Json voice(const std::string& voice_id);
|
|
Json create_voice(const VoiceCreateParams& params);
|
|
Json update_voice(const std::string& voice_id, const Json& fields); // name, languages, gender, age, tags, description
|
|
Json remove_voice(const std::string& voice_id); // explicit, irreversible
|
|
std::string voice_sample(const std::string& voice_id); // audio/wav bytes
|
|
};
|
|
|
|
} // namespace molo::mistral
|