VoiceSDK  5.0.2
quality_check.h
Go to the documentation of this file.
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 {
107  return quality_check_short_description == other.quality_check_short_description && snr_db == other.snr_db &&
108  speech_length_ms == other.speech_length_ms && speech_relative_length == other.speech_relative_length &&
109  multiple_speakers_detector_score == other.multiple_speakers_detector_score;
110  }
111 };
112 
121  float minimum_snr_db = 0;
122 
126  float minimum_speech_length_ms = 0;
127 
131  float minimum_speech_relative_length = 0;
132 
136  float maximum_multiple_speakers_detector_score = 0;
137 };
138 
142 enum class QualityCheckScenario: uint8_t {
147 
152 
157 
162 
166  kLiveness = 4
167 };
168 
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
Verification, TD enrollment step.
float speech_length_ms
Speech length metric value obtained on quality check in milliseconds.
Definition: quality_check.h:58
Verification, TD verification step.
Quality check engine class.
Definition: quality_check.h:172
Too small speech relative length (speech length relative to the total audio length).
QualityCheckScenario
Enumeration representing scenarios used to get recommended quality check thresholds.
Definition: quality_check.h:142
Structure representing audio quality check result.
Definition: quality_check.h:18
Definition: intervals.h:8
std::shared_ptr< QualityCheckEngine > Ptr
Definition: quality_check.h:174
Verification, TI verification step.
float multiple_speakers_detector_score
Multiple speakers detector score value obtained on quality check.
Definition: quality_check.h:68
friend std::ostream & operator<<(std::ostream &os, const QualityCheckEngineResult &obj)
Definition: quality_check.h:75
#define VOICE_SDK_API
Definition: config.h:21
bool operator==(const QualityCheckEngineResult &other) const
Definition: quality_check.h:106
Struct for quality checking metrics thresholds QualityCheckEngine::CheckQuality.
Definition: quality_check.h:117
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
QualityCheckShortDescription
Enumeration representing short quality check description.
Definition: quality_check.h:23
QualityCheckShortDescription quality_check_short_description
Short description of the quality check results.
Definition: quality_check.h:73
Verification, TI enrollment step.
float snr_db
SNR metric value obtained on quality check in Db.
Definition: quality_check.h:53