aristech-ai-check 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- aristech_ai_check-1.0.0/LICENSE +21 -0
- aristech_ai_check-1.0.0/PKG-INFO +99 -0
- aristech_ai_check-1.0.0/README.md +66 -0
- aristech_ai_check-1.0.0/THIRD_PARTY_NOTICES +23 -0
- aristech_ai_check-1.0.0/pyproject.toml +62 -0
- aristech_ai_check-1.0.0/pyproject.toml.orig +48 -0
- aristech_ai_check-1.0.0/src/aristech_ai_check/__init__.py +5 -0
- aristech_ai_check-1.0.0/src/aristech_ai_check/__main__.py +5 -0
- aristech_ai_check-1.0.0/src/aristech_ai_check/aristech_ca.pem +12 -0
- aristech_ai_check-1.0.0/src/aristech_ai_check/check.py +91 -0
- aristech_ai_check-1.0.0/src/aristech_ai_check/cli.py +153 -0
- aristech_ai_check-1.0.0/src/aristech_ai_check/model/detector.onnx +0 -0
- aristech_ai_check-1.0.0/src/aristech_ai_check/provenance.py +71 -0
- aristech_ai_check-1.0.0/src/aristech_ai_check/py.typed +0 -0
- aristech_ai_check-1.0.0/src/aristech_ai_check/watermark.py +95 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Aristech GmbH
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: aristech-ai-check
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Checks audio files for the AI marking of Aristech TTS (EU AI Act Art. 50)
|
|
5
|
+
Keywords: ai-act,ai-generated,audio,c2pa,content-credentials,detection,speech,tts,watermark
|
|
6
|
+
Author: Aristech GmbH
|
|
7
|
+
License-Expression: MIT
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
License-File: THIRD_PARTY_NOTICES
|
|
10
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
11
|
+
Classifier: Environment :: Console
|
|
12
|
+
Classifier: Intended Audience :: End Users/Desktop
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: Natural Language :: English
|
|
15
|
+
Classifier: Natural Language :: German
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Classifier: Programming Language :: Python :: 3
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Multimedia :: Sound/Audio :: Analysis
|
|
23
|
+
Classifier: Typing :: Typed
|
|
24
|
+
Requires-Dist: numpy>=1.26
|
|
25
|
+
Requires-Dist: scipy>=1.11
|
|
26
|
+
Requires-Dist: soundfile>=0.12
|
|
27
|
+
Requires-Dist: onnxruntime>=1.19
|
|
28
|
+
Requires-Dist: c2pa-python>=0.39,<0.40
|
|
29
|
+
Requires-Dist: tinytag>=2.0
|
|
30
|
+
Requires-Python: >=3.10
|
|
31
|
+
Project-URL: Homepage, https://aristech.ai
|
|
32
|
+
Description-Content-Type: text/markdown
|
|
33
|
+
|
|
34
|
+
# aristech-ai-check
|
|
35
|
+
|
|
36
|
+
Checks audio files for the AI marking of Aristech TTS. Speech from Aristech TTS is
|
|
37
|
+
marked as AI-generated in line with Art. 50(2) of the EU AI Act:
|
|
38
|
+
|
|
39
|
+
- an inaudible watermark in the audio itself, in every output format
|
|
40
|
+
- a signed C2PA manifest (Content Credentials) in WAV files
|
|
41
|
+
- an unsigned note in the file's metadata (MP3, OGG, FLAC, WAV)
|
|
42
|
+
|
|
43
|
+
## Installation
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
pip install aristech-ai-check
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
Runs locally and offline on Linux, macOS and Windows. No audio is sent anywhere.
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
aristech-ai-check speech.wav recording.mp3
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
```
|
|
58
|
+
speech.wav
|
|
59
|
+
Watermark: present
|
|
60
|
+
Signature: valid, signed by Aristech GmbH (Aristech TTS Signer), created 2026-11-26T11:52:22.473Z
|
|
61
|
+
Metadata note: present ("Synthetic speech generated by aristech-tts-20cd4e418375")
|
|
62
|
+
Result: AI-generated
|
|
63
|
+
recording.mp3
|
|
64
|
+
Watermark: not found
|
|
65
|
+
Signature: none
|
|
66
|
+
Metadata note: none
|
|
67
|
+
Result: no AI marking found
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
`--lang de` prints German, `--json` one JSON object per file. Supported formats: WAV
|
|
71
|
+
(including A-law and µ-law), FLAC, OGG and MP3. Stereo files are checked channel by
|
|
72
|
+
channel.
|
|
73
|
+
|
|
74
|
+
Exit code 0 means every file was checked, whatever the result. Exit code 1 means at
|
|
75
|
+
least one file could not be checked (for example because it is missing or not an
|
|
76
|
+
audio file).
|
|
77
|
+
|
|
78
|
+
## Reading the result
|
|
79
|
+
|
|
80
|
+
The result is "AI-generated", "inconclusive" or "no AI marking found".
|
|
81
|
+
|
|
82
|
+
- The watermark shows that the audio was generated by AI. Other providers use the
|
|
83
|
+
same kind of watermark, so on its own it does not show that the audio comes from
|
|
84
|
+
Aristech.
|
|
85
|
+
- A valid signature from Aristech GmbH proves that the file was generated by Aristech
|
|
86
|
+
TTS and has not been changed since. It makes the result "AI-generated" in any case.
|
|
87
|
+
- The metadata note is shown for information only. It is unsigned and does not change
|
|
88
|
+
the result.
|
|
89
|
+
|
|
90
|
+
"No AI marking found" does not prove that a recording is human speech.
|
|
91
|
+
|
|
92
|
+
## Python
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from aristech_ai_check import check_file
|
|
96
|
+
|
|
97
|
+
result = check_file("speech.wav")
|
|
98
|
+
print(result.verdict, result.signature)
|
|
99
|
+
```
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# aristech-ai-check
|
|
2
|
+
|
|
3
|
+
Checks audio files for the AI marking of Aristech TTS. Speech from Aristech TTS is
|
|
4
|
+
marked as AI-generated in line with Art. 50(2) of the EU AI Act:
|
|
5
|
+
|
|
6
|
+
- an inaudible watermark in the audio itself, in every output format
|
|
7
|
+
- a signed C2PA manifest (Content Credentials) in WAV files
|
|
8
|
+
- an unsigned note in the file's metadata (MP3, OGG, FLAC, WAV)
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
```sh
|
|
13
|
+
pip install aristech-ai-check
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
Runs locally and offline on Linux, macOS and Windows. No audio is sent anywhere.
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```sh
|
|
21
|
+
aristech-ai-check speech.wav recording.mp3
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```
|
|
25
|
+
speech.wav
|
|
26
|
+
Watermark: present
|
|
27
|
+
Signature: valid, signed by Aristech GmbH (Aristech TTS Signer), created 2026-11-26T11:52:22.473Z
|
|
28
|
+
Metadata note: present ("Synthetic speech generated by aristech-tts-20cd4e418375")
|
|
29
|
+
Result: AI-generated
|
|
30
|
+
recording.mp3
|
|
31
|
+
Watermark: not found
|
|
32
|
+
Signature: none
|
|
33
|
+
Metadata note: none
|
|
34
|
+
Result: no AI marking found
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
`--lang de` prints German, `--json` one JSON object per file. Supported formats: WAV
|
|
38
|
+
(including A-law and µ-law), FLAC, OGG and MP3. Stereo files are checked channel by
|
|
39
|
+
channel.
|
|
40
|
+
|
|
41
|
+
Exit code 0 means every file was checked, whatever the result. Exit code 1 means at
|
|
42
|
+
least one file could not be checked (for example because it is missing or not an
|
|
43
|
+
audio file).
|
|
44
|
+
|
|
45
|
+
## Reading the result
|
|
46
|
+
|
|
47
|
+
The result is "AI-generated", "inconclusive" or "no AI marking found".
|
|
48
|
+
|
|
49
|
+
- The watermark shows that the audio was generated by AI. Other providers use the
|
|
50
|
+
same kind of watermark, so on its own it does not show that the audio comes from
|
|
51
|
+
Aristech.
|
|
52
|
+
- A valid signature from Aristech GmbH proves that the file was generated by Aristech
|
|
53
|
+
TTS and has not been changed since. It makes the result "AI-generated" in any case.
|
|
54
|
+
- The metadata note is shown for information only. It is unsigned and does not change
|
|
55
|
+
the result.
|
|
56
|
+
|
|
57
|
+
"No AI marking found" does not prove that a recording is human speech.
|
|
58
|
+
|
|
59
|
+
## Python
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from aristech_ai_check import check_file
|
|
63
|
+
|
|
64
|
+
result = check_file("speech.wav")
|
|
65
|
+
print(result.verdict, result.signature)
|
|
66
|
+
```
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
This package contains a detector model derived from the following software:
|
|
2
|
+
|
|
3
|
+
MIT License
|
|
4
|
+
|
|
5
|
+
Copyright (c) 2025 Resemble AI
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "aristech-ai-check"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
description = "Checks audio files for the AI marking of Aristech TTS (EU AI Act Art. 50)"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = [
|
|
8
|
+
"LICENSE",
|
|
9
|
+
"THIRD_PARTY_NOTICES",
|
|
10
|
+
]
|
|
11
|
+
keywords = [
|
|
12
|
+
"ai-act",
|
|
13
|
+
"ai-generated",
|
|
14
|
+
"audio",
|
|
15
|
+
"c2pa",
|
|
16
|
+
"content-credentials",
|
|
17
|
+
"detection",
|
|
18
|
+
"speech",
|
|
19
|
+
"tts",
|
|
20
|
+
"watermark",
|
|
21
|
+
]
|
|
22
|
+
classifiers = [
|
|
23
|
+
"Development Status :: 5 - Production/Stable",
|
|
24
|
+
"Environment :: Console",
|
|
25
|
+
"Intended Audience :: End Users/Desktop",
|
|
26
|
+
"Intended Audience :: Developers",
|
|
27
|
+
"Natural Language :: English",
|
|
28
|
+
"Natural Language :: German",
|
|
29
|
+
"Operating System :: OS Independent",
|
|
30
|
+
"Programming Language :: Python :: 3",
|
|
31
|
+
"Programming Language :: Python :: 3.10",
|
|
32
|
+
"Programming Language :: Python :: 3.11",
|
|
33
|
+
"Programming Language :: Python :: 3.12",
|
|
34
|
+
"Programming Language :: Python :: 3.13",
|
|
35
|
+
"Topic :: Multimedia :: Sound/Audio :: Analysis",
|
|
36
|
+
"Typing :: Typed",
|
|
37
|
+
]
|
|
38
|
+
requires-python = ">=3.10"
|
|
39
|
+
dependencies = [
|
|
40
|
+
"numpy>=1.26",
|
|
41
|
+
"scipy>=1.11",
|
|
42
|
+
"soundfile>=0.12",
|
|
43
|
+
"onnxruntime>=1.19",
|
|
44
|
+
"c2pa-python>=0.39,<0.40",
|
|
45
|
+
"tinytag>=2.0",
|
|
46
|
+
]
|
|
47
|
+
|
|
48
|
+
[[project.authors]]
|
|
49
|
+
name = "Aristech GmbH"
|
|
50
|
+
|
|
51
|
+
[project.urls]
|
|
52
|
+
Homepage = "https://aristech.ai"
|
|
53
|
+
|
|
54
|
+
[project.scripts]
|
|
55
|
+
aristech-ai-check = "aristech_ai_check.cli:main"
|
|
56
|
+
|
|
57
|
+
[dependency-groups]
|
|
58
|
+
dev = ["pytest"]
|
|
59
|
+
|
|
60
|
+
[build-system]
|
|
61
|
+
requires = ["uv_build>=0.13.5,<0.14.0"]
|
|
62
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "aristech-ai-check"
|
|
3
|
+
version = "1.0.0"
|
|
4
|
+
description = "Checks audio files for the AI marking of Aristech TTS (EU AI Act Art. 50)"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = "MIT"
|
|
7
|
+
license-files = ["LICENSE", "THIRD_PARTY_NOTICES"]
|
|
8
|
+
authors = [{ name = "Aristech GmbH" }]
|
|
9
|
+
keywords = ["ai-act", "ai-generated", "audio", "c2pa", "content-credentials", "detection", "speech", "tts", "watermark"]
|
|
10
|
+
classifiers = [
|
|
11
|
+
"Development Status :: 5 - Production/Stable",
|
|
12
|
+
"Environment :: Console",
|
|
13
|
+
"Intended Audience :: End Users/Desktop",
|
|
14
|
+
"Intended Audience :: Developers",
|
|
15
|
+
"Natural Language :: English",
|
|
16
|
+
"Natural Language :: German",
|
|
17
|
+
"Operating System :: OS Independent",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Programming Language :: Python :: 3.10",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Topic :: Multimedia :: Sound/Audio :: Analysis",
|
|
24
|
+
"Typing :: Typed",
|
|
25
|
+
]
|
|
26
|
+
requires-python = ">=3.10"
|
|
27
|
+
dependencies = [
|
|
28
|
+
"numpy>=1.26",
|
|
29
|
+
"scipy>=1.11",
|
|
30
|
+
"soundfile>=0.12",
|
|
31
|
+
# 1.19 is the first release that works with numpy 2
|
|
32
|
+
"onnxruntime>=1.19",
|
|
33
|
+
"c2pa-python>=0.39,<0.40",
|
|
34
|
+
"tinytag>=2.0",
|
|
35
|
+
]
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Homepage = "https://aristech.ai"
|
|
39
|
+
|
|
40
|
+
[project.scripts]
|
|
41
|
+
aristech-ai-check = "aristech_ai_check.cli:main"
|
|
42
|
+
|
|
43
|
+
[dependency-groups]
|
|
44
|
+
dev = ["pytest"]
|
|
45
|
+
|
|
46
|
+
[build-system]
|
|
47
|
+
requires = ["uv_build>=0.13.5,<0.14.0"]
|
|
48
|
+
build-backend = "uv_build"
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
-----BEGIN CERTIFICATE-----
|
|
2
|
+
MIIB1DCCAXmgAwIBAgIUGB2ZA5QiUsCqqSBbjN994Hu4lP8wCgYIKoZIzj0EAwIw
|
|
3
|
+
RjEWMBQGA1UECgwNQXJpc3RlY2ggR21iSDEsMCoGA1UEAwwjQXJpc3RlY2ggVFRT
|
|
4
|
+
IENvbnRlbnQgQ3JlZGVudGlhbHMgQ0EwHhcNMjYxMTE3MDc0MjI4WhcNMzYxMTE0
|
|
5
|
+
MDc0MjI4WjBGMRYwFAYDVQQKDA1BcmlzdGVjaCBHbWJIMSwwKgYDVQQDDCNBcmlz
|
|
6
|
+
dGVjaCBUVFMgQ29udGVudCBDcmVkZW50aWFscyBDQTBZMBMGByqGSM49AgEGCCqG
|
|
7
|
+
SM49AwEHA0IABGX7XxrYClXdT8hmRr2RHjV64unu/GoOKkL9Vi2piYvlrPJBnz8V
|
|
8
|
+
46EyamU8rREaWEJW2wEEcoD9o6x6p8PbFXWjRTBDMBIGA1UdEwEB/wQIMAYBAf8C
|
|
9
|
+
AQAwDgYDVR0PAQH/BAQDAgEGMB0GA1UdDgQWBBStEJYQpxaHmqjBFolKrbSnefIb
|
|
10
|
+
cTAKBggqhkjOPQQDAgNJADBGAiEAnuB3rZnmLlY5fZP/S3pukc5jzP+7pNExPRwB
|
|
11
|
+
Dwq8TOICIQCMPXH0A2FcTYViaZjQqr86hY3lai43l5Y1IH6wk18bUA==
|
|
12
|
+
-----END CERTIFICATE-----
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
"""Combines watermark, C2PA signature and metadata note into one verdict per file."""
|
|
2
|
+
|
|
3
|
+
import io
|
|
4
|
+
import os
|
|
5
|
+
from dataclasses import asdict, dataclass
|
|
6
|
+
from typing import BinaryIO, Literal
|
|
7
|
+
|
|
8
|
+
import soundfile as sf
|
|
9
|
+
from tinytag import TinyTag
|
|
10
|
+
|
|
11
|
+
from .provenance import Provenance, check_provenance
|
|
12
|
+
from .watermark import file_score
|
|
13
|
+
|
|
14
|
+
Verdict = Literal["ai_generated", "inconclusive", "not_found"]
|
|
15
|
+
Watermark = Literal["present", "inconclusive", "not_found"]
|
|
16
|
+
|
|
17
|
+
_PRESENT = 0.9
|
|
18
|
+
_INCONCLUSIVE = 0.5
|
|
19
|
+
SHORT_SECONDS = 1.5
|
|
20
|
+
|
|
21
|
+
_MIME = {"WAV": "audio/wav", "WAVEX": "audio/wav"}
|
|
22
|
+
# Wording of the unsigned note Aristech TTS writes into MP3, OGG, FLAC and WAV tags.
|
|
23
|
+
_NOTE_PREFIX = "Synthetic speech generated by"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@dataclass
|
|
27
|
+
class Result:
|
|
28
|
+
"""Outcome of checking one audio file."""
|
|
29
|
+
|
|
30
|
+
file: str
|
|
31
|
+
verdict: Verdict
|
|
32
|
+
watermark: Watermark
|
|
33
|
+
seconds: float
|
|
34
|
+
signature: Provenance | None
|
|
35
|
+
# Unsigned, so it is shown but never decides the verdict.
|
|
36
|
+
metadata_note: str | None
|
|
37
|
+
|
|
38
|
+
def as_dict(self) -> dict:
|
|
39
|
+
d = asdict(self)
|
|
40
|
+
d["seconds"] = round(self.seconds, 2)
|
|
41
|
+
return d
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _watermark(score: float) -> Watermark:
|
|
45
|
+
if score >= _PRESENT:
|
|
46
|
+
return "present"
|
|
47
|
+
if score >= _INCONCLUSIVE:
|
|
48
|
+
return "inconclusive"
|
|
49
|
+
return "not_found"
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def _metadata_note(stream: BinaryIO) -> str | None:
|
|
53
|
+
try:
|
|
54
|
+
tag = TinyTag.get(file_obj=stream)
|
|
55
|
+
except Exception:
|
|
56
|
+
return None
|
|
57
|
+
# ffmpeg writes the MP3 comment as TXXX:comment, which tinytag files under "_comment".
|
|
58
|
+
candidates = [tag.comment, *tag.other.get("_comment", []), *tag.other.get("comment", [])]
|
|
59
|
+
return next((c for c in candidates if c and c.startswith(_NOTE_PREFIX)), None)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def _check(stream: BinaryIO, name: str) -> Result:
|
|
63
|
+
info = sf.info(stream)
|
|
64
|
+
stream.seek(0)
|
|
65
|
+
score, seconds = file_score(stream)
|
|
66
|
+
watermark = _watermark(score)
|
|
67
|
+
|
|
68
|
+
mime = _MIME.get(info.format)
|
|
69
|
+
stream.seek(0)
|
|
70
|
+
signature = check_provenance(stream, mime) if mime else None
|
|
71
|
+
stream.seek(0)
|
|
72
|
+
note = _metadata_note(stream)
|
|
73
|
+
|
|
74
|
+
if signature and signature.status == "trusted" and signature.ai_generated:
|
|
75
|
+
verdict: Verdict = "ai_generated"
|
|
76
|
+
elif watermark == "present":
|
|
77
|
+
verdict = "ai_generated"
|
|
78
|
+
else:
|
|
79
|
+
verdict = watermark
|
|
80
|
+
return Result(name, verdict, watermark, seconds, signature, note)
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def check_file(path: str | os.PathLike) -> Result:
|
|
84
|
+
"""Checks the audio file at `path` (WAV, FLAC, OGG or MP3)."""
|
|
85
|
+
with open(path, "rb") as f:
|
|
86
|
+
return _check(f, os.fspath(path))
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def check_bytes(data: bytes, name: str = "") -> Result:
|
|
90
|
+
"""Checks audio given as bytes. `name` is only copied into the result."""
|
|
91
|
+
return _check(io.BytesIO(data), name)
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
import argparse
|
|
2
|
+
import json
|
|
3
|
+
import locale
|
|
4
|
+
import os
|
|
5
|
+
import sys
|
|
6
|
+
from importlib.metadata import version
|
|
7
|
+
|
|
8
|
+
import soundfile as sf
|
|
9
|
+
|
|
10
|
+
from .check import SHORT_SECONDS, check_file
|
|
11
|
+
from .watermark import AudioTooLong, AudioTooShort, ModelMissing
|
|
12
|
+
|
|
13
|
+
TEXT = {
|
|
14
|
+
"de": {
|
|
15
|
+
"ai_generated": "KI-generiert",
|
|
16
|
+
"inconclusive": "nicht eindeutig",
|
|
17
|
+
"not_found": "keine KI-Kennzeichnung gefunden",
|
|
18
|
+
"watermark": "Wasserzeichen",
|
|
19
|
+
"present": "vorhanden",
|
|
20
|
+
"wm_inconclusive": "nicht eindeutig",
|
|
21
|
+
"wm_not_found": "nicht gefunden",
|
|
22
|
+
"signature": "Signatur",
|
|
23
|
+
"none": "keine",
|
|
24
|
+
"trusted": "gültig, signiert von {issuer} ({signer})",
|
|
25
|
+
"untrusted": "gültig, aber nicht von Aristech signiert ({issuer})",
|
|
26
|
+
"invalid": "konnte nicht bestätigt werden, z. B. weil die Datei nach der Erzeugung verändert wurde",
|
|
27
|
+
"created": "erzeugt am {created}",
|
|
28
|
+
"note": "Metadaten-Hinweis",
|
|
29
|
+
"note_present": 'vorhanden ("{note}")',
|
|
30
|
+
"result": "Ergebnis",
|
|
31
|
+
"short": "Hinweis: kurze Aufnahme ({seconds} s), das Wasserzeichen ist dort schwächer. "
|
|
32
|
+
"Eine längere Aufnahme liefert ein eindeutigeres Ergebnis.",
|
|
33
|
+
"error": "Fehler",
|
|
34
|
+
"decimal": ",",
|
|
35
|
+
"file_not_found": "Datei nicht gefunden",
|
|
36
|
+
"is_directory": "ist ein Verzeichnis, keine Datei",
|
|
37
|
+
"permission_denied": "keine Leseberechtigung",
|
|
38
|
+
"unreadable": "keine lesbare Audiodatei (unterstützt: WAV, FLAC, OGG, MP3)",
|
|
39
|
+
"too_short": "Aufnahme zu kurz für eine Prüfung",
|
|
40
|
+
"too_long": "Aufnahme länger als 30 Minuten, bitte kürzen",
|
|
41
|
+
"model_missing": "Prüfmodell fehlt, bitte das Paket neu installieren",
|
|
42
|
+
"internal": "unerwarteter Fehler: {detail}",
|
|
43
|
+
},
|
|
44
|
+
"en": {
|
|
45
|
+
"ai_generated": "AI-generated",
|
|
46
|
+
"inconclusive": "inconclusive",
|
|
47
|
+
"not_found": "no AI marking found",
|
|
48
|
+
"watermark": "Watermark",
|
|
49
|
+
"present": "present",
|
|
50
|
+
"wm_inconclusive": "inconclusive",
|
|
51
|
+
"wm_not_found": "not found",
|
|
52
|
+
"signature": "Signature",
|
|
53
|
+
"none": "none",
|
|
54
|
+
"trusted": "valid, signed by {issuer} ({signer})",
|
|
55
|
+
"untrusted": "valid, but not signed by Aristech ({issuer})",
|
|
56
|
+
"invalid": "could not be verified, e.g. because the file was changed after it was generated",
|
|
57
|
+
"created": "created {created}",
|
|
58
|
+
"note": "Metadata note",
|
|
59
|
+
"note_present": 'present ("{note}")',
|
|
60
|
+
"result": "Result",
|
|
61
|
+
"short": "Note: short recording ({seconds} s), the watermark is weaker there. "
|
|
62
|
+
"A longer recording gives a clearer result.",
|
|
63
|
+
"error": "Error",
|
|
64
|
+
"decimal": ".",
|
|
65
|
+
"file_not_found": "file not found",
|
|
66
|
+
"is_directory": "is a directory, not a file",
|
|
67
|
+
"permission_denied": "permission denied",
|
|
68
|
+
"unreadable": "not a readable audio file (supported: WAV, FLAC, OGG, MP3)",
|
|
69
|
+
"too_short": "recording too short to check",
|
|
70
|
+
"too_long": "recording longer than 30 minutes, please shorten it",
|
|
71
|
+
"model_missing": "detector model missing, please reinstall the package",
|
|
72
|
+
"internal": "unexpected error: {detail}",
|
|
73
|
+
},
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
_ERRORS = [
|
|
77
|
+
(FileNotFoundError, "file_not_found"),
|
|
78
|
+
(IsADirectoryError, "is_directory"),
|
|
79
|
+
(PermissionError, "permission_denied"),
|
|
80
|
+
(AudioTooShort, "too_short"),
|
|
81
|
+
(AudioTooLong, "too_long"),
|
|
82
|
+
(ModelMissing, "model_missing"),
|
|
83
|
+
(sf.LibsndfileError, "unreadable"),
|
|
84
|
+
]
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def _default_lang() -> str:
|
|
88
|
+
for var in ("LC_ALL", "LC_MESSAGES", "LANG"):
|
|
89
|
+
if os.environ.get(var):
|
|
90
|
+
return "de" if os.environ[var].lower().startswith("de") else "en"
|
|
91
|
+
# Windows reports e.g. "German_Germany".
|
|
92
|
+
lang = (locale.getlocale()[0] or "").lower()
|
|
93
|
+
return "de" if lang.startswith(("de", "german")) else "en"
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def _error_code(e: Exception) -> str:
|
|
97
|
+
return next((code for cls, code in _ERRORS if isinstance(e, cls)), "internal")
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _print_result(r, t) -> None:
|
|
101
|
+
wm = {"present": t["present"], "inconclusive": t["wm_inconclusive"], "not_found": t["wm_not_found"]}[r.watermark]
|
|
102
|
+
print(r.file)
|
|
103
|
+
print(f" {t['watermark']}: {wm}")
|
|
104
|
+
sig = r.signature
|
|
105
|
+
if sig is None:
|
|
106
|
+
print(f" {t['signature']}: {t['none']}")
|
|
107
|
+
else:
|
|
108
|
+
line = t[sig.status].format(issuer=sig.issuer, signer=sig.signer)
|
|
109
|
+
if sig.created and sig.status != "invalid":
|
|
110
|
+
line += ", " + t["created"].format(created=sig.created)
|
|
111
|
+
print(f" {t['signature']}: {line}")
|
|
112
|
+
note = t["note_present"].format(note=r.metadata_note) if r.metadata_note else t["none"]
|
|
113
|
+
print(f" {t['note']}: {note}")
|
|
114
|
+
print(f" {t['result']}: {t[r.verdict]}")
|
|
115
|
+
if r.seconds < SHORT_SECONDS and r.verdict != "ai_generated":
|
|
116
|
+
seconds = f"{r.seconds:.1f}".replace(".", t["decimal"])
|
|
117
|
+
print(f" {t['short'].format(seconds=seconds)}")
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def main(argv: list[str] | None = None) -> int:
|
|
121
|
+
parser = argparse.ArgumentParser(
|
|
122
|
+
prog="aristech-ai-check",
|
|
123
|
+
description="Checks audio files for the AI marking of Aristech TTS. "
|
|
124
|
+
"Exit code 0: all files checked, 1: at least one file could not be checked.",
|
|
125
|
+
)
|
|
126
|
+
parser.add_argument("files", nargs="+", help="audio files (WAV, FLAC, OGG, MP3)")
|
|
127
|
+
parser.add_argument("--json", action="store_true", help="one JSON object per file")
|
|
128
|
+
parser.add_argument("--lang", choices=["de", "en"], default=None, help="language of the output")
|
|
129
|
+
parser.add_argument("--version", action="version", version=f"%(prog)s {version('aristech-ai-check')}")
|
|
130
|
+
args = parser.parse_args(argv)
|
|
131
|
+
t = TEXT[args.lang or _default_lang()]
|
|
132
|
+
|
|
133
|
+
failed = False
|
|
134
|
+
for path in args.files:
|
|
135
|
+
try:
|
|
136
|
+
r = check_file(path)
|
|
137
|
+
except Exception as e: # report and continue with the next file
|
|
138
|
+
failed = True
|
|
139
|
+
code = _error_code(e)
|
|
140
|
+
if args.json:
|
|
141
|
+
print(json.dumps({"file": path, "error": code}, ensure_ascii=False))
|
|
142
|
+
else:
|
|
143
|
+
print(f"{path}\n {t['error']}: {t[code].format(detail=e)}", file=sys.stderr)
|
|
144
|
+
continue
|
|
145
|
+
if args.json:
|
|
146
|
+
print(json.dumps(r.as_dict(), ensure_ascii=False))
|
|
147
|
+
else:
|
|
148
|
+
_print_result(r, t)
|
|
149
|
+
return 1 if failed else 0
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
if __name__ == "__main__":
|
|
153
|
+
sys.exit(main())
|
|
Binary file
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"""C2PA check of WAV files against the Aristech CA."""
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
from dataclasses import dataclass
|
|
5
|
+
from functools import lru_cache
|
|
6
|
+
from importlib.resources import files
|
|
7
|
+
from typing import BinaryIO, Literal
|
|
8
|
+
|
|
9
|
+
import c2pa
|
|
10
|
+
|
|
11
|
+
_AI_SOURCE_TYPES = {
|
|
12
|
+
"http://cv.iptc.org/newscodes/digitalsourcetype/trainedAlgorithmicMedia",
|
|
13
|
+
"http://cv.iptc.org/newscodes/digitalsourcetype/compositeSynthetic",
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
# "trusted": valid and signed by an Aristech certificate.
|
|
17
|
+
# "untrusted": valid, but another signer.
|
|
18
|
+
# "invalid": the signature could not be verified, e.g. because the file was changed.
|
|
19
|
+
Status = Literal["trusted", "untrusted", "invalid"]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
@dataclass
|
|
23
|
+
class Provenance:
|
|
24
|
+
"""Result of the C2PA signature check."""
|
|
25
|
+
|
|
26
|
+
status: Status
|
|
27
|
+
signer: str | None = None
|
|
28
|
+
issuer: str | None = None
|
|
29
|
+
created: str | None = None
|
|
30
|
+
ai_generated: bool = False
|
|
31
|
+
problems: tuple[str, ...] = ()
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
@lru_cache(maxsize=1)
|
|
35
|
+
def _context() -> "c2pa.Context":
|
|
36
|
+
anchors = files("aristech_ai_check").joinpath("aristech_ca.pem").read_text()
|
|
37
|
+
return c2pa.Context(c2pa.Settings.from_dict({"trust": {"trust_anchors": anchors}}))
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def check_provenance(stream: BinaryIO, mime: str) -> Provenance | None:
|
|
41
|
+
"""None when the file carries no C2PA manifest."""
|
|
42
|
+
try:
|
|
43
|
+
with c2pa.Reader(mime, stream, context=_context()) as reader:
|
|
44
|
+
store = json.loads(reader.json())
|
|
45
|
+
except c2pa.C2paError.ManifestNotFound:
|
|
46
|
+
return None
|
|
47
|
+
except c2pa.C2paError as e:
|
|
48
|
+
return Provenance(status="invalid", problems=(str(e),))
|
|
49
|
+
|
|
50
|
+
manifest = store.get("manifests", {}).get(store.get("active_manifest"))
|
|
51
|
+
if not isinstance(manifest, dict):
|
|
52
|
+
return Provenance(status="invalid", problems=("no active manifest",))
|
|
53
|
+
info = manifest.get("signature_info") or {}
|
|
54
|
+
created = None
|
|
55
|
+
ai_generated = False
|
|
56
|
+
for assertion in manifest.get("assertions") or []:
|
|
57
|
+
if str(assertion.get("label", "")).startswith("c2pa.actions"):
|
|
58
|
+
for action in (assertion.get("data") or {}).get("actions") or []:
|
|
59
|
+
if action.get("action") == "c2pa.created":
|
|
60
|
+
created = action.get("when")
|
|
61
|
+
ai_generated = action.get("digitalSourceType") in _AI_SOURCE_TYPES
|
|
62
|
+
status: Status = {"Trusted": "trusted", "Valid": "untrusted"}.get(store.get("validation_state"), "invalid")
|
|
63
|
+
problems = tuple(s.get("code", "") for s in store.get("validation_status") or [])
|
|
64
|
+
return Provenance(
|
|
65
|
+
status=status,
|
|
66
|
+
signer=info.get("common_name"),
|
|
67
|
+
issuer=info.get("issuer"),
|
|
68
|
+
created=created,
|
|
69
|
+
ai_generated=ai_generated,
|
|
70
|
+
problems=problems,
|
|
71
|
+
)
|
|
File without changes
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
"""Watermark detection: magnitude spectrogram at 32 kHz into the bundled ONNX model."""
|
|
2
|
+
|
|
3
|
+
from functools import lru_cache
|
|
4
|
+
from importlib.resources import files
|
|
5
|
+
from math import gcd
|
|
6
|
+
|
|
7
|
+
import numpy as np
|
|
8
|
+
import onnxruntime as ort
|
|
9
|
+
import soundfile as sf
|
|
10
|
+
from scipy.signal import resample_poly
|
|
11
|
+
|
|
12
|
+
_SAMPLE_RATE = 32000
|
|
13
|
+
_N_FFT = 2048
|
|
14
|
+
_HOP = 320
|
|
15
|
+
_MIN_MAGNITUDE = 1e-9
|
|
16
|
+
_HEADROOM_DB = 15.0
|
|
17
|
+
_MIN_LEVEL_DB = 20 * np.log10(_MIN_MAGNITUDE)
|
|
18
|
+
# Shorter audio (in samples at 32 kHz) gives the model too few frames.
|
|
19
|
+
_MIN_SAMPLES = _N_FFT
|
|
20
|
+
_MAX_SECONDS = 30 * 60
|
|
21
|
+
# Frames per batch when computing the spectrogram, to bound memory on long files.
|
|
22
|
+
_FRAME_BATCH = 4096
|
|
23
|
+
# The real model is ~28 MB, a git-lfs pointer file ~130 bytes.
|
|
24
|
+
_MIN_MODEL_BYTES = 1_000_000
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class AudioTooShort(ValueError):
|
|
28
|
+
pass
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class AudioTooLong(ValueError):
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class ModelMissing(RuntimeError):
|
|
36
|
+
pass
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _spectrogram(audio: np.ndarray, sample_rate: int) -> np.ndarray:
|
|
40
|
+
"""(1025, T) normalized log magnitude of mono float audio, as the model was trained on."""
|
|
41
|
+
if sample_rate != _SAMPLE_RATE:
|
|
42
|
+
g = gcd(_SAMPLE_RATE, sample_rate)
|
|
43
|
+
audio = resample_poly(audio, _SAMPLE_RATE // g, sample_rate // g)
|
|
44
|
+
audio = np.asarray(audio, dtype=np.float32)
|
|
45
|
+
padded = np.pad(audio, _N_FFT // 2, mode="reflect")
|
|
46
|
+
n_frames = 1 + (len(padded) - _N_FFT) // _HOP
|
|
47
|
+
frames = np.lib.stride_tricks.as_strided(
|
|
48
|
+
padded, shape=(n_frames, _N_FFT), strides=(padded.strides[0] * _HOP, padded.strides[0])
|
|
49
|
+
)
|
|
50
|
+
window = (0.5 - 0.5 * np.cos(2 * np.pi * np.arange(_N_FFT) / _N_FFT)).astype(np.float32)
|
|
51
|
+
spec = np.empty((_N_FFT // 2 + 1, n_frames), dtype=np.float32)
|
|
52
|
+
for start in range(0, n_frames, _FRAME_BATCH):
|
|
53
|
+
batch = frames[start : start + _FRAME_BATCH] * window
|
|
54
|
+
magnitude = np.abs(np.fft.rfft(batch, axis=1)).T
|
|
55
|
+
db = 20 * np.log10(np.maximum(magnitude, _MIN_MAGNITUDE))
|
|
56
|
+
spec[:, start : start + len(batch)] = (db - _MIN_LEVEL_DB) / (-_MIN_LEVEL_DB + _HEADROOM_DB)
|
|
57
|
+
return spec
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
@lru_cache(maxsize=1)
|
|
61
|
+
def _session() -> ort.InferenceSession:
|
|
62
|
+
model = files("aristech_ai_check").joinpath("model/detector.onnx").read_bytes()
|
|
63
|
+
if len(model) < _MIN_MODEL_BYTES:
|
|
64
|
+
raise ModelMissing("detector model missing, the package was built without git-lfs")
|
|
65
|
+
options = ort.SessionOptions()
|
|
66
|
+
options.log_severity_level = 3
|
|
67
|
+
return ort.InferenceSession(model, options, providers=["CPUExecutionProvider"])
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def _too_short(n_samples: int, sample_rate: int) -> bool:
|
|
71
|
+
return n_samples * _SAMPLE_RATE < _MIN_SAMPLES * sample_rate
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def segment_score(audio: np.ndarray, sample_rate: int) -> float:
|
|
75
|
+
"""Score between 0 and 1 for one mono segment, scored as a whole."""
|
|
76
|
+
if _too_short(len(audio), sample_rate):
|
|
77
|
+
raise AudioTooShort("audio too short")
|
|
78
|
+
(score,) = _session().run(["score"], {"magspec": _spectrogram(audio, sample_rate)[None]})
|
|
79
|
+
return float(np.clip(score[0], 0.0, 1.0))
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def file_score(stream) -> tuple[float, float]:
|
|
83
|
+
"""(highest score over the channels, duration in seconds). Each channel is scored as a whole."""
|
|
84
|
+
with sf.SoundFile(stream) as f:
|
|
85
|
+
if f.frames > _MAX_SECONDS * f.samplerate:
|
|
86
|
+
raise AudioTooLong("audio too long")
|
|
87
|
+
# read() without a frame count stops at the real end. Some decoders (MP3)
|
|
88
|
+
# report a few more frames than they deliver.
|
|
89
|
+
audio = f.read(dtype="float32", always_2d=True)
|
|
90
|
+
rate = f.samplerate
|
|
91
|
+
if len(audio) == 0 or _too_short(len(audio), rate):
|
|
92
|
+
raise AudioTooShort("audio too short")
|
|
93
|
+
audio = np.clip(np.nan_to_num(audio, nan=0.0, posinf=0.0, neginf=0.0), -1.0, 1.0)
|
|
94
|
+
best = max(segment_score(np.ascontiguousarray(channel), rate) for channel in audio.T)
|
|
95
|
+
return best, len(audio) / rate
|