Call Center SDK  1.11.3
attributes.h
1 /* Copyright 2021 ID R&D Inc. All Rights Reserved. */
2 
3 #pragma once
4 
5 #include <voicesdk/core/config.h>
6 
7 #include <memory>
8 #include <string>
9 #include <iostream>
10 
11 namespace voicesdk {
12 namespace attr {
13 
17 struct Attributes {
18 
22  enum class Gender : uint8_t { MALE = 0, FEMALE = 1 };
23 
28  enum class PhoneCallParticipant : uint8_t {
29  OPERATOR = 0,
30  CUSTOMER = 1,
31  OTHER = 2,
32  UNDEFINED = 3
33  };
34 
35  Attributes(const Attributes& other) = default;
36 
37  Attributes(const float& gender_score_, const Gender& gender_, const size_t& age_,
38  const PhoneCallParticipant& phone_call_participant_ = PhoneCallParticipant::UNDEFINED)
39  : gender_score(gender_score_),
40  gender(gender_),
41  age(age_),
42  phone_call_participant(phone_call_participant_) {}
43 
44  bool operator==(const Attributes& other) const {
45  return gender_score == other.gender_score && gender == other.gender && age == other.age;
46  }
47 
48  friend std::ostream& operator<<(std::ostream& os, const Attributes& obj) {
49  os << "Attributes["
50  << "genderScore: " << obj.gender_score << ", "
51  << "gender: " << (obj.gender == Gender::MALE ? "MALE" : "FEMALE") << ", "
52  << "age: " << obj.age << ", "
53  << "phoneCallParticipant: "
54  << (obj.phone_call_participant == PhoneCallParticipant::OPERATOR
55  ? "OPERATOR"
56  : (obj.phone_call_participant == PhoneCallParticipant::CUSTOMER
57  ? "CUSTOMER"
58  : (obj.phone_call_participant == PhoneCallParticipant::OTHER ? "OTHER"
59  : "UNDEFINED")))
60  << "]";
61  return os;
62  }
63 
68  const float gender_score;
69 
73  const Gender gender;
74 
78  const size_t age;
79 
85 };
86 
90 class VOICE_SDK_API AttributesEstimator {
91 public:
92  using Ptr = std::shared_ptr<AttributesEstimator>;
93 
101  static AttributesEstimator::Ptr Create(const std::string& init_path);
102 
112  virtual Attributes Estimate(const uint8_t* bytes, size_t bytes_num, size_t sample_rate) = 0;
113 
123  virtual Attributes Estimate(const int16_t* pcm16_samples, size_t samples_num, size_t sample_rate) = 0;
124 
134  virtual Attributes Estimate(const float* float_samples, size_t samples_num, size_t sample_rate) = 0;
135 
143  virtual Attributes Estimate(const std::string& audio_file) = 0;
144 
145  virtual ~AttributesEstimator() = default;
146 };
147 
148 } // namespace attr
149 } // namespace voicesdk
Class for estimating person attributes by their voice (age and gender)
Definition: attributes.h:90
static AttributesEstimator::Ptr Create(const std::string &init_path)
Creates AttributesEstimator instance.
virtual Attributes Estimate(const int16_t *pcm16_samples, size_t samples_num, size_t sample_rate)=0
virtual Attributes Estimate(const std::string &audio_file)=0
virtual Attributes Estimate(const float *float_samples, size_t samples_num, size_t sample_rate)=0
virtual Attributes Estimate(const uint8_t *bytes, size_t bytes_num, size_t sample_rate)=0
Structure representing estimated person attributes.
Definition: attributes.h:17
const size_t age
Estimated age in years.
Definition: attributes.h:78
const Gender gender
Estimated gender.
Definition: attributes.h:73
const PhoneCallParticipant phone_call_participant
Estimated phone call participant class. Makes sense only for single speaker phone call recordings.
Definition: attributes.h:84
PhoneCallParticipant
Enumeration representing phone call participant class.
Definition: attributes.h:28
Gender
Enumeration representing human gender.
Definition: attributes.h:22
const float gender_score
Raw gender score (the bigger score corresponding to male and the smaller score corresponding to femal...
Definition: attributes.h:68