BarkModel<T>
Models & Types · AiDotNet.TextToSpeech.CodecBased
Low-level, checkpoint-faithful Bark foundation model.
Inheritance: NeuralNetworkBase<T> → TtsModelBase<T> → BarkModel<T>
Known derived types: Bark<T>
For Beginners
Use Bark when starting from text. Use this class
when you already have tokenizer IDs, want intermediate audio tokens, or are training one stage.
How It Works
Bark has four distinct stages: causal semantic GPT, causal coarse GPT, bidirectional fine GPT,
and EnCodec. This class is the one neural implementation used by the high-level
Bark façade. The stage layers live in the standard model layer graph, so base
lifecycle and generator automation own parameters, gradients, cloning, serialization, and
shape discovery.
Constructors
| Constructor | Summary |
|---|---|
BarkModel(BarkOptions options, IAudioCodec<T> codec, int? seed) |
Creates Bark using an explicit framework architecture descriptor. |
BarkModel(NeuralNetworkArchitecture<T> architecture, BarkOptions options, IAudioCodec<T> codec) |
Creates Bark using an explicit framework architecture descriptor. |
Properties
| Property | Summary |
|---|---|
BarkOptions BarkConfiguration { get; } |
The validated Bark configuration. |
bool IsCoarseCacheActive { get; } |
Whether the coarse stage currently has an active KV-cache. |
bool IsSemanticCacheActive { get; } |
Whether the semantic stage currently has an active KV-cache. |
int CodebookSize { get; } |
EnCodec codebook vocabulary size. |
int CodecFrameRate { get; } |
EnCodec frame rate. |
int NumberOfCodebooks { get; } |
Number of EnCodec residual-vector-quantization codebooks. |
long EstimatedBarkTransformerParameterCount { get; } |
Exact structural parameter estimate without materializing any lazy transformer weights. |
Methods
| Method | Summary |
|---|---|
BarkGenerationResult<T> Generate(IReadOnlyList<int> textTokenIds, BarkGenerationOptions generationOptions, BarkHistoryPrompt history, CancellationToken cancellationToken) |
Runs all four Bark stages from already-tokenized text. |
IReadOnlyList<int> GenerateSemanticTokens(IReadOnlyList<int> textTokenIds, BarkGenerationOptions generationOptions, BarkHistoryPrompt history, CancellationToken cancellationToken) |
Generates semantic audio tokens from tokenizer IDs. |
ModelMetadata<T> GetModelMetadata() |
|
Task<BarkGenerationResult<T>> GenerateAsync(IReadOnlyList<int> textTokenIds, BarkGenerationOptions generationOptions, BarkHistoryPrompt history, CancellationToken cancellationToken) |
Asynchronous four-stage generation with cooperative cancellation. |
Tensor<T> DecodeAudioTokens(int[] tokens) |
Decodes Bark/EnCodec tokens to a waveform. |
Tensor<T> ForwardForTraining(Tensor<T> input) |
|
Tensor<T> PredictSemanticLogits(IReadOnlyList<int> tokenIds) |
Computes semantic next-token logits without starting generation. |
Vector<T> AppendSemanticToken(int tokenId) |
Appends one semantic token to the KV-cache and returns next-token logits. |
Vector<T> BeginSemanticSequence(IReadOnlyList<int> tokenIds) |
Prefills the semantic KV-cache and returns next-token logits. |
int[] EncodeAudio(Tensor<T> audio) |
Encodes a waveform into Bark/EnCodec tokens. |
int[] GenerateCoarseTokens(IReadOnlyList<int> semanticTokens, BarkGenerationOptions generationOptions, BarkHistoryPrompt history, CancellationToken cancellationToken) |
Generates Bark’s two coarse EnCodec codebooks from semantic tokens. |
int[] GenerateFineTokens(int[] coarseTokens, BarkGenerationOptions generationOptions, BarkHistoryPrompt history, CancellationToken cancellationToken) |
Refines coarse tokens into all eight Bark/EnCodec codebooks. |
void ResetGenerationCaches() |
Clears semantic and coarse generation caches. |
void TrainCoarse(Tensor<T> inputTokenIds, Tensor<T> expectedTokenDistribution) |
Trains the coarse causal language model with categorical next-token targets. |
void TrainFine(Tensor<T> inputCodebooks, int targetCodebook, Tensor<T> expectedTokenDistribution) |
Trains one fine codebook head with categorical token targets. |
void TrainSemantic(Tensor<T> inputTokenIds, Tensor<T> expectedTokenDistribution) |
Trains the semantic causal language model with categorical next-token targets. |