Call Center SDK  1.11.3
verify.h
1 /* Copyright 2021 ID R&D Inc. All Rights Reserved. */
2 
3 #pragma once
4 
5 #include <voicesdk/core/config.h>
6 #include <voicesdk/core/common/voice_template.h>
7 
8 #include <vector>
9 #include <memory>
10 #include <iostream>
11 #include <unordered_map>
12 
13 namespace voicesdk {
17  struct VerifyResult {
22  float score;
23 
28  float probability;
29 
31 
32  friend std::ostream& operator<<(std::ostream& os, const VerifyResult& obj) {
33  os << "VerifyResult["
34  << "score: " << obj.score << ", "
35  << "probability: " << obj.probability << "]";
36  return os;
37  }
38 
39  bool operator==(const VerifyResult& other) const {
40  return score == other.score && probability == other.probability;
41  }
42  };
43 
47  class VOICE_SDK_API VoiceTemplateMatcher
48  {
49  public:
50  using Ptr = std::shared_ptr<VoiceTemplateMatcher>;
51 
52  virtual ~VoiceTemplateMatcher() = default;
53 
61  static Ptr create(const std::string& initPath);
62 
72  virtual VerifyResult matchVoiceTemplates(const VoiceTemplate::Ptr& template1, const VoiceTemplate::Ptr& template2) const = 0;
73 
78  virtual const std::string& getInitDataId() const = 0;
79  };
80 
89  float minimumSnrDb = 0;
90 
95  };
96 
102 
108  std::string wav_file_path;
109 
113  ChannelType channel_type;
114  };
115 
120  template <class T>
122  VerifySamplesBatchElement(const T* data, size_t data_size, size_t sample_rate, ChannelType channel_type)
124 
128  const T* data;
129 
133  size_t data_size;
134 
140  size_t sample_rate;
141 
145  ChannelType channel_type;
146  };
147 
151  class VOICE_SDK_API VoiceTemplateFactory
152  {
153  public:
154 
155  using Ptr = std::shared_ptr<VoiceTemplateFactory>;
156 
164  static Ptr create(const std::string& initPath);
165 
176  virtual VoiceTemplate::Ptr createVoiceTemplate(
177  const std::string& audioPath,
178  const ChannelType& channelType = ChannelType::TEL) const = 0;
179 
192  virtual VoiceTemplate::Ptr createVoiceTemplate(
193  const float *floatSamples,
194  size_t numSamples,
195  size_t sampleRate,
196  const ChannelType& channelType = ChannelType::TEL) const = 0;
197 
210  virtual VoiceTemplate::Ptr createVoiceTemplate(
211  const int16_t *pcm16Samples,
212  size_t numSamples,
213  size_t sampleRate,
214  const ChannelType& channelType = ChannelType::TEL) const = 0;
215 
228  virtual VoiceTemplate::Ptr createVoiceTemplate(
229  const uint8_t *pcm16Bytes,
230  size_t numBytes,
231  size_t sampleRate,
232  const ChannelType& channelType = ChannelType::TEL) const = 0;
233 
241  virtual std::vector<VoiceTemplate::Ptr> createVoiceTemplateBatch(
242  const std::vector<VerifyFileBatchElement>& input_batch) const = 0;
243 
252  virtual std::vector<VoiceTemplate::Ptr> createVoiceTemplateBatch(
253  const std::vector<VerifySamplesBatchElement<float>>& input_batch) const = 0;
254 
262  virtual std::vector<VoiceTemplate::Ptr> createVoiceTemplateBatch(
263  const std::vector<VerifySamplesBatchElement<int16_t>>& input_batch) const = 0;
264 
272  virtual std::vector<VoiceTemplate::Ptr> createVoiceTemplateBatch(
273  const std::vector<VerifySamplesBatchElement<uint8_t>>& input_batch) const = 0;
274 
283  virtual VoiceTemplate::Ptr mergeVoiceTemplates(const std::vector<VoiceTemplate::Ptr>& voiceTemplates) const = 0;
284 
289  virtual const std::string& getInitDataId() const = 0;
290 
295  virtual const size_t& getMinimumAudioSampleRate() const = 0;
296 
297  virtual ~VoiceTemplateFactory() = default;
298  };
299 }
Class for creating and merging voice templates.
Definition: verify.h:152
virtual VoiceTemplate::Ptr createVoiceTemplate(const float *floatSamples, size_t numSamples, size_t sampleRate, const ChannelType &channelType=ChannelType::TEL) const =0
Creates a voice template from the given float audio samples.
virtual VoiceTemplate::Ptr createVoiceTemplate(const uint8_t *pcm16Bytes, size_t numBytes, size_t sampleRate, const ChannelType &channelType=ChannelType::TEL) const =0
Creates a voice template from the given byte representation of PCM16 audio samples.
static Ptr create(const std::string &initPath)
Factory method.
virtual const size_t & getMinimumAudioSampleRate() const =0
Returns minimum supported input audio sampling frequency in Hz.
virtual std::vector< VoiceTemplate::Ptr > createVoiceTemplateBatch(const std::vector< VerifySamplesBatchElement< float >> &input_batch) const =0
Creates a voice template from the given batch of float audio samples.
virtual std::vector< VoiceTemplate::Ptr > createVoiceTemplateBatch(const std::vector< VerifyFileBatchElement > &input_batch) const =0
Creates a voice template from the given batch of WAV files.
virtual std::vector< VoiceTemplate::Ptr > createVoiceTemplateBatch(const std::vector< VerifySamplesBatchElement< uint8_t >> &input_batch) const =0
Creates a voice template from the given batch of byte representation PCM16 audio samples.
virtual VoiceTemplate::Ptr mergeVoiceTemplates(const std::vector< VoiceTemplate::Ptr > &voiceTemplates) const =0
Merges multiple voice templates of a single speaker to a union voice template.
virtual VoiceTemplate::Ptr createVoiceTemplate(const int16_t *pcm16Samples, size_t numSamples, size_t sampleRate, const ChannelType &channelType=ChannelType::TEL) const =0
Creates a voice template from the given PCM16 audio samples.
virtual const std::string & getInitDataId() const =0
Returns ID of the init data, which was used to create the factory.
virtual VoiceTemplate::Ptr createVoiceTemplate(const std::string &audioPath, const ChannelType &channelType=ChannelType::TEL) const =0
Creates a voice template from the given audio file.
virtual std::vector< VoiceTemplate::Ptr > createVoiceTemplateBatch(const std::vector< VerifySamplesBatchElement< int16_t >> &input_batch) const =0
Creates a voice template from the given batch of PCM16 audio samples.
Class for matching voice templates one-to-one.
Definition: verify.h:48
virtual const std::string & getInitDataId() const =0
Returns ID of the init data, which was used to create the matcher.
static Ptr create(const std::string &initPath)
Factory method.
virtual VerifyResult matchVoiceTemplates(const VoiceTemplate::Ptr &template1, const VoiceTemplate::Ptr &template2) const =0
Matches two voice templates one-to-one.
Struct for custom quality checking thresholds VoiceTemplateFactory::checkQuality.
Definition: verify.h:85
float minimumSnrDb
Minimum signal-to-noise ratio required to pass quality check in dB.
Definition: verify.h:89
float minimumSpeechLengthMs
Minimum speech length required to pass quality check in milliseconds.
Definition: verify.h:94
Struct for verify factory batch processing VoiceTemplateFactory::createVoiceTemplateBatch.
Definition: verify.h:101
std::string wav_file_path
path to WAV file
Definition: verify.h:108
ChannelType channel_type
Audio record channel type.
Definition: verify.h:113
Structure representing voice verification result.
Definition: verify.h:17
float probability
Voice matching probability from 0 to 1, should be used for making a biometrics authentication decisio...
Definition: verify.h:28
float score
Raw verification score, intended to be used for evaluation and data-wise calibration.
Definition: verify.h:22
Struct for verify factory batch processing VoiceTemplateFactory::createVoiceTemplateBatch.
Definition: verify.h:121
size_t data_size
Number of audio samples.
Definition: verify.h:133
const T * data
A buffer containing audio samples.
Definition: verify.h:128
ChannelType channel_type
Audio record channel type.
Definition: verify.h:145
size_t sample_rate
Audio sampling rate in Hz.
Definition: verify.h:140