93template <ComputeData InputType = std::vector<Kakshya::DataVariant>, ComputeData OutputType = Eigen::MatrixXd>
111 if (
const std::string reason =
diagnose(
config); !reason.empty()) {
113 std::source_location::current(),
"VadAnalyzer: {}", reason);
117 std::source_location::current(),
"VadAnalyzer: {}", reason);
119 m_weights = std::make_shared<const Kakshya::TensorSet>(weights);
135 if (
config.sample_rate !=
static_cast<double>(framing.sample_rate)) {
136 return std::format(
"sample_rate {} is not the {} Hz the network runs at; convert the input first, for example with Kinesis::Discrete::Resampler",
137 config.sample_rate, framing.sample_rate);
148 return safe_any_cast_or_throw<VadAnalysis>(result);
175 std::source_location::current(),
"The recording can only be shared before the network starts");
194 [[nodiscard]]
size_t record(std::span<const float> samples)
197 if (
const std::string reason =
diagnose(cfg); !reason.empty()) {
199 std::source_location::current(),
"VadAnalyzer: {}", reason);
244 [[nodiscard]] std::string
get_name()
const override
246 return "VadAnalyzer";
262 if (
const std::string reason =
diagnose(cfg); !reason.empty()) {
264 std::source_location::current(),
"VadAnalyzer: {}", reason);
270 if (data_span.size() != 1) {
272 std::source_location::current(),
"VadAnalyzer analyses one channel and was given {}", data_span.size());
275 const std::vector<float> samples(data_span[0].begin(), data_span[0].end());
281 if (cfg.flush_tail) {
296 std::vector<std::vector<double>> channel_values(1);
304 }
catch (
const std::exception& e) {
324 mutable std::unique_ptr<SileroVadModel>
m_model;
Modern, digital-first analyzer framework for Maya Flux.
#define MF_ERROR(comp, ctx,...)
#define MF_DESCRIBE(...)
Requests a generated member description for a struct at namespace scope.
The Silero voice activity network run on the GPU, one probability per 512 sample chunk.
void set(T value)
Stores a struct under its type identity.
bool is_initialized() const
Check if compiler is initialized.
void store_current_analysis(AnalysisResultType &&result) const
std::any get_current_analysis() const
Access cached analysis from last operation.
std::any analyze_data(const input_type &data)
User-facing analysis method - returns analysis results directly.
Template-flexible analyzer base with instance-defined I/O types.
const Config & config() const
void set_config(Config config)
Stores a config struct, whole, under its own type.
ConfigRefs stored_configs(Supports< Configs... >) const
The stored configs among those listed, in listed order.
output_type convert_result(std::vector< std::vector< double > > &result_data, DataStructureInfo &metadata)
Convert processed double data back to OutputType using metadata and optional callback.
static std::tuple< NumericChannels, DataStructureInfo > extract_structured_double(T &compute_data)
Extract structured double data from Datum container or direct ComputeData with automatic container ha...
ProbabilityBuffer hidden_buffer()
Where the recurrent output of the latest run is on the device.
ProbabilityBuffer probability_buffer()
The device buffer of the probabilities.
static std::string diagnose(const Kakshya::TensorSet &weights)
Check that a tensor set holds the weights the network needs.
size_t record(std::span< const float > samples)
Run every chunk the samples complete, without waiting for the result.
void keep_hidden(bool keep)
Keep the recurrent output of every chunk process and flush run, for take_hidden.
std::vector< float > flush()
Run the partial chunk, padded with zeros to a whole one.
std::vector< float > process(std::span< const float > samples)
Append samples and run every chunk they complete.
static StreamFraming framing() noexcept
The framing of this network.
std::vector< float > take_hidden()
The recurrent output kept since the last call, hidden_width values per chunk, chunk after chunk.
static constexpr uint32_t chunk_samples
Silero VAD at 16 kHz as a stream: samples in, one speech probability per chunk out.
static float fitness(const input_type &)
One while a device is up, zero otherwise.
VadAnalysis get_speech_analysis() const
void reset()
Start a new signal: forget the recurrent state, the context and any partial chunk.
ConfigRefs configs() const override
The base view of the config structs this operation holds.
std::string get_name() const override
Get operation name for debugging/introspection.
Datum< OutputType > output_type
size_t record(std::span< const float > samples)
Run every chunk the samples complete without waiting for the result.
Supports< VadAnalyzerConfig > supports
VadAnalysis analyze_speech(const input_type &data)
Type-safe speech probability analysis.
VadAnalyzer(const Kakshya::TensorSet &weights, VadAnalyzerConfig config={})
Construct from the network weights.
SileroVadModel::ProbabilityBuffer probability_buffer()
Where the probabilities of the latest run are on the device, for a consumer on the same recording.
AnalysisType get_analysis_type() const override
Gets the analysis type category for this analyzer.
std::shared_ptr< const Kakshya::TensorSet > m_weights
SileroVadModel::ProbabilityBuffer hidden_buffer()
Where the network's recurrent output of the latest run is on the device, SileroVadModel::hidden_width...
static constexpr Target target
VadAnalysis analyze_speech(const InputType &data)
std::shared_ptr< GpuDispatchRecorder > m_recording
Analyzer< InputType, OutputType > base_type
void share_recording(std::shared_ptr< GpuDispatchRecorder > recording)
Append to a recording the caller shares with other work.
Datum< InputType > input_type
SileroVadModel & network() const
output_type analyze_implementation(const input_type &input) override
Pure virtual analysis implementation - derived classes implement this.
size_t resident_count() const noexcept
Probabilities the latest run left in probability_buffer.
std::unique_ptr< SileroVadModel > m_model
static std::string diagnose(const VadAnalyzerConfig &config)
Why a config cannot be analysed.
Whether each 32 ms chunk of a mono 16 kHz stream is voice activity, from a learned network.
@ ComputeMatrix
Compute operations (Yantra - algorithms, matrices, DSP).
@ Yantra
DSP algorithms, computational units, matrix operations, Grammar.
MAYAFLUX_API ShaderFoundry & get_shader_foundry()
Get the global shader compiler instance.
AnalysisType
Categories of analysis operations for discovery and organization.
@ CUSTOM
User-defined analysis types.
VadAnalyzer< std::vector< Kakshya::DataVariant >, Eigen::MatrixXd > StandardVadAnalyzer
Standard VAD analyzer: DataVariant -> MatrixXd.
VadAnalyzer< std::shared_ptr< Kakshya::SignalSourceContainer >, Eigen::MatrixXd > ContainerVadAnalyzer
Container VAD analyzer: SignalContainer -> MatrixXd.
std::vector< std::reference_wrapper< const OperationConfig > > ConfigRefs
Borrowed views of the configs an operation holds.
Named tensors that belong together, such as a model's weights or I/O.
uint32_t window_size
Analysis window length in samples.
uint32_t hop_size
Distance between successive windows in samples.
Settings every analyzer family accepts.
Facets facets
Typed results that travel with the data, read by type.
std::unordered_map< std::string, std::any > metadata
Associated metadata.
Input/Output container for computation pipeline data flow with structure preservation.
Where the probabilities of the latest run are on the device.
uint32_t sample_rate
Sample rate in Hz the network runs at.
The config structs an operation class accepts, declared as using supports.
A set of (device, runtime) pairs.
std::vector< float > embeddings
Recurrent output of the network for each chunk, SileroVadModel::hidden_width values each,...
std::vector< float > probabilities
Speech probability of each chunk completed by this call, 0 to 1.
VadAnalyzerConfig config
Settings the analysis was produced under.
std::vector< std::pair< size_t, size_t > > chunk_positions
First and one past the last sample of each chunk, counted from the start of the stream.
Analysis result of a VadAnalyzer.
bool flush_tail
Also run the partial chunk left at the end of each call, padded with zeros.
bool keep_embeddings
Also read back the network's recurrent output of every chunk, SileroVadModel::hidden_width values eac...
double sample_rate
Sample rate in Hz of the input.
Settings of a VadAnalyzer.