VoiceSDK  5.0.2
verify.h
Go to the documentation of this file.
1 /* Copyright 2017 ID R&D Inc. All Rights Reserved. */
2 
3 #pragma once
4 
5 #include <voicesdk/core/config.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 
30  VerifyResult(float score, float probability) : score(score), probability(probability) {}
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 
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 
74  virtual const std::string& getInitDataId() const = 0;
75  };
76 
82 
88  std::string wav_file_path;
89 
94  };
95 
100  template <class T>
102  VerifySamplesBatchElement(const T* data, size_t data_size, size_t sample_rate, ChannelType channel_type)
103  : data(data), data_size(data_size), sample_rate(sample_rate), channel_type(channel_type) {}
104 
108  const T* data;
109 
113  size_t data_size;
114 
120  size_t sample_rate;
121 
126  };
127 
132  {
133  public:
134 
135  using Ptr = std::shared_ptr<VoiceTemplateFactory>;
136 
144  static Ptr create(const std::string& initPath);
145 
156  virtual VoiceTemplate::Ptr createVoiceTemplate(
157  const std::string& audioPath,
158  const ChannelType& channelType = ChannelType::MIC) const = 0;
159 
172  virtual VoiceTemplate::Ptr createVoiceTemplate(
173  const float *floatSamples,
174  size_t numSamples,
175  size_t sampleRate,
176  const ChannelType& channelType = ChannelType::MIC) const = 0;
177 
190  virtual VoiceTemplate::Ptr createVoiceTemplate(
191  const int16_t *pcm16Samples,
192  size_t numSamples,
193  size_t sampleRate,
194  const ChannelType& channelType = ChannelType::MIC) const = 0;
195 
208  virtual VoiceTemplate::Ptr createVoiceTemplate(
209  const uint8_t *pcm16Bytes,
210  size_t numBytes,
211  size_t sampleRate,
212  const ChannelType& channelType = ChannelType::MIC) const = 0;
213 
221  virtual std::vector<VoiceTemplate::Ptr> createVoiceTemplateBatch(
222  const std::vector<VerifyFileBatchElement>& input_batch) const = 0;
223 
232  virtual std::vector<VoiceTemplate::Ptr> createVoiceTemplateBatch(
233  const std::vector<VerifySamplesBatchElement<float>>& input_batch) const = 0;
234 
242  virtual std::vector<VoiceTemplate::Ptr> createVoiceTemplateBatch(
243  const std::vector<VerifySamplesBatchElement<int16_t>>& input_batch) const = 0;
244 
252  virtual std::vector<VoiceTemplate::Ptr> createVoiceTemplateBatch(
253  const std::vector<VerifySamplesBatchElement<uint8_t>>& input_batch) const = 0;
254 
263  virtual VoiceTemplate::Ptr mergeVoiceTemplates(const std::vector<VoiceTemplate::Ptr>& voiceTemplates) const = 0;
264 
269  virtual const std::string& getInitDataId() const = 0;
270 
275  virtual const size_t& getMinimumAudioSampleRate() const = 0;
276 
277  virtual ~VoiceTemplateFactory() = default;
278  };
279 }
Struct for verify factory batch processing VoiceTemplateFactory::createVoiceTemplateBatch.
Definition: verify.h:101
Class for creating and merging voice templates.
Definition: verify.h:131
size_t sample_rate
Audio sampling rate in Hz.
Definition: verify.h:120
VerifyResult(float score, float probability)
Definition: verify.h:30
ChannelType channel_type
Audio record channel type.
Definition: verify.h:93
std::shared_ptr< VoiceTemplateFactory > Ptr
Definition: verify.h:135
ChannelType channel_type
Audio record channel type.
Definition: verify.h:125
Class for matching voice templates one-to-one.
Definition: verify.h:47
VerifySamplesBatchElement(const T *data, size_t data_size, size_t sample_rate, ChannelType channel_type)
Definition: verify.h:102
Struct for verify factory batch processing VoiceTemplateFactory::createVoiceTemplateBatch.
Definition: verify.h:81
bool operator==(const VerifyResult &other) const
Definition: verify.h:39
Definition: intervals.h:8
std::string wav_file_path
path to WAV file
Definition: verify.h:88
size_t data_size
Number of audio samples.
Definition: verify.h:113
float probability
Voice matching probability from 0 to 1, should be used for making a biometrics authentication decisio...
Definition: verify.h:28
friend std::ostream & operator<<(std::ostream &os, const VerifyResult &obj)
Definition: verify.h:32
std::shared_ptr< VoiceTemplateMatcher > Ptr
Definition: verify.h:50
#define VOICE_SDK_API
Definition: config.h:21
float score
Raw verification score, intended to be used for evaluation and data-wise calibration.
Definition: verify.h:22
const T * data
A buffer containing audio samples.
Definition: verify.h:108
ChannelType
An enumeration for audio source labeling during voice template creation.
Definition: voice_template.h:15
Structure representing voice verification result.
Definition: verify.h:17
std::shared_ptr< VoiceTemplate > Ptr
Definition: voice_template.h:27