Call Center SDK  1.11.3
antispoof.h
1 /* Copyright 2023 ID R&D Inc. All Rights Reserved. */
2 
3 #pragma once
4 #include <string>
5 #include <iostream>
6 #include <utility>
7 #include <vector>
8 #include <memory>
9 #include <voicesdk/core/config.h>
10 
11 namespace voicesdk {
12 
16  struct AntispoofResult {
17 
18  float score = 0.0;
19  float score_Replay = 0.0;
20  float score_TTS = 0.0;
21  float score_VC = 0.0;
22  std::string unsuitableInputMessage;
24  friend std::ostream& operator<<(std::ostream& os, const AntispoofResult& obj) {
25  os << "AntispoofResult["
26  << "score: " << obj.score << ", "
27  << "score_Replay: " << obj.score_Replay << ", "
28  << "score_TTS: " << obj.score_TTS << ", "
29  << "score_VC: " << obj.score_VC;
30  if (!obj.unsuitableInputMessage.empty()) {
31  os << ", ";
32  os << "unsuitableInputMessage: " << obj.unsuitableInputMessage;
33  }
34  os << "]";
35  return os;
36  }
37 
39  float score,
40  float score_Replay,
41  float score_TTS,
42  float score_VC,
43  std::string unsuitableInputMessage = "")
44  :
45  score (score),
50  {}
51 
52  AntispoofResult() = default;
53  AntispoofResult(const AntispoofResult& other) = default;
54 
55  bool operator== (const AntispoofResult& other) const {
56  return score == other.score
57  && score_Replay == other.score_Replay
58  && score_TTS == other.score_TTS
59  && score_VC == other.score_VC
60  && unsuitableInputMessage == other.unsuitableInputMessage;
61  }
62 
63  bool isValid() {
64  auto isScoreValid = [](float score) -> bool {
65  return 0.0 <= score && score <= 1.0;
66  };
67  return isScoreValid(score)
68  && isScoreValid(score_Replay)
69  && isScoreValid(score_TTS)
70  && isScoreValid(score_VC);
71  }
72  };
73 
74 
80  class VOICE_SDK_API AntispoofEngine {
81  public:
85  using Ptr = std::shared_ptr<AntispoofEngine>;
86 
94  static AntispoofEngine::Ptr create(const std::string& initPath);
95 
105  const uint8_t* pcm16Bytes,
106  size_t bytesNum,
107  int sampleRate) const = 0;
108 
118  const int16_t* pcm16Samples,
119  size_t samplesNum,
120  int sampleRate) const = 0;
121 
131  const float* floatSamples,
132  size_t samplesNum,
133  int sampleRate) const = 0;
134 
141  virtual AntispoofResult isSpoof(const std::string& audioFile) const = 0;
142 
143  virtual ~AntispoofEngine() = default;
144  };
145 }
Class for detecting spoofing attacks in audio with human speech. This is an entry point for voice ant...
Definition: antispoof.h:80
virtual AntispoofResult isSpoof(const uint8_t *pcm16Bytes, size_t bytesNum, int sampleRate) const =0
virtual AntispoofResult isSpoof(const std::string &audioFile) const =0
Tests whether given audio file contains spoofed speech.
std::shared_ptr< AntispoofEngine > Ptr
Smart pointer to AntispoofEngine instance.
Definition: antispoof.h:85
virtual AntispoofResult isSpoof(const int16_t *pcm16Samples, size_t samplesNum, int sampleRate) const =0
virtual AntispoofResult isSpoof(const float *floatSamples, size_t samplesNum, int sampleRate) const =0
static AntispoofEngine::Ptr create(const std::string &initPath)
Creates AntispoofEngine instance.
Result structure returned from AntispoofEngine::isSpoof functions.
Definition: antispoof.h:16
std::string unsuitableInputMessage
Definition: antispoof.h:22
float score_TTS
Definition: antispoof.h:20
float score_VC
Definition: antispoof.h:21
float score_Replay
Definition: antispoof.h:19
float score
Definition: antispoof.h:18