Call Center SDK  1.11.3
identification.h
1 /* Copyright 2021 ID R&D Inc. All Rights Reserved. */
2 
3 #pragma once
4 
5 #include <string>
6 #include <vector>
7 #include <memory>
8 
9 #include <voicesdk/verify/verify.h>
10 
11 namespace voicesdk {
12 namespace ident {
13 
24  std::vector<size_t> GetIndexesOfMatchedTemplates() const {
25  std::vector<size_t> indexes;
26 
27  for (size_t i = 0; i < scores.size(); ++i) {
28  if (scores[i] >= threshold) {
29  indexes.push_back(i);
30  }
31  }
32 
33  return indexes;
34  }
35 
40  bool IsMatched() const {
41  for (const auto& score : scores) {
42  if (score >= threshold) {
43  return true;
44  }
45  }
46  return false;
47  }
48 
49  VOICE_SDK_API
50  friend std::ostream& operator<<(std::ostream& os, const IdentificationResult& obj) {
51  os << "IdentificationList["
52  << "scores: { ";
53 
54  for (const auto& s : obj.scores) {
55  os << s << ", ";
56  }
57 
58  os << "}, ";
59  os << "threshold: " << obj.threshold << "]";
60 
61  return os;
62  }
63 
68  std::vector<float> scores;
69 
76  float threshold;
77 };
78 
82 struct VOICE_SDK_API IdentificationList {
83  using Ptr = std::shared_ptr<IdentificationList>;
84 
89  virtual void Serialize(std::ostream& stream) const = 0;
90 
96  static IdentificationList::Ptr Deserialize(std::istream& stream);
97 
98  virtual ~IdentificationList() = default;
99 };
100 
104 class VOICE_SDK_API IdentificationEngine {
105 public:
106  using Ptr = std::shared_ptr<IdentificationEngine>;
107 
113  static Ptr Create(const std::string& initDataPath);
114 
121  virtual IdentificationList::Ptr CreateIdentificationList(
122  const std::vector<voicesdk::VoiceTemplate::Ptr>& voice_templates) = 0;
123 
134  virtual IdentificationResult Identify(const voicesdk::VoiceTemplate::Ptr& voice_template,
135  const IdentificationList::Ptr& identification_list,
136  const float acceptance_level = -2.0f) = 0;
137 
144  virtual void EnrichIdentificationList(const IdentificationList::Ptr& identification_list,
145  const std::vector<voicesdk::VoiceTemplate::Ptr>& voice_templates) = 0;
146 
147  virtual ~IdentificationEngine() = default;
148 };
149 
150 } // namespace ident
151 } // namespace voicesdk
Identification engine class used for creating identification list and for identification itself.
Definition: identification.h:104
virtual IdentificationResult Identify(const voicesdk::VoiceTemplate::Ptr &voice_template, const IdentificationList::Ptr &identification_list, const float acceptance_level=-2.0f)=0
Performs an identification of given voice template using given identification list.
virtual void EnrichIdentificationList(const IdentificationList::Ptr &identification_list, const std::vector< voicesdk::VoiceTemplate::Ptr > &voice_templates)=0
Enrich identification list with new templates.
virtual IdentificationList::Ptr CreateIdentificationList(const std::vector< voicesdk::VoiceTemplate::Ptr > &voice_templates)=0
Creates a list for identification from given voice templates.
static Ptr Create(const std::string &initDataPath)
Factory method used for creating an instance of identification engine.
Structure containing list for identification.
Definition: identification.h:82
virtual void Serialize(std::ostream &stream) const =0
Serializes identification list to an output stream.
static IdentificationList::Ptr Deserialize(std::istream &stream)
Deserializes identification list from an input stream.
Structure containing identification result.
Definition: identification.h:17
float threshold
Similarity score threshold, supposed to be used to make a decision about if corresponding voice templ...
Definition: identification.h:76
std::vector< size_t > GetIndexesOfMatchedTemplates() const
Returns indexes of templates stored (i.e. used for creation) identification list which are considered...
Definition: identification.h:24
std::vector< float > scores
Contains similarity score for each template sorted in according to templates identification list was ...
Definition: identification.h:68
bool IsMatched() const
Check whether voice template was matched or not.
Definition: identification.h:40