Spaces:
Runtime error
Runtime error
Kabatubare
commited on
Commit
•
09457f4
1
Parent(s):
d1640d9
Update
Browse files
app.py
CHANGED
@@ -6,20 +6,15 @@ import traceback
|
|
6 |
|
7 |
def detect_watermark(audio_file_path):
|
8 |
try:
|
9 |
-
# Load the audio file
|
10 |
waveform, sample_rate = torchaudio.load(audio_file_path)
|
|
|
|
|
|
|
|
|
11 |
|
12 |
-
# Normalize
|
13 |
-
|
14 |
-
if waveform_max > 0:
|
15 |
-
waveform = waveform / waveform_max
|
16 |
-
|
17 |
-
# Resample the waveform to 16kHz if necessary
|
18 |
-
target_sample_rate = 16000
|
19 |
-
if sample_rate != target_sample_rate:
|
20 |
-
resampler = torchaudio.transforms.Resample(orig_freq=sample_rate, new_freq=target_sample_rate)
|
21 |
-
waveform = resampler(waveform)
|
22 |
-
sample_rate = target_sample_rate
|
23 |
|
24 |
# Ensure waveform has a batch dimension for processing
|
25 |
if waveform.ndim < 3:
|
@@ -28,18 +23,16 @@ def detect_watermark(audio_file_path):
|
|
28 |
# Initialize the AudioSeal detector
|
29 |
detector = AudioSeal.load_detector("audioseal_detector_16bits")
|
30 |
|
31 |
-
#
|
32 |
-
|
33 |
-
|
34 |
-
result, confidence = detector.detect_watermark(waveform, message_threshold=message_threshold)
|
35 |
|
36 |
-
#
|
37 |
-
if result:
|
38 |
-
detection_result =
|
39 |
-
else:
|
40 |
-
detection_result = "
|
41 |
|
42 |
-
return
|
43 |
except Exception as e:
|
44 |
error_traceback = traceback.format_exc()
|
45 |
return f"Error occurred: {e}\n\n{error_traceback}"
|
|
|
6 |
|
7 |
def detect_watermark(audio_file_path):
|
8 |
try:
|
9 |
+
# Load the audio file and resample if necessary
|
10 |
waveform, sample_rate = torchaudio.load(audio_file_path)
|
11 |
+
if sample_rate != 16000:
|
12 |
+
resample_transform = torchaudio.transforms.Resample(orig_freq=sample_rate, new_freq=16000)
|
13 |
+
waveform = resample_transform(waveform)
|
14 |
+
sample_rate = 16000
|
15 |
|
16 |
+
# Normalize waveform loudness
|
17 |
+
waveform = torch.clamp(waveform, min=-1.0, max=1.0)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
# Ensure waveform has a batch dimension for processing
|
20 |
if waveform.ndim < 3:
|
|
|
23 |
# Initialize the AudioSeal detector
|
24 |
detector = AudioSeal.load_detector("audioseal_detector_16bits")
|
25 |
|
26 |
+
# Detect watermark (simplified to binary outcome for AI-generated or not)
|
27 |
+
result, _ = detector.detect_watermark(waveform, message_threshold=0.99)
|
|
|
|
|
28 |
|
29 |
+
# Simplify the output message
|
30 |
+
if result == 1: # Assuming '1' means AI-generated
|
31 |
+
detection_result = "The audio is likely AI-generated."
|
32 |
+
else: # Assuming '0' means human-created
|
33 |
+
detection_result = "The audio is likely human-created."
|
34 |
|
35 |
+
return detection_result
|
36 |
except Exception as e:
|
37 |
error_traceback = traceback.format_exc()
|
38 |
return f"Error occurred: {e}\n\n{error_traceback}"
|