MoonshineBase<T>
Models & Types · AiDotNet.SpeechRecognition.Streaming
Moonshine Base (Jeffries et al. 2024): an encoder-decoder Transformer over the raw waveform with rotary positions.
Inheritance: NeuralNetworkBase<T> → AudioNeuralNetworkBase<T> → MoonshineBase<T>
Implements: ISpeechRecognizer<T>
For Beginners
Moonshine Base shortens 16 kHz audio 384x with three convolutions, encodes it with Transformer layers, and a second Transformer writes the transcript token by token while reading the encoded audio. It is small and fast enough for live captions on a device.
How It Works
A three-convolution stem compresses the 16 kHz waveform 384x (widths 127, 7 and 3, strides 64, 3 and 2, with tanh and group normalization, then GELU; Figure 3), so the encoder handles audio of any length without padding. Encoder and decoder use rotary position embeddings in every layer; the encoder feed-forward networks use GELU and the decoder ones SwiGLU (Table 1). Moonshine Base is width 416 with 8 encoder and 8 decoder layers and 8 heads; the vocabulary is the Llama byte-level BPE (32,000 tokens) plus 768 special tokens, with start token 1 and end token 2. Training minimizes the decoder’s cross-entropy and transcription decodes greedily.
Example
var architecture = new NeuralNetworkArchitecture<float>(
inputType: InputType.OneDimensional,
taskType: NeuralNetworkTaskType.SpeechRecognition,
inputSize: 16000, outputSize: 34);
var model = new MoonshineBase<float>(architecture);
var text = model.Transcribe(waveform).Text;
Constructors
| Constructor | Summary |
|---|---|
MoonshineBase(NeuralNetworkArchitecture<T> architecture, MoonshineBaseOptions options, IGradientBasedOptimizer<T, Tensor<T>, Tensor<T>> optimizer) |
|
MoonshineBase(NeuralNetworkArchitecture<T> architecture, string modelPath, MoonshineBaseOptions options) |
Properties
| Property | Summary |
|---|---|
IReadOnlyList<string> SupportedLanguages { get; } |
|
bool SupportsStreaming { get; } |
|
bool SupportsWordTimestamps { get; } |
Methods
| Method | Summary |
|---|---|
IReadOnlyDictionary<string, T> DetectLanguageProbabilities(Tensor<T> audio) |
|
IStreamingTranscriptionSession<T> StartStreamingSession(string language) |
|
ModelMetadata<T> GetModelMetadata() |
|
Task<TranscriptionResult<T>> TranscribeAsync(Tensor<T> audio, string language, bool? includeTimestamps, CancellationToken cancellationToken) |
|
Tensor<T> ForwardForTraining(Tensor<T> input) |
|
TranscriptionResult<T> Transcribe(Tensor<T> audio, string language, bool? includeTimestamps) |
Transcribes audio: the encoder and the decoder with greedy decoding. |
string DetectLanguage(Tensor<T> audio) |