VoiceSDK  5.3.1
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 
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>
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 
157  const std::string& audioPath,
158  const ChannelType& channelType = ChannelType::MIC) const = 0;
159 
173  const float *floatSamples,
174  size_t numSamples,
175  size_t sampleRate,
176  const ChannelType& channelType = ChannelType::MIC) const = 0;
177 
191  const int16_t *pcm16Samples,
192  size_t numSamples,
193  size_t sampleRate,
194  const ChannelType& channelType = ChannelType::MIC) const = 0;
195 
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 }
Class for creating and merging voice templates.
Definition: verify.h:132
std::shared_ptr< VoiceTemplateFactory > Ptr
Definition: verify.h:135
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 VoiceTemplate::Ptr createVoiceTemplate(const int16_t *pcm16Samples, size_t numSamples, size_t sampleRate, const ChannelType &channelType=ChannelType::MIC) const =0
Creates a voice template from the given PCM16 audio samples.
virtual VoiceTemplate::Ptr createVoiceTemplate(const float *floatSamples, size_t numSamples, size_t sampleRate, const ChannelType &channelType=ChannelType::MIC) const =0
Creates a voice template from the given 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 ~VoiceTemplateFactory()=default
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 std::string &audioPath, const ChannelType &channelType=ChannelType::MIC) const =0
Creates a voice template from the given audio file.
virtual const std::string & getInitDataId() const =0
Returns ID of the init data, which was used to create the factory.
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.
virtual VoiceTemplate::Ptr createVoiceTemplate(const uint8_t *pcm16Bytes, size_t numBytes, size_t sampleRate, const ChannelType &channelType=ChannelType::MIC) const =0
Creates a voice template from the given byte representation of PCM16 audio samples.
Class for matching voice templates one-to-one.
Definition: verify.h:48
virtual const std::string & getInitDataId() const =0
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.
virtual ~VoiceTemplateMatcher()=default
std::shared_ptr< VoiceTemplateMatcher > Ptr
Definition: verify.h:50
std::shared_ptr< VoiceTemplate > Ptr
Definition: voice_template.h:27
#define VOICE_SDK_API
Definition: config.h:21
Definition: intervals.h:8
ChannelType
An enumeration for audio source labeling during voice template creation.
Definition: voice_template.h:15
Struct for verify factory batch processing VoiceTemplateFactory::createVoiceTemplateBatch.
Definition: verify.h:81
std::string wav_file_path
path to WAV file
Definition: verify.h:88
ChannelType channel_type
Audio record channel type.
Definition: verify.h:93
Structure representing voice verification result.
Definition: verify.h:17
VerifyResult(float score, float probability)
Definition: verify.h:30
friend std::ostream & operator<<(std::ostream &os, const VerifyResult &obj)
Definition: verify.h:32
float probability
Voice matching probability from 0 to 1, should be used for making a biometrics authentication decisio...
Definition: verify.h:28
bool operator==(const VerifyResult &other) const
Definition: verify.h:39
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:101
size_t data_size
Number of audio samples.
Definition: verify.h:113
const T * data
A buffer containing audio samples.
Definition: verify.h:108
ChannelType channel_type
Audio record channel type.
Definition: verify.h:125
size_t sample_rate
Audio sampling rate in Hz.
Definition: verify.h:120
VerifySamplesBatchElement(const T *data, size_t data_size, size_t sample_rate, ChannelType channel_type)
Definition: verify.h:102