跳转到主要内容

语音音频的水印和检测

项目描述

:loud_sound: AudioSeal: 主动本地化水印

Python Code style: black

AudioSeal语音本地化水印方法的推理代码,具有最先进的鲁棒性和检测器速度(训练代码即将推出)。更多详情请参阅论文

[arXiv] [Colab笔记本][🤗Hugging Face]

fig

更新

  • 2024-06-17: 训练代码现已可用。请查看说明!!!
  • 2024-05-31: 我们的论文被ICML'24接受 :)
  • 2024-04-02: 我们已将许可更新为完整的MIT许可(包括模型权重的许可)!现在您也可以在商业应用中使用AudioSeal!
  • 2024-02-29: AudioSeal 0.1.2已发布,修复了更多关于重采样音频的错误,并更新了笔记本。

摘要

我们介绍AudioSeal,一种语音局部化水印方法,具有最先进的鲁棒性和检测速度。它联合训练了一个将水印嵌入音频的生成器和一个检测更长音频中水印片段的检测器,即使在编辑的情况下也能检测。AudioSeal在样本级别(1/16k秒分辨率)上实现了自然和合成语音的最先进检测性能,它对信号质量的改变有限,并对多种音频编辑具有鲁棒性。AudioSeal采用快速的单次遍历检测器,在速度上显著超过现有模型——检测速度可快两个数量级,使其非常适合大规模和实时应用。

:mate: 安装

AudioSeal需要Python >=3.8,Pytorch >= 1.13.0,omegaconf,julius和numpy。要从PyPI安装

pip install audioseal

从源代码安装:克隆此仓库并使用可编辑模式安装

git clone https://github.com/facebookresearch/audioseal
cd audioseal
pip install -e .

:gear: 模型

您可以在Hugging Face Hub上找到所有模型检查点。我们提供了以下模型的检查点

  • AudioSeal 生成器。它接受音频信号(作为波形)作为输入,并输出与输入大小相同的水印,可以添加到输入中以便进行水印。可选地,它还可以接受16位秘密消息作为输入,该消息将被编码到水印中。
  • AudioSeal 检测器。它接受音频信号(作为波形)作为输入,并在音频的每个样本(每1/16k秒)输出一个概率,表示输入是否包含水印。可选地,它还可以输出编码在水印中的秘密消息。

请注意,消息是可选的,并且对检测输出没有影响。它可以用来标识模型版本等(有$2**16=65536$种可能的选择)。

注意:我们正在努力发布训练代码,以便任何人都可以构建他们自己的水印器。请保持关注!

:abacus: 使用

Audioseal提供了一个简单的API,用于从音频样本中水印和检测水印。示例用法

from audioseal import AudioSeal

# model name corresponds to the YAML card file name found in audioseal/cards
model = AudioSeal.load_generator("audioseal_wm_16bits")

# Other way is to load directly from the checkpoint
# model =  Watermarker.from_pretrained(checkpoint_path, device = wav.device)

# a torch tensor of shape (batch, channels, samples) and a sample rate
# It is important to process the audio to the same sample rate as the model
# expectes. In our case, we support 16khz audio 
wav, sr = ..., 16000

watermark = model.get_watermark(wav, sr)

# Optional: you can add a 16-bit message to embed in the watermark
# msg = torch.randint(0, 2, (wav.shape(0), model.msg_processor.nbits), device=wav.device)
# watermark = model.get_watermark(wav, message = msg)

watermarked_audio = wav + watermark

detector = AudioSeal.load_detector("audioseal_detector_16bits")

# To detect the messages in the high-level.
result, message = detector.detect_watermark(watermarked_audio, sr)

print(result) # result is a float number indicating the probability of the audio being watermarked,
print(message)  # message is a binary vector of 16 bits


# To detect the messages in the low-level.
result, message = detector(watermarked_audio, sr)

# result is a tensor of size batch x 2 x frames, indicating the probability (positive and negative) of watermarking for each frame
# A watermarked audio should have result[:, 1, :] > 0.5
print(result[:, 1 , :])  

# Message is a tensor of size batch x 16, indicating of the probability of each bit to be 1.
# message will be a random tensor if the detector detects no watermarking from the audio
print(message)  

训练您自己的水印模型

有关如何训练您自己的水印模型的详细信息,请参阅此处

想要贡献吗?

我们欢迎包含改进或建议的拉取请求。如果您想标记一个问题或提出改进,但不知道如何实现,请创建一个GitHub问题。

故障排除

  • 如果您遇到错误ValueError: not enough values to unpack (expected 3, got 2),这是因为我们期望一个音频张量批次作为输入。向您的输入添加一个虚拟批次维度(例如wav.unsqueeze(0),见入门示例笔记本)。

  • 在Windows机器上,如果您遇到错误KeyError raised while resolving interpolation: "Environmen variable 'USER' not found":这是由于上传到模型中心的旧检查点不兼容Windows。尝试通过删除C:\Users\\.cache\audioseal中的文件来清除缓存,然后再次运行。

  • 如果您使用torchaudio处理音频并遇到错误Couldn't find appropriate backend to handle uri ...,这是由于torchaudio的新版本没有很好地处理默认后端。要么将torchaudio降级到2.1.0或更早版本,要么安装soundfile作为您的音频后端。

许可

  • 此存储库中的代码根据LICENSE文件中找到的MIT许可证发布。

维护者

引用

如果您觉得这个仓库很有用,请考虑给它点个星 :star: 并引用如下

@article{sanroman2024proactive,
  title={Proactive Detection of Voice Cloning with Localized Watermarking},
  author={San Roman, Robin and Fernandez, Pierre and Elsahar, Hady and D´efossez, Alexandre and Furon, Teddy and Tran, Tuan},
  journal={ICML},
  year={2024}
}

项目详情


下载文件

下载适用于您平台的文件。如果您不确定选择哪个,请了解有关安装包的更多信息。

源代码分发

audioseal-0.1.4.tar.gz (1.9 MB 查看哈希值)

上传时间 源代码

构建分发

audioseal-0.1.4-py3-none-any.whl (21.2 kB 查看哈希值)

上传时间 Python 3

由以下机构支持