wavmark


Namewavmark JSON
Version 0.0.3 PyPI version JSON
download
home_page
SummaryAI-Based Audio Watermarking Tool
upload_time2024-01-07 07:46:10
maintainer
docs_urlNone
author
requires_python>=3.6
license
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # WavMark
> AI-based Audio Watermarking Tool

- ⚡  **Leading Stability:** The watermark resist to **10**  types of common attacks like Gaussian noise, MP3 compression, low-pass filter, and speed variation; achieving over **29** times in robustness compared with the traditional method.
- 🙉 **High Imperceptibility:** The watermarked audio has over 38dB SNR and 4.3 PESQ, which means it is inaudible to humans. Listen the examples: [https://wavmark.github.io/](https://wavmark.github.io/).
- 😉 **Easy for Extending:** This project is entirely python based. You can easily leverage our underlying PyTorch model to implement a custom watermarking system with higher capacity or robustness.
- 🤗 **Huggingface Spaces:**  Try our online demonstration: https://huggingface.co/spaces/M4869/WavMark

## Installation
```
pip install wavmark
```

## Basic Usage
The following code adds 16-bit watermark into the input file `example.wav` and subsequently performs decoding:
```python
import numpy as np
import soundfile
import torch
import wavmark


# 1.load model
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
model = wavmark.load_model().to(device)

# 2.create 16-bit payload
payload = np.random.choice([0, 1], size=16)
print("Payload:", payload)

# 3.read host audio
# the audio should be a single-channel 16kHz wav, you can read it using soundfile:
signal, sample_rate = soundfile.read("example.wav")
# Otherwise, you can use the following function to convert the host audio to single-channel 16kHz format:
# from wavmark.utils import file_reader
# signal = file_reader.read_as_single_channel("example.wav", aim_sr=16000)

# 4.encode watermark
watermarked_signal, _ = wavmark.encode_watermark(model, signal, payload, show_progress=True)
# you can save it as a new wav:
# soundfile.write("output.wav", watermarked_signal, 16000)

# 5.decode watermark
payload_decoded, _ = wavmark.decode_watermark(model, watermarked_signal, show_progress=True)
BER = (payload != payload_decoded).mean() * 100

print("Decode BER:%.1f" % BER)
```


## How it works?
In paper [WavMark: Watermarking for Audio Generation](https://arxiv.org/pdf/2308.12770.pdf) we proposed the WavMark model,
which enables encoding 32 bits of information into 1-second audio.
In this tool, we take the first 16 bits as a fixed pattern for watermark identification and the remaining 16 bits as a custom payload.
The same watermark is added repetitively to ensure full-time region protection:
![Illustrate](data/imgs/structure.png)

Since the pattern length is 16, the probability of "mistakenly identifying an unwatermarked audio as watermarked" is only  `1/(2^16)=0.000015`.



## Low-level Access
For a specific watermarking algorithm, there exists a trade-off among capacity, robustness, and imperceptibility. 
Therefore, a watermarking system often needs customization according to application requirements.
The good news is that WavMark is entirely implemented with PyTorch. 
Here is an example of directly calling the PyTorch model:

```python
# 1.load model
device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
model = wavmark.load_model().to(device)

# 2. take 16,000 samples
signal, sample_rate = soundfile.read("example.wav")
trunck = signal[0:16000]
message_npy = np.random.choice([0, 1], size=32)

# 3. do encode:
with torch.no_grad():
    signal = torch.FloatTensor(trunck).to(device)[None]
    message_tensor = torch.FloatTensor(message_npy).to(device)[None]
    signal_wmd_tensor = model.encode(signal, message_tensor)
    signal_wmd_npy = signal_wmd_tensor.detach().cpu().numpy().squeeze()

# 4.do decode:
with torch.no_grad():
    signal = torch.FloatTensor(signal_wmd_npy).to(device).unsqueeze(0)
    message_decoded_npy = (model.decode(signal) >= 0.5).int().detach().cpu().numpy().squeeze()

BER = (message_npy != message_decoded_npy).mean() * 100
print("BER:", BER)
```





## Thanks
The "[Audiowmark](https://uplex.de/audiowmark)" developed by Stefan Westerfeld has provided valuable ideas for the design of this project.
## Citation
```
@misc{chen2023wavmark,
      title={WavMark: Watermarking for Audio Generation}, 
      author={Guangyu Chen and Yu Wu and Shujie Liu and Tao Liu and Xiaoyong Du and Furu Wei},
      year={2023},
      eprint={2308.12770},
      archivePrefix={arXiv},
      primaryClass={cs.SD}
}
```

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "wavmark",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "",
    "author": "",
    "author_email": "\"Guangyu Chen (RUC)\" <v-chenguangyu@outlook.com>",
    "download_url": "https://files.pythonhosted.org/packages/26/46/31acbe081fe7822a26af90e7e9f2160daa01bcf78cc94b2f46132c9b9adc/wavmark-0.0.3.tar.gz",
    "platform": null,
    "description": "# WavMark\n> AI-based Audio Watermarking Tool\n\n- \u26a1  **Leading Stability:** The watermark resist to **10**  types of common attacks like Gaussian noise, MP3 compression, low-pass filter, and speed variation; achieving over **29** times in robustness compared with the traditional method.\n- \ud83d\ude49 **High Imperceptibility:** The watermarked audio has over 38dB SNR and 4.3 PESQ, which means it is inaudible to humans. Listen the examples: [https://wavmark.github.io/](https://wavmark.github.io/).\n- \ud83d\ude09 **Easy for Extending:** This project is entirely python based. You can easily leverage our underlying PyTorch model to implement a custom watermarking system with higher capacity or robustness.\n- \ud83e\udd17 **Huggingface Spaces:**  Try our online demonstration: https://huggingface.co/spaces/M4869/WavMark\n\n## Installation\n```\npip install wavmark\n```\n\n## Basic Usage\nThe following code adds 16-bit watermark into the input file `example.wav` and subsequently performs decoding:\n```python\nimport numpy as np\nimport soundfile\nimport torch\nimport wavmark\n\n\n# 1.load model\ndevice = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')\nmodel = wavmark.load_model().to(device)\n\n# 2.create 16-bit payload\npayload = np.random.choice([0, 1], size=16)\nprint(\"Payload:\", payload)\n\n# 3.read host audio\n# the audio should be a single-channel 16kHz wav, you can read it using soundfile:\nsignal, sample_rate = soundfile.read(\"example.wav\")\n# Otherwise, you can use the following function to convert the host audio to single-channel 16kHz format:\n# from wavmark.utils import file_reader\n# signal = file_reader.read_as_single_channel(\"example.wav\", aim_sr=16000)\n\n# 4.encode watermark\nwatermarked_signal, _ = wavmark.encode_watermark(model, signal, payload, show_progress=True)\n# you can save it as a new wav:\n# soundfile.write(\"output.wav\", watermarked_signal, 16000)\n\n# 5.decode watermark\npayload_decoded, _ = wavmark.decode_watermark(model, watermarked_signal, show_progress=True)\nBER = (payload != payload_decoded).mean() * 100\n\nprint(\"Decode BER:%.1f\" % BER)\n```\n\n\n## How it works?\nIn paper [WavMark: Watermarking for Audio Generation](https://arxiv.org/pdf/2308.12770.pdf) we proposed the WavMark model,\nwhich enables encoding 32 bits of information into 1-second audio.\nIn this tool, we take the first 16 bits as a fixed pattern for watermark identification and the remaining 16 bits as a custom payload.\nThe same watermark is added repetitively to ensure full-time region protection:\n![Illustrate](data/imgs/structure.png)\n\nSince the pattern length is 16, the probability of \"mistakenly identifying an unwatermarked audio as watermarked\" is only  `1/(2^16)=0.000015`.\n\n\n\n## Low-level Access\nFor a specific watermarking algorithm, there exists a trade-off among capacity, robustness, and imperceptibility. \nTherefore, a watermarking system often needs customization according to application requirements.\nThe good news is that WavMark is entirely implemented with PyTorch. \nHere is an example of directly calling the PyTorch model:\n\n```python\n# 1.load model\ndevice = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')\nmodel = wavmark.load_model().to(device)\n\n# 2. take 16,000 samples\nsignal, sample_rate = soundfile.read(\"example.wav\")\ntrunck = signal[0:16000]\nmessage_npy = np.random.choice([0, 1], size=32)\n\n# 3. do encode:\nwith torch.no_grad():\n    signal = torch.FloatTensor(trunck).to(device)[None]\n    message_tensor = torch.FloatTensor(message_npy).to(device)[None]\n    signal_wmd_tensor = model.encode(signal, message_tensor)\n    signal_wmd_npy = signal_wmd_tensor.detach().cpu().numpy().squeeze()\n\n# 4.do decode:\nwith torch.no_grad():\n    signal = torch.FloatTensor(signal_wmd_npy).to(device).unsqueeze(0)\n    message_decoded_npy = (model.decode(signal) >= 0.5).int().detach().cpu().numpy().squeeze()\n\nBER = (message_npy != message_decoded_npy).mean() * 100\nprint(\"BER:\", BER)\n```\n\n\n\n\n\n## Thanks\nThe \"[Audiowmark](https://uplex.de/audiowmark)\" developed by Stefan Westerfeld has provided valuable ideas for the design of this project.\n## Citation\n```\n@misc{chen2023wavmark,\n      title={WavMark: Watermarking for Audio Generation}, \n      author={Guangyu Chen and Yu Wu and Shujie Liu and Tao Liu and Xiaoyong Du and Furu Wei},\n      year={2023},\n      eprint={2308.12770},\n      archivePrefix={arXiv},\n      primaryClass={cs.SD}\n}\n```\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "AI-Based Audio Watermarking Tool",
    "version": "0.0.3",
    "project_urls": {
        "Bug Tracker": "https://github.com/wavmark/wavmark/issues",
        "Homepage": "https://github.com/wavmark/wavmark"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "46ddb929dff997313091c60a93df26b82f400267c17a425bd1b4666f1761ad34",
                "md5": "f1cbebe8320d986f17c1862b57cdd506",
                "sha256": "f77c7234e66b6983273fa7bd7509acaa9195cd936fd1c178b46c8e996d7e8f02"
            },
            "downloads": -1,
            "filename": "wavmark-0.0.3-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f1cbebe8320d986f17c1862b57cdd506",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 13921,
            "upload_time": "2024-01-07T07:46:07",
            "upload_time_iso_8601": "2024-01-07T07:46:07.487708Z",
            "url": "https://files.pythonhosted.org/packages/46/dd/b929dff997313091c60a93df26b82f400267c17a425bd1b4666f1761ad34/wavmark-0.0.3-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "264631acbe081fe7822a26af90e7e9f2160daa01bcf78cc94b2f46132c9b9adc",
                "md5": "4670d23289e385b43958ccf499130a38",
                "sha256": "64e5773d7c1bf07d31fe92375fa921f6e5c511a560a8a523c449626adcdeaa0f"
            },
            "downloads": -1,
            "filename": "wavmark-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "4670d23289e385b43958ccf499130a38",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 564521,
            "upload_time": "2024-01-07T07:46:10",
            "upload_time_iso_8601": "2024-01-07T07:46:10.273026Z",
            "url": "https://files.pythonhosted.org/packages/26/46/31acbe081fe7822a26af90e7e9f2160daa01bcf78cc94b2f46132c9b9adc/wavmark-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-07 07:46:10",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "wavmark",
    "github_project": "wavmark",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "wavmark"
}
        
Elapsed time: 0.35087s