Authenticity Verification
This guide demonstrates how to perform Authenticity Verification with Phonexia Speech Platform 4.
For testing, we'll be using two audio files - one is real and the other is deepfake. These files are from ASVspoof 2021 challenge under the Open Data Commons Attribution Licence. You can download them together in the
audio_files.ziparchive.
At the end of this guide, you'll find the full Python code example that combines all the steps that will first be discussed separately. This guide should give you a comprehensive understanding on how to integrate Authenticity Verification in your own projects.
Prerequisites
In the guide, we assume that the Virtual Appliance is running on port 8000
of
http://localhost
. For more information on how to install and start the Virtual
Appliance, please refer to the
Virtual Appliance Installation guide. The
technology requires a proper model and license to process any files. For more
details on models and licenses see the
Licensing
section.
Environment Setup
We are using Python 3.9
and Python library requests 2.27
in this example.
You can install the requests
library with pip
as follows:
pip install requests~=2.27
Basic Authenticity Verification
To run Authenticity Verification for a single media file, you should start by
sending a POST
request to the
/api/technology/experimental/authenticity-verification
endpoint. In Python, you can do this as follows:
import requests
SPEECH_PLATFORM_SERVER = "http://localhost:8000" # Replace with your actual server URL
ENDPOINT_URL = f"{SPEECH_PLATFORM_SERVER}/api/technology/experimental/authenticity-verification"
audio_path = "DF_E_3651135_1.flac"
with open(audio_path, mode="rb") as file:
files = {"file": file}
response = requests.post(
url=ENDPOINT_URL,
files=files,
)
print(response.status_code) # Should print '202'
If the task has been successfully accepted, the 202
code will be returned
together with a unique task ID
in the response body. The task isn't processed
immediately, but only scheduled for processing. You can check the current task
status by polling for the result.
The URL for polling the result is returned in the X-Location
header.
Alternatively, you can assemble the polling URL on your own by appending a slash
(/
) and the task ID
to the endpoint URL.
import json
import requests
import time
# Use the `response` from the previous step
polling_url = response.headers["x-location"]
# Alternatively:
# polling_url = ENDPOINT_URL + "/" + response.json()["task"]["task_id"]
while True:
response = requests.get(polling_url)
data = response.json()
task_status = data["task"]["state"]
if task_status in {"done", "failed", "rejected"}:
break
time.sleep(5)
print(json.dumps(data, indent=2))
Once the polling finishes, data
will contain the latest response from the
server - either the result of Authenticity Verification, or an error message
with details, in case processing was not able to finish properly. Currently, the
only supported result is deepfake_detection
, but we plan to expand this
endpoint in the future to include more options to verify the authenticity. The
resulting score has a decision threshold of 0. Deepfake files should have a
score lower than 0, while genuine files should have a score higher than 0. The
technology result for deepfake_detection
can be accessed as
data["result"]["deepfake_detection"]
, and for our sample audio, data
should
look as follows:
{
"task": {
"task_id": "330f9d36-04e2-4b78-b4da-79bdd61aa7db",
"state": "done"
},
"result": {
"deepfake_detection": {
"channels": [
{
"channel_number": 0,
"score": 6.496947288513184
}
]
}
}
}
When processing multichannel media files, you will receive an independent
Authenticity Verification technology result for each channel and each supported
technology within the channels
list.
Full Python code
Here is the full example on how to run the Authenticity Verification technology. The code is slightly adjusted and wrapped into functions for better readability.
import json
import requests
import time
SPEECH_PLATFORM_SERVER = "http://localhost:8000" # Replace with your actual server URL
ENDPOINT_URL = f"{SPEECH_PLATFORM_SERVER}/api/technology/experimental/authenticity-verification"
def poll_result(polling_url: str, sleep: int = 5):
while True:
response = requests.get(polling_url)
response.raise_for_status()
data = response.json()
task_status = data["task"]["state"]
if task_status in {"done", "failed", "rejected"}:
break
time.sleep(sleep)
return response
def run_authenticity_verification(audio_path: str):
with open(audio_path, mode="rb") as file:
files = {"file": file}
response = requests.post(
url=ENDPOINT_URL,
files=files,
)
response.raise_for_status()
polling_url = response.headers["x-location"]
response_result = poll_result(polling_url)
return response_result.json()
filenames = ["DF_E_3651135_1.flac", "DF_E_3555565_1.flac"]
for filename in filenames:
print(f"Running Authenticity Verification for file {filename}.")
data = run_authenticity_verification(filename)
result = data["result"]
print(json.dumps(result, indent=2))