34 lines
1.5 KiB
C++
34 lines
1.5 KiB
C++
// Qwen3-TTS ECAPA-TDNN speaker encoder (ggml C++) — API publique.
|
|
//
|
|
// WAV mono 16-bit 24kHz -> mel 128 -> ECAPA-TDNN forward -> x_vector[1024] f32.
|
|
// Bit-correct vs torch.nn.functional.conv1d (cos > 0.999 vs Python ref).
|
|
//
|
|
// Architecture (cf speaker_encoder.gguf) :
|
|
// blocks.0 Conv1d(128 -> 512, k=5)
|
|
// blocks.1,2,3 SE-Res2Net (tdnn1 1x1 + 7x Conv k=3 + tdnn2 1x1 + se_block)
|
|
// mfa Conv1d(1536 -> 1536, k=1) // concat des 3 blocks
|
|
// asp.tdnn Conv1d(4608 -> 128, k=1) // Attentive Stats Pooling
|
|
// asp.conv Conv1d(128 -> 1536, k=1)
|
|
// fc Linear(3072 -> 1024) // x_vector final
|
|
//
|
|
// Constantes mel : SR=24000, N_FFT=1024, HOP=256, WIN=1024, N_MELS=128, log compression.
|
|
#pragma once
|
|
#include <string>
|
|
#include <vector>
|
|
|
|
struct SpeakerEncoder; // opaque
|
|
|
|
// Charge GGUF + mel_basis (.bin float32 [128,513] = librosa pré-calculé).
|
|
// Retourne nullptr si échec.
|
|
SpeakerEncoder * speaker_encoder_load(const char * gguf_path, const char * mel_basis_path);
|
|
|
|
// Encode un WAV mono 16-bit en x_vector[1024] f32.
|
|
// Le sample rate doit être 24000 (resample externe sinon).
|
|
// Renvoie un vecteur vide en cas d'échec.
|
|
std::vector<float> speaker_encoder_encode_wav(SpeakerEncoder * spk, const char * wav_path);
|
|
|
|
// Encode directement un buffer waveform mono 24kHz (f32 [-1..1]).
|
|
std::vector<float> speaker_encoder_encode_waveform(SpeakerEncoder * spk, const std::vector<float> & wav);
|
|
|
|
void speaker_encoder_free(SpeakerEncoder * spk);
|