Spaces:
Runtime error
Runtime error
Commit
·
089179d
1
Parent(s):
7342b32
update desc
Browse files- .gitignore +1 -1
- app.py +29 -16
.gitignore
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
.DS_Store
|
| 2 |
-
|
| 3 |
#idea
|
| 4 |
.idea
|
| 5 |
wandb/
|
|
|
|
| 1 |
.DS_Store
|
| 2 |
+
说明.txt
|
| 3 |
#idea
|
| 4 |
.idea
|
| 5 |
wandb/
|
app.py
CHANGED
|
@@ -1,27 +1,31 @@
|
|
| 1 |
-
import pdb
|
| 2 |
import time
|
| 3 |
import wavmark
|
| 4 |
import streamlit as st
|
| 5 |
import os
|
| 6 |
import torch
|
| 7 |
-
import uuid
|
| 8 |
import datetime
|
| 9 |
import numpy as np
|
| 10 |
import soundfile
|
| 11 |
-
from huggingface_hub import hf_hub_download, HfApi
|
| 12 |
from wavmark.utils import file_reader
|
| 13 |
|
| 14 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
def add_watermark(audio_path, watermark_text):
|
| 16 |
t1 = time.time()
|
| 17 |
assert len(watermark_text) == 16
|
| 18 |
watermark_npy = np.array([int(i) for i in watermark_text])
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
signal, sr, audio_length_second = file_reader.read_as_single_channel_16k(audio_path, 16000)
|
| 22 |
watermarked_signal, _ = wavmark.encode_watermark(model, signal, watermark_npy, show_progress=False)
|
| 23 |
|
| 24 |
-
tmp_file_name = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S') + "_" +
|
| 25 |
tmp_file_path = '/tmp/' + tmp_file_name
|
| 26 |
soundfile.write(tmp_file_path, watermarked_signal, sr)
|
| 27 |
encode_time_cost = time.time() - t1
|
|
@@ -32,12 +36,8 @@ def decode_watermark(audio_path):
|
|
| 32 |
assert os.path.exists(audio_path)
|
| 33 |
|
| 34 |
t1 = time.time()
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
if audio_length_second > max_second:
|
| 38 |
-
watermarked_signal = watermarked_signal[0:16000 * max_second]
|
| 39 |
-
|
| 40 |
-
payload_decoded, _ = wavmark.decode_watermark(model, watermarked_signal, show_progress=False)
|
| 41 |
decode_cost = time.time() - t1
|
| 42 |
|
| 43 |
if payload_decoded is None:
|
|
@@ -59,8 +59,19 @@ def create_default_value():
|
|
| 59 |
def main():
|
| 60 |
create_default_value()
|
| 61 |
|
| 62 |
-
st.title("WavMark")
|
| 63 |
-
st.write("https://github.com/wavmark/wavmark")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 64 |
|
| 65 |
audio_file = st.file_uploader("Upload Audio", type=["wav", "mp3"], accept_multiple_files=False)
|
| 66 |
|
|
@@ -95,8 +106,10 @@ def main():
|
|
| 95 |
|
| 96 |
|
| 97 |
if __name__ == "__main__":
|
|
|
|
|
|
|
|
|
|
| 98 |
len_start_bit = 16
|
| 99 |
-
|
| 100 |
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
|
| 101 |
model = wavmark.load_model().to(device)
|
| 102 |
main()
|
|
|
|
|
|
|
| 1 |
import time
|
| 2 |
import wavmark
|
| 3 |
import streamlit as st
|
| 4 |
import os
|
| 5 |
import torch
|
|
|
|
| 6 |
import datetime
|
| 7 |
import numpy as np
|
| 8 |
import soundfile
|
|
|
|
| 9 |
from wavmark.utils import file_reader
|
| 10 |
|
| 11 |
|
| 12 |
+
def my_read_file(audio_path, max_second):
|
| 13 |
+
signal, sr, audio_length_second = file_reader.read_as_single_channel_16k(audio_path, default_sr)
|
| 14 |
+
if audio_length_second > max_second:
|
| 15 |
+
signal = signal[0:default_sr * max_second]
|
| 16 |
+
audio_length_second = max_second
|
| 17 |
+
|
| 18 |
+
return signal, sr, audio_length_second
|
| 19 |
+
|
| 20 |
+
|
| 21 |
def add_watermark(audio_path, watermark_text):
|
| 22 |
t1 = time.time()
|
| 23 |
assert len(watermark_text) == 16
|
| 24 |
watermark_npy = np.array([int(i) for i in watermark_text])
|
| 25 |
+
signal, sr, audio_length_second = my_read_file(audio_path, max_second_encode)
|
|
|
|
|
|
|
| 26 |
watermarked_signal, _ = wavmark.encode_watermark(model, signal, watermark_npy, show_progress=False)
|
| 27 |
|
| 28 |
+
tmp_file_name = datetime.datetime.now().strftime('%Y-%m-%d_%H-%M-%S') + "_" + watermark_text + ".wav"
|
| 29 |
tmp_file_path = '/tmp/' + tmp_file_name
|
| 30 |
soundfile.write(tmp_file_path, watermarked_signal, sr)
|
| 31 |
encode_time_cost = time.time() - t1
|
|
|
|
| 36 |
assert os.path.exists(audio_path)
|
| 37 |
|
| 38 |
t1 = time.time()
|
| 39 |
+
signal, sr, audio_length_second = my_read_file(audio_path, max_second_decode)
|
| 40 |
+
payload_decoded, _ = wavmark.decode_watermark(model, signal, show_progress=False)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
decode_cost = time.time() - t1
|
| 42 |
|
| 43 |
if payload_decoded is None:
|
|
|
|
| 59 |
def main():
|
| 60 |
create_default_value()
|
| 61 |
|
| 62 |
+
# st.title("WavMark")
|
| 63 |
+
# st.write("https://github.com/wavmark/wavmark")
|
| 64 |
+
markdown_text = """
|
| 65 |
+
# WavMark
|
| 66 |
+
[WavMark](https://github.com/wavmark/wavmark) is the next-generation watermarking tool driven by AI.
|
| 67 |
+
You can upload an audio file and encode a custom 16-bit watermark or perform decoding from a watermarked audio.
|
| 68 |
+
|
| 69 |
+
This page is for demonstration usage and only process **the first minute** of the audio.
|
| 70 |
+
If you have longer files for processing, we recommend using [our python toolkit](https://github.com/wavmark/wavmark).
|
| 71 |
+
"""
|
| 72 |
+
|
| 73 |
+
# 使用st.markdown渲染Markdown文本
|
| 74 |
+
st.markdown(markdown_text)
|
| 75 |
|
| 76 |
audio_file = st.file_uploader("Upload Audio", type=["wav", "mp3"], accept_multiple_files=False)
|
| 77 |
|
|
|
|
| 106 |
|
| 107 |
|
| 108 |
if __name__ == "__main__":
|
| 109 |
+
default_sr = 16000
|
| 110 |
+
max_second_encode = 60
|
| 111 |
+
max_second_decode = 30
|
| 112 |
len_start_bit = 16
|
|
|
|
| 113 |
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
|
| 114 |
model = wavmark.load_model().to(device)
|
| 115 |
main()
|