Call Center SDK  1.11.3
quality_check.h
1 /* Copyright 2023 ID R&D Inc. All Rights Reserved. */
2 
3 #pragma once
4 
5 #include <voicesdk/core/config.h>
6 
7 #include <iostream>
8 #include <vector>
9 #include <memory>
10 #include <unordered_map>
11 #include <string>
12 
13 namespace voicesdk {
14 
19 
23  enum class QualityCheckShortDescription : uint8_t {
27  kTooNoisy = 0,
28 
33 
37  kOk = 2,
38 
43 
48  };
49 
53  float snr_db;
54 
59 
64 
69 
74 
75  friend std::ostream& operator<<(std::ostream& os, const QualityCheckEngineResult& obj) {
76  std::string short_description_str;
77 
78  switch (obj.quality_check_short_description) {
80  short_description_str = "kTooNoisy";
81  break;
83  short_description_str = "kTooSmallSpeechLength";
84  break;
86  short_description_str = "kOk";
87  break;
89  short_description_str = "kTooSmallSpeechRelativeLength";
90  break;
92  short_description_str = "kMultipleSpeakersDetected";
93  break;
94  }
95 
96  os << "QualityCheckEngineResult["
97  << "snr_db: " << obj.snr_db << ", "
98  << "speech_length_ms: " << obj.speech_length_ms << ", "
99  << "speech_relative_length: " << obj.speech_relative_length << ", "
100  << "multiple_speakers_detector_score: " << obj.multiple_speakers_detector_score << ", "
101  << "quality_check_short_description: " << short_description_str
102  << "]";
103  return os;
104  }
105 
106  bool operator==(const QualityCheckEngineResult& other) const {
110  }
111 };
112 
121  float minimum_snr_db = 0;
122 
127 
132 
137 };
138 
142 enum class QualityCheckScenario: uint8_t {
146  kVerifyTiEnrollment = 0,
147 
151  kVerifyTiVerification = 1,
152 
156  kVerifyTdEnrollment = 2,
157 
161  kVerifyTdVerification = 3,
162 
166  kLiveness = 4
167 };
168 
172 class VOICE_SDK_API QualityCheckEngine {
173 public:
174  using Ptr = std::shared_ptr<QualityCheckEngine>;
175 
184  static QualityCheckEngine::Ptr Create(const std::string& init_path);
185 
186  virtual ~QualityCheckEngine() = default;
187 
195  virtual QualityCheckMetricsThresholds GetRecommendedThresholds(QualityCheckScenario scenario) const = 0;
196 
205  virtual QualityCheckEngineResult CheckQuality(const std::string& audio_path,
206  const QualityCheckMetricsThresholds& thresholds) const = 0;
207 
218  virtual QualityCheckEngineResult CheckQuality(const float* float_samples, size_t num_samples, size_t sample_rate,
219  const QualityCheckMetricsThresholds& thresholds) const = 0;
220 
230  virtual QualityCheckEngineResult CheckQuality(const int16_t* pcm16_samples, size_t num_samples, size_t sample_rate,
231  const QualityCheckMetricsThresholds& threshold) const = 0;
232 
243  virtual QualityCheckEngineResult CheckQuality(const uint8_t* pcm16_bytes, size_t num_bytes, size_t sample_rate,
244  const QualityCheckMetricsThresholds& thresholds) const = 0;
245 };
246 
247 } // namespace voicesdk
Quality check engine class.
Definition: quality_check.h:172
static QualityCheckEngine::Ptr Create(const std::string &init_path)
Creates QualityCheckEngine instance.
virtual QualityCheckMetricsThresholds GetRecommendedThresholds(QualityCheckScenario scenario) const =0
Gets recommended quality checking thresholds for the specified scenario.
virtual QualityCheckEngineResult CheckQuality(const float *float_samples, size_t num_samples, size_t sample_rate, const QualityCheckMetricsThresholds &thresholds) const =0
Checks whether audio buffer is suitable from the quality perspective, from the given float audio samp...
virtual QualityCheckEngineResult CheckQuality(const std::string &audio_path, const QualityCheckMetricsThresholds &thresholds) const =0
Checks whether audio file is suitable from the quality perspective, from the given audio file.
virtual QualityCheckEngineResult CheckQuality(const uint8_t *pcm16_bytes, size_t num_bytes, size_t sample_rate, const QualityCheckMetricsThresholds &thresholds) const =0
Checks whether audio buffer is suitable from the quality perspective, from the given PCM16 audio samp...
virtual QualityCheckEngineResult CheckQuality(const int16_t *pcm16_samples, size_t num_samples, size_t sample_rate, const QualityCheckMetricsThresholds &threshold) const =0
Checks whether audio buffer is suitable from the quality perspective, from the given PCM16 audio samp...
Structure representing audio quality check result.
Definition: quality_check.h:18
QualityCheckShortDescription
Enumeration representing short quality check description.
Definition: quality_check.h:23
@ kTooSmallSpeechRelativeLength
Too small speech relative length (speech length relative to the total audio length).
@ kTooSmallSpeechLength
Too small speech length in the audio.
float speech_relative_length
Speech relative length (speech length relative to the total audio length) metric value obtained on qu...
Definition: quality_check.h:63
float multiple_speakers_detector_score
Multiple speakers detector score value obtained on quality check.
Definition: quality_check.h:68
float snr_db
SNR metric value obtained on quality check in Db.
Definition: quality_check.h:53
QualityCheckShortDescription quality_check_short_description
Short description of the quality check results.
Definition: quality_check.h:73
float speech_length_ms
Speech length metric value obtained on quality check in milliseconds.
Definition: quality_check.h:58
Struct for quality checking metrics thresholds QualityCheckEngine::CheckQuality.
Definition: quality_check.h:117
float minimum_snr_db
Minimum signal-to-noise ratio required to pass quality check in dB.
Definition: quality_check.h:121
float minimum_speech_length_ms
Minimum speech length required to pass quality check in milliseconds.
Definition: quality_check.h:126
float maximum_multiple_speakers_detector_score
Maximum multiple speakers detector score allowed to pass quality check.
Definition: quality_check.h:136
float minimum_speech_relative_length
Minimum speech relative length (speech length relative to the total audio length) required to pass qu...
Definition: quality_check.h:131