MayaFlux 1.0.0
Digital-First Multimedia Processing Framework
Loading...
Searching...
No Matches

◆ measure_voicing()

SpeechVoicing MayaFlux::Yantra::measure_voicing ( StandardWaveformAnalyzer & analyzer,
std::span< const double > samples,
const std::vector< std::pair< size_t, size_t > > & speech,
double voicing_threshold )
inlinenodiscard

Voiced share and median frequency of the waveform windows that start in each interval.

Parameters
analyzerAnalyzer built from voicing_analyzer_config.
samplesOne channel of samples.
speechHalf open sample intervals.
voicing_thresholdPeriodicity at or above which a window is voiced.
Returns
One entry per interval; 0 for an interval holding no windows or no voiced window.

Definition at line 176 of file SpeechSegmenter.hpp.

178{
179 SpeechVoicing voicing;
180 voicing.voiced_fraction.assign(speech.size(), 0.0);
181 voicing.f0.assign(speech.size(), 0.0);
182 if (speech.empty() || samples.size() < WaveformAnalyzerConfig {}.window_size) {
183 return voicing;
184 }
185
186 const auto analysis = analyzer.analyze_waveform(
187 std::vector<Kakshya::DataVariant> { std::vector<double>(samples.begin(), samples.end()) });
188 if (analysis.channels.empty()) {
189 return voicing;
190 }
191 const auto& waveform = analysis.channels[0];
192
193 std::vector<size_t> starts;
194 starts.reserve(waveform.window_positions.size());
195 for (const auto& position : waveform.window_positions) {
196 starts.push_back(position.first);
197 }
199 waveform.periodicity, starts, speech, voicing_threshold);
200
201 std::vector<double> voiced_frequency;
202 std::vector<size_t> voiced_starts;
203 for (size_t window = 0; window < starts.size() && window < waveform.periodicity.size(); ++window) {
204 if (waveform.periodicity[window] >= voicing_threshold) {
205 voiced_frequency.push_back(waveform.frequency[window]);
206 voiced_starts.push_back(starts[window]);
207 }
208 }
209 voicing.f0 = Kinesis::Discrete::interval_median(voiced_frequency, voiced_starts, speech);
210 return voicing;
211}
WaveformAnalysis analyze_waveform(const input_type &data)
Type-safe waveform analysis.
std::vector< double > interval_share_above(std::span< const double > values, std::span< const size_t > positions, const std::vector< std::pair< size_t, size_t > > &intervals, double threshold)
Share of the values inside each interval that are at or above a threshold.
Definition Extract.cpp:94
std::vector< double > interval_median(std::span< const double > values, std::span< const size_t > positions, const std::vector< std::pair< size_t, size_t > > &intervals)
Median of the values inside each interval.
Definition Extract.cpp:110
uint32_t window_size
Analysis window length in samples.
Definition Analyzer.hpp:64
std::vector< double > voiced_fraction
Voiced share of each interval's windows.
std::vector< double > f0
Median frequency of each interval's voiced windows.
Voicing of each interval, as SpeechSegmentation holds it.
std::vector< ChannelWaveform > channels
Settings of a WaveformAnalyzer.

References MayaFlux::Yantra::WaveformAnalyzer< InputType, OutputType >::analyze_waveform(), MayaFlux::Yantra::WaveformAnalysis::channels, MayaFlux::Yantra::SpeechVoicing::f0, MayaFlux::Kinesis::Discrete::interval_median(), MayaFlux::Kinesis::Discrete::interval_share_above(), MayaFlux::Yantra::SpeechVoicing::voiced_fraction, and MayaFlux::Yantra::AnalyzerConfig::window_size.

Referenced by MayaFlux::Yantra::SpeechSegmenter< std::vector< Kakshya::DataVariant >, Kakshya::RegionGroup >::measure_speech().

Here is the call graph for this function:
Here is the caller graph for this function: