[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"similar-declare-lab--tango":3,"tool-declare-lab--tango":61},[4,18,26,36,44,53],{"id":5,"name":6,"github_repo":7,"description_zh":8,"stars":9,"difficulty_score":10,"last_commit_at":11,"category_tags":12,"status":17},4358,"openclaw","openclaw\u002Fopenclaw","OpenClaw 是一款专为个人打造的本地化 AI 助手，旨在让你在自己的设备上拥有完全可控的智能伙伴。它打破了传统 AI 助手局限于特定网页或应用的束缚，能够直接接入你日常使用的各类通讯渠道，包括微信、WhatsApp、Telegram、Discord、iMessage 等数十种平台。无论你在哪个聊天软件中发送消息，OpenClaw 都能即时响应，甚至支持在 macOS、iOS 和 Android 设备上进行语音交互，并提供实时的画布渲染功能供你操控。\n\n这款工具主要解决了用户对数据隐私、响应速度以及“始终在线”体验的需求。通过将 AI 部署在本地，用户无需依赖云端服务即可享受快速、私密的智能辅助，真正实现了“你的数据，你做主”。其独特的技术亮点在于强大的网关架构，将控制平面与核心助手分离，确保跨平台通信的流畅性与扩展性。\n\nOpenClaw 非常适合希望构建个性化工作流的技术爱好者、开发者，以及注重隐私保护且不愿被单一生态绑定的普通用户。只要具备基础的终端操作能力（支持 macOS、Linux 及 Windows WSL2），即可通过简单的命令行引导完成部署。如果你渴望拥有一个懂你",349277,3,"2026-04-06T06:32:30",[13,14,15,16],"Agent","开发框架","图像","数据工具","ready",{"id":19,"name":20,"github_repo":21,"description_zh":22,"stars":23,"difficulty_score":10,"last_commit_at":24,"category_tags":25,"status":17},3808,"stable-diffusion-webui","AUTOMATIC1111\u002Fstable-diffusion-webui","stable-diffusion-webui 是一个基于 Gradio 构建的网页版操作界面，旨在让用户能够轻松地在本地运行和使用强大的 Stable Diffusion 图像生成模型。它解决了原始模型依赖命令行、操作门槛高且功能分散的痛点，将复杂的 AI 绘图流程整合进一个直观易用的图形化平台。\n\n无论是希望快速上手的普通创作者、需要精细控制画面细节的设计师，还是想要深入探索模型潜力的开发者与研究人员，都能从中获益。其核心亮点在于极高的功能丰富度：不仅支持文生图、图生图、局部重绘（Inpainting）和外绘（Outpainting）等基础模式，还独创了注意力机制调整、提示词矩阵、负向提示词以及“高清修复”等高级功能。此外，它内置了 GFPGAN 和 CodeFormer 等人脸修复工具，支持多种神经网络放大算法，并允许用户通过插件系统无限扩展能力。即使是显存有限的设备，stable-diffusion-webui 也提供了相应的优化选项，让高质量的 AI 艺术创作变得触手可及。",162132,"2026-04-05T11:01:52",[14,15,13],{"id":27,"name":28,"github_repo":29,"description_zh":30,"stars":31,"difficulty_score":32,"last_commit_at":33,"category_tags":34,"status":17},1381,"everything-claude-code","affaan-m\u002Feverything-claude-code","everything-claude-code 是一套专为 AI 编程助手（如 Claude Code、Codex、Cursor 等）打造的高性能优化系统。它不仅仅是一组配置文件，而是一个经过长期实战打磨的完整框架，旨在解决 AI 代理在实际开发中面临的效率低下、记忆丢失、安全隐患及缺乏持续学习能力等核心痛点。\n\n通过引入技能模块化、直觉增强、记忆持久化机制以及内置的安全扫描功能，everything-claude-code 能显著提升 AI 在复杂任务中的表现，帮助开发者构建更稳定、更智能的生产级 AI 代理。其独特的“研究优先”开发理念和针对 Token 消耗的优化策略，使得模型响应更快、成本更低，同时有效防御潜在的攻击向量。\n\n这套工具特别适合软件开发者、AI 研究人员以及希望深度定制 AI 工作流的技术团队使用。无论您是在构建大型代码库，还是需要 AI 协助进行安全审计与自动化测试，everything-claude-code 都能提供强大的底层支持。作为一个曾荣获 Anthropic 黑客大奖的开源项目，它融合了多语言支持与丰富的实战钩子（hooks），让 AI 真正成长为懂上",157379,2,"2026-04-15T23:32:42",[14,13,35],"语言模型",{"id":37,"name":38,"github_repo":39,"description_zh":40,"stars":41,"difficulty_score":32,"last_commit_at":42,"category_tags":43,"status":17},2271,"ComfyUI","Comfy-Org\u002FComfyUI","ComfyUI 是一款功能强大且高度模块化的视觉 AI 引擎，专为设计和执行复杂的 Stable Diffusion 图像生成流程而打造。它摒弃了传统的代码编写模式，采用直观的节点式流程图界面，让用户通过连接不同的功能模块即可构建个性化的生成管线。\n\n这一设计巧妙解决了高级 AI 绘图工作流配置复杂、灵活性不足的痛点。用户无需具备编程背景，也能自由组合模型、调整参数并实时预览效果，轻松实现从基础文生图到多步骤高清修复等各类复杂任务。ComfyUI 拥有极佳的兼容性，不仅支持 Windows、macOS 和 Linux 全平台，还广泛适配 NVIDIA、AMD、Intel 及苹果 Silicon 等多种硬件架构，并率先支持 SDXL、Flux、SD3 等前沿模型。\n\n无论是希望深入探索算法潜力的研究人员和开发者，还是追求极致创作自由度的设计师与资深 AI 绘画爱好者，ComfyUI 都能提供强大的支持。其独特的模块化架构允许社区不断扩展新功能，使其成为当前最灵活、生态最丰富的开源扩散模型工具之一，帮助用户将创意高效转化为现实。",108322,"2026-04-10T11:39:34",[14,15,13],{"id":45,"name":46,"github_repo":47,"description_zh":48,"stars":49,"difficulty_score":32,"last_commit_at":50,"category_tags":51,"status":17},6121,"gemini-cli","google-gemini\u002Fgemini-cli","gemini-cli 是一款由谷歌推出的开源 AI 命令行工具，它将强大的 Gemini 大模型能力直接集成到用户的终端环境中。对于习惯在命令行工作的开发者而言，它提供了一条从输入提示词到获取模型响应的最短路径，无需切换窗口即可享受智能辅助。\n\n这款工具主要解决了开发过程中频繁上下文切换的痛点，让用户能在熟悉的终端界面内直接完成代码理解、生成、调试以及自动化运维任务。无论是查询大型代码库、根据草图生成应用，还是执行复杂的 Git 操作，gemini-cli 都能通过自然语言指令高效处理。\n\n它特别适合广大软件工程师、DevOps 人员及技术研究人员使用。其核心亮点包括支持高达 100 万 token 的超长上下文窗口，具备出色的逻辑推理能力；内置 Google 搜索、文件操作及 Shell 命令执行等实用工具；更独特的是，它支持 MCP（模型上下文协议），允许用户灵活扩展自定义集成，连接如图像生成等外部能力。此外，个人谷歌账号即可享受免费的额度支持，且项目基于 Apache 2.0 协议完全开源，是提升终端工作效率的理想助手。",100752,"2026-04-10T01:20:03",[52,13,15,14],"插件",{"id":54,"name":55,"github_repo":56,"description_zh":57,"stars":58,"difficulty_score":10,"last_commit_at":59,"category_tags":60,"status":17},4487,"LLMs-from-scratch","rasbt\u002FLLMs-from-scratch","LLMs-from-scratch 是一个基于 PyTorch 的开源教育项目，旨在引导用户从零开始一步步构建一个类似 ChatGPT 的大型语言模型（LLM）。它不仅是同名技术著作的官方代码库，更提供了一套完整的实践方案，涵盖模型开发、预训练及微调的全过程。\n\n该项目主要解决了大模型领域“黑盒化”的学习痛点。许多开发者虽能调用现成模型，却难以深入理解其内部架构与训练机制。通过亲手编写每一行核心代码，用户能够透彻掌握 Transformer 架构、注意力机制等关键原理，从而真正理解大模型是如何“思考”的。此外，项目还包含了加载大型预训练权重进行微调的代码，帮助用户将理论知识延伸至实际应用。\n\nLLMs-from-scratch 特别适合希望深入底层原理的 AI 开发者、研究人员以及计算机专业的学生。对于不满足于仅使用 API，而是渴望探究模型构建细节的技术人员而言，这是极佳的学习资源。其独特的技术亮点在于“循序渐进”的教学设计：将复杂的系统工程拆解为清晰的步骤，配合详细的图表与示例，让构建一个虽小但功能完备的大模型变得触手可及。无论你是想夯实理论基础，还是为未来研发更大规模的模型做准备",90106,"2026-04-06T11:19:32",[35,15,13,14],{"id":62,"github_repo":63,"name":64,"description_en":65,"description_zh":66,"ai_summary_zh":66,"readme_en":67,"readme_zh":68,"quickstart_zh":69,"use_case_zh":70,"hero_image_url":71,"owner_login":72,"owner_name":73,"owner_avatar_url":74,"owner_bio":75,"owner_company":76,"owner_location":76,"owner_email":76,"owner_twitter":76,"owner_website":77,"owner_url":78,"languages":79,"stars":103,"forks":104,"last_commit_at":105,"license":106,"difficulty_score":10,"env_os":107,"env_gpu":108,"env_ram":109,"env_deps":110,"category_tags":120,"github_topics":122,"view_count":32,"oss_zip_url":76,"oss_zip_packed_at":76,"status":17,"created_at":129,"updated_at":130,"faqs":131,"releases":166},7940,"declare-lab\u002Ftango","tango","A family of diffusion models for text-to-audio generation.","Tango 是一个基于扩散模型的开源项目，专为“文生音频”任务设计。它能将简单的文字描述转化为逼真的声音，涵盖人声、动物叫声、自然环境音、机械声以及各种音效，甚至支持音乐生成。\n\n针对传统音频生成模型往往需要海量数据训练且输出不够自然的问题，Tango 创新性地结合了冻结指令的大语言模型（Flan-T5）作为文本编码器，与基于 UNet 的扩散模型协同工作。这一架构使其仅用相当于同类最先进模型六十三分之一的数据量，就能在客观和主观评估中达到顶尖水平。其升级版 Tango 2 进一步引入了基于人类反馈的直接偏好优化（DPO）技术，利用 Audio-Alpaca 数据集进行对齐训练，显著提升了生成音频的质量和相关性，实现了更快的推理速度。\n\nTango 非常适合 AI 研究人员探索多模态生成技术，也适合开发者将其集成到应用中进行二次开发。同时，对于游戏设计师、视频创作者等需要快速获取高质量素材的专业人士，Tango 提供了高效的创作辅助能力。项目完全开源，提供了从预训练模型、训练代码到在线演示的完整资源，降低了技术使用门槛，助力社区共同推动音频生成技术的发展。","# Tango: LLM-guided Diffusion-based Text-to-Audio Generation and DPO-based Alignment\n\n🔥If you enjoyed Tango, please check out our latest innovation, Jam, a lyrics-to-song generator: https:\u002F\u002Fgithub.com\u002Fdeclare-lab\u002Fjamify\n\n🔥🎤 We have released TangoFlux, the new SOTA in text-to-audio generation. Now you can generate 30 seconds of audio in less than 3 seconds. [Please visit the Github](https:\u002F\u002Fgithub.com\u002Fdeclare-lab\u002FTangoFlux).\n\n\u003Cp align=\"center\">\n      \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdeclare-lab_tango_readme_674003a49f5b.png\" alt=\"Tango 2\" width= \"80%\" class=\"center\" >\n      \n[Tango 2 Paper](https:\u002F\u002Farxiv.org\u002Fabs\u002F2404.09956) | [Tango 2 Model](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango2) | [Tango 2 Demo](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002Fdeclare-lab\u002Ftango2)  | [Tango 2 Replicate Demo](https:\u002F\u002Freplicate.com\u002Fdeclare-lab\u002Ftango) | [Audio-Alpaca](https:\u002F\u002Fhuggingface.co\u002Fdatasets\u002Fdeclare-lab\u002Faudio-alpaca) | [Tango 2 Website](https:\u002F\u002Ftango2-web.github.io\u002F)  \n[Tango Paper](https:\u002F\u002Farxiv.org\u002Fpdf\u002F2304.13731.pdf) | [Tango Model](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango) | [Tango Demo](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002Fdeclare-lab\u002Ftango) | [Tango Website](https:\u002F\u002Ftango-web.github.io\u002F) \n\n\u003C\u002Fp>\n\n## Quickstart on Google Colab\n\n| Colab | Info\n| --- | --- |\n[![Open In Colab](https:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg)](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fsaravananbcs\u002Ftango-demo-colab\u002Fblob\u002Fmaster\u002FTango_2_Google_Colab_demo.ipynb) | [Tango_2_Google_Colab_demo.ipynb](https:\u002F\u002Fgithub.com\u002Fdeclare-lab\u002Ftango\u002Fblob\u002Fmaster\u002FTango_Google_Colab_demo.ipynb)\n\n\n\n## Tango Model Family\n\n| Model Name                 | Model Path                                       |\n|----------------------------|-------------------------------------------------|\n| Tango                      | [https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango)                               |\n| Tango-Full-FT-Audiocaps    | [https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango-full-ft-audiocaps](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango-full-ft-audiocaps) |\nTango-Full-FT-Audio-Music-Caps | [https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango-full-ft-audio-music-caps](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango-full-ft-audio-music-caps) |\n| Mustango | [https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Fmustango](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Fmustango) |\n| Tango-Full | [https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango-full](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango-full) |\n| Tango-2    | [https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango2](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango2)|\n| Tango-2-full| [https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango2-full](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango2-full)|\n| Tango-AF-AC-FT-AC| [https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango-af-ac-ft-ac](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango-af-ac-ft-ac)|\n| TangoMusic-AF-FT-MC| [https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango-music-af-ft-mc](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango-music-af-ft-mc)|\n\n## Description\n\n**TANGO** is a latent diffusion model (LDM) for text-to-audio (TTA) generation. **TANGO** can generate realistic audios including human sounds, animal sounds, natural and artificial sounds and sound effects from textual prompts. We use the frozen instruction-tuned LLM Flan-T5 as the text encoder and train a UNet based diffusion model for audio generation. We perform comparably to current state-of-the-art models for TTA across both objective and subjective metrics, despite training the LDM on a 63 times smaller dataset. We release our model, training, inference code, and pre-trained checkpoints for the research community.\n\n\u003Cp align=\"center\">\n  \u003Cimg src=img\u002Ftango.png \u002F>\n\u003C\u002Fp>\n\n🎵 🔥 We are releasing Tango 2 built upon Tango for text-to-audio generation. Tango 2 was initialized with the Tango-full-ft checkpoint and underwent alignment training using DPO on audio-alpaca, a pairwise text-to-audio preference dataset. 🎶\n\n\u003Cp align=\"center\">\n  \u003Cimg src=img\u002Ftango2-framework.png width=80%\u002F>\n\u003C\u002Fp>\n\n🎵 🔥 We are also making **Audio-alpaca** available. **Audio-alpaca** is a pairwise preference dataset containing about 15k (prompt,audio_w, audio_l) triplets where given a textual prompt, audio_w is the preferred generated audio and audio_l is the undesirable audio. [Download Audio-alpaca](https:\u002F\u002Fhuggingface.co\u002Fdatasets\u002Fdeclare-lab\u002Faudio-alpaca). **Tango 2** was trained on **Audio-alpaca**.\n\n## Quickstart Guide\n\nDownload the **TANGO** model and generate audio from a text prompt:\n\n```python\nimport IPython\nimport soundfile as sf\nfrom tango import Tango\n\ntango = Tango(\"declare-lab\u002Ftango2\")\n\nprompt = \"An audience cheering and clapping\"\naudio = tango.generate(prompt)\nsf.write(f\"{prompt}.wav\", audio, samplerate=16000)\nIPython.display.Audio(data=audio, rate=16000)\n```\n[CheerClap.webm](https:\u002F\u002Fuser-images.githubusercontent.com\u002F13917097\u002F233851915-e702524d-cd35-43f7-93e0-86ea579231a7.webm)\n\nThe model will be automatically downloaded and saved in cache. Subsequent runs will load the model directly from cache.\n\nThe `generate` function uses 100 steps by default to sample from the latent diffusion model. We recommend using 200 steps for generating better quality audios. This comes at the cost of increased run-time.\n\n```python\nprompt = \"Rolling thunder with lightning strikes\"\naudio = tango.generate(prompt, steps=200)\nIPython.display.Audio(data=audio, rate=16000)\n```\n[Thunder.webm](https:\u002F\u002Fuser-images.githubusercontent.com\u002F13917097\u002F233851929-90501e41-911d-453f-a00b-b215743365b4.webm)\n\n\u003C!-- [MachineClicking](https:\u002F\u002Fuser-images.githubusercontent.com\u002F25340239\u002F233857834-bfda52b4-4fcc-48de-b47a-6a6ddcb3671b.mp4 \"sample 1\") -->\n\nUse the `generate_for_batch` function to generate multiple audio samples for a batch of text prompts:\n\n```python\nprompts = [\n    \"A car engine revving\",\n    \"A dog barks and rustles with some clicking\",\n    \"Water flowing and trickling\"\n]\naudios = tango.generate_for_batch(prompts, samples=2)\n```\nThis will generate two samples for each of the three text prompts.\n\nMore generated samples are shown [here](https:\u002F\u002Fgithub.com\u002Fdeclare-lab\u002Ftango\u002Fblob\u002Fmaster\u002Fsamples\u002FREADME.md).\n\n## Prerequisites\n\nOur code is built on pytorch version 1.13.1+cu117. We mention `torch==1.13.1` in the requirements file but you might need to install a specific cuda version of torch depending on your GPU device type.\n\nInstall `requirements.txt`.\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fdeclare-lab\u002Ftango\u002F\ncd tango\npip install -r requirements.txt\n```\n\nYou might also need to install `libsndfile1` for soundfile to work properly in linux:\n\n```bash\n(sudo) apt-get install libsndfile1\n```\n\n## Datasets\n\nFollow the instructions given in the [AudioCaps repository](https:\u002F\u002Fgithub.com\u002Fcdjkim\u002Faudiocaps) for downloading the data. The audio locations and corresponding captions are provided in our `data` directory. The `*.json` files are used for training and evaluation. Once you have downloaded your version of the data you should be able to map it using the file ids to the file locations provided in our `data\u002F*.json` files.\n\nNote that we cannot distribute the data because of copyright issues.\n\n🎵 🔥 We are also making **Audio-alpaca** available. **Audio-alpaca** is a pairwise preference dataset containing about 15k (prompt,audio_w, audio_l) triplets where given a textual prompt, audio_w is the preferred generated audio and audio_l is the undesirable audio. [Download Audio-alpaca](https:\u002F\u002Fhuggingface.co\u002Fdatasets\u002Fdeclare-lab\u002Faudio-alpaca). **Tango 2** was trained on **Audio-alpaca**.\n\n## How to train?\nWe use the `accelerate` package from Hugging Face for multi-gpu training. Run `accelerate config` from terminal and set up your run configuration by the answering the questions asked.\n\nYou can now train **TANGO** on the AudioCaps dataset using:\n\n```bash\naccelerate launch train.py \\\n--text_encoder_name=\"google\u002Fflan-t5-large\" \\\n--scheduler_name=\"stabilityai\u002Fstable-diffusion-2-1\" \\\n--unet_model_config=\"configs\u002Fdiffusion_model_config.json\" \\\n--freeze_text_encoder --augment --snr_gamma 5 \\\n```\n\nThe argument `--augment` uses augmented data for training as reported in our paper. We recommend training for at-least 40 epochs, which is the default in `train.py`.\n\nTo start training from our released checkpoint use the `--hf_model` argument.\n\n```bash\naccelerate launch train.py \\\n--hf_model \"declare-lab\u002Ftango\" \\\n--unet_model_config=\"configs\u002Fdiffusion_model_config.json\" \\\n--freeze_text_encoder --augment --snr_gamma 5 \\\n```\n\nCheck `train.py` and `train.sh` for the full list of arguments and how to use them.\n\nThe training script should automatically download the AudioLDM weights from [here](https:\u002F\u002Fzenodo.org\u002Frecord\u002F7600541\u002Ffiles\u002Faudioldm-s-full?download=1). However if the download is slow or if you face any other issues then you can: i) download the `audioldm-s-full` file from [here](https:\u002F\u002Fhuggingface.co\u002Fhaoheliu\u002FAudioLDM-S-Full\u002Ftree\u002Fmain), ii) rename it to `audioldm-s-full.ckpt`, and iii) keep it in `\u002Fhome\u002Fuser\u002F.cache\u002Faudioldm\u002F` direcrtory.\n\nTo train **TANGO 2** on the Audio-alpaca dataset from **TANGO** checkpoint using:\nThe training script will download audio_alpaca wav files and save it in {PATH_TO_DOWNLOAD_WAV_FILE}\u002Faudio_alpaca. Default location will be ~\u002F.cache\u002Fhuggingface\u002Fdatasets.\n```bash\naccelerate launch  tango2\u002Ftango2-train.py --hf_model \"declare-lab\u002Ftango-full-ft-audiocaps\" \\\n--unet_model_config=\"configs\u002Fdiffusion_model_config.json\" \\\n--freeze_text_encoder  \\\n--learning_rate=9.6e-7 \\\n--num_train_epochs=5  \\\n--num_warmup_steps=200 \\\n--per_device_train_batch_size=4 \\\n--per_device_eval_batch_size=4  \\\n--gradient_accumulation_steps=4 \\\n--beta_dpo=2000  \\\n--sft_first_epochs=1 \\\n--dataset_dir={PATH_TO_DOWNLOAD_WAV_FILE}\n```\n\n\n## How to make inferences?\n\n### From your trained checkpoints\n\nCheckpoints from training will be saved in the `saved\u002F*\u002F` directory.\n\nTo perform audio generation and objective evaluation in AudioCaps test set from your trained checkpoint:\n\n```bash\nCUDA_VISIBLE_DEVICES=0 python inference.py \\\n--original_args=\"saved\u002F*\u002Fsummary.jsonl\" \\\n--model=\"saved\u002F*\u002Fbest\u002Fpytorch_model_2.bin\" \\\n```\n\nCheck `inference.py` and `inference.sh` for the full list of arguments and how to use them.\n\nTo perform audio generation and objective evaluation in AudioCaps test set for **TANGO 2** :\n\n```bash\nCUDA_VISIBLE_DEVICES=0 python tango2\u002Finference.py \\\n--original_args=\"saved\u002F*\u002Fsummary.jsonl\" \\\n--model=\"saved\u002F*\u002Fbest\u002Fpytorch_model_2.bin\" \\\n```\nNote that **TANGO 2** inference.py script is different from **TANGO** .\n\n### From our released checkpoints in Hugging Face Hub\n\nTo perform audio generation and objective evaluation in AudioCaps test set from our huggingface checkpoints:\n\n```bash\npython inference_hf.py --checkpoint=\"declare-lab\u002Ftango\"\n```\n\n### Note\n\nWe use functionalities from `audioldm_eval` for objective evalution in `inference.py`. It requires the gold reference audio files and generated audio files to have the same name. You need to create the directory `data\u002Faudiocaps_test_references\u002Fsubset` and keep the reference audio files there. The files should have names as following: `output_0.wav`, `output_1.wav` and so on. The indices should correspond to the corresponding line indices in `data\u002Ftest_audiocaps_subset.json`.\n\nWe use the term _subset_ as some data instances originally released in AudioCaps have since been removed from YouTube and are no longer available. We thus evaluated our models on all the instances which were available as of 8th April, 2023.\n\nWe use wandb to log training and infernce results.\n\n## Experimental Results\n\n### Tango\n\n|           **Model**            |  **Datasets**  | **Text** | **#Params** |         FD ↓          |   KL ↓   |  FAD ↓   |         OVL ↑          |   REL ↑   |\n|:------------------------------:|:--------------:|:--------:|:-----------:|:---------------------:|:--------:|:--------:|:----------------------:|:---------:|\n|          Ground truth          |       −        |    −     |      −      |           −           |    −     |    −     |         91.61          |   86.78   |\n|                                |                |          |             |                       |          |          |                        |           |\n|           DiffSound            |     AS+AC      |    ✓     |    400M     |         47.68         |   2.52   |   7.75   |           −            |     −     |\n|           AudioGen             | AS+AC+8 others |    ✗     |    285M     |           −           |   2.09   |   3.13   |           −            |     −     |\n|           AudioLDM-S           |       AC       |    ✗     |    181M     |         29.48         |   1.97   |   2.43   |           −            |     −     |\n|           AudioLDM-L           |       AC       |    ✗     |    739M     |         27.12         |   1.86   |   2.08   |           −            |     −     |\n|                                |                |          |             |                       |          |          |                        |           |\n| AudioLDM-M-Full-FT\u003Csup>‡\u003C\u002Fsup> | AS+AC+2 others |    ✗     |    416M     |         26.12         | **1.26** |   2.57   |         79.85          |   76.84   |\n|  AudioLDM-L-Full\u003Csup>‡\u003C\u002Fsup>   | AS+AC+2 others |    ✗     |    739M     |         32.46         |   1.76   |   4.18   |         78.63          |   62.69   |\n|       AudioLDM-L-Full-FT       | AS+AC+2 others |    ✗     |    739M     |       **23.31**       |   1.59   |   1.96   |           −            |     −     |\n|                                |                |          |             |                       |          |          |                        |           |\n|              TANGO             |       AC       |    ✓     |    866M     |         24.52         |   1.37   | **1.59** |       **85.94**        | **80.36** |\n\n### Tango 2\n\n| Model                | Parameters | FAD ↓     | KL ↓      | IS ↑      | CLAP ↑    | OVL ↑      | REL ↑      |\n|----------------------|------------|-----------|-----------|-----------|-----------|------------|------------|\n| AudioLDM-M-Full-FT   | 416M       | 2.57      | 1.26      | 8.34      | 0.43      | -          | -          |\n| AudioLDM-L-Full      | 739M       | 4.18      | 1.76      | 7.76      | 0.43      | -          | -          |\n| AudioLDM 2-Full      | 346M       | **2.18**  | 1.62      | 6.92      | 0.43      | -          | -          |\n| AudioLDM 2-Full-Large| 712M       | **2.11**  | 1.54      | 8.29      | 0.44      | 3.56       | 3.19       |\n| Tango-full-FT        | 866M       | 2.51      | 1.15      | 7.87      | 0.54      | 3.81       | 3.77       |\n| Tango 2              | 866M       | 2.69      | **1.12**  | **9.09**  | **0.57**  | **3.99**   | **4.07**   |\n\n\n## Citation\nPlease consider citing the following articles if you found our work useful:\n\n```bibtex\n@misc{majumder2024tango,\n      title={Tango 2: Aligning Diffusion-based Text-to-Audio Generations through Direct Preference Optimization}, \n      author={Navonil Majumder and Chia-Yu Hung and Deepanway Ghosal and Wei-Ning Hsu and Rada Mihalcea and Soujanya Poria},\n      year={2024},\n      eprint={2404.09956},\n      archivePrefix={arXiv},\n      primaryClass={cs.SD}\n}\n@article{ghosal2023tango,\n  title={Text-to-Audio Generation using Instruction Tuned LLM and Latent Diffusion Model},\n  author={Ghosal, Deepanway and Majumder, Navonil and Mehrish, Ambuj and Poria, Soujanya},\n  journal={arXiv preprint arXiv:2304.13731},\n  year={2023}\n}\n```\n\n## Acknowledgement\nWe borrow the code in `audioldm` and `audioldm_eval` from the [AudioLDM](https:\u002F\u002Fgithub.com\u002Fhaoheliu\u002FAudioLDM) [repositories](https:\u002F\u002Fgithub.com\u002Fhaoheliu\u002Faudioldm_eval). We thank the AudioLDM team for open-sourcing their code.\n","# Tango：LLM引导的扩散模型文生音频及基于DPO的对齐\n\n🔥如果你喜欢Tango，请查看我们的最新创新Jam，一款歌词转歌曲生成器：https:\u002F\u002Fgithub.com\u002Fdeclare-lab\u002Fjamify\n\n🔥🎤 我们发布了TangoFlux，这是文生音频领域的最新SOTA。现在你可以在不到3秒内生成30秒的音频。[请访问Github](https:\u002F\u002Fgithub.com\u002Fdeclare-lab\u002FTangoFlux)。\n\n\u003Cp align=\"center\">\n      \u003Cimg src=\"https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdeclare-lab_tango_readme_674003a49f5b.png\" alt=\"Tango 2\" width= \"80%\" class=\"center\" >\n      \n[Tango 2论文](https:\u002F\u002Farxiv.org\u002Fabs\u002F2404.09956) | [Tango 2模型](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango2) | [Tango 2演示](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002Fdeclare-lab\u002Ftango2)  | [Tango 2 Replicate演示](https:\u002F\u002Freplicate.com\u002Fdeclare-lab\u002Ftango) | [Audio-Alpaca](https:\u002F\u002Fhuggingface.co\u002Fdatasets\u002Fdeclare-lab\u002Faudio-alpaca) | [Tango 2官网](https:\u002F\u002Ftango2-web.github.io\u002F)  \n[Tango论文](https:\u002F\u002Farxiv.org\u002Fpdf\u002F2304.13731.pdf) | [Tango模型](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango) | [Tango演示](https:\u002F\u002Fhuggingface.co\u002Fspaces\u002Fdeclare-lab\u002Ftango) | [Tango官网](https:\u002F\u002Ftango-web.github.io\u002F) \n\n\u003C\u002Fp>\n\n## Google Colab快速入门\n\n| Colab | 信息\n| --- | --- |\n[![在Colab中打开](https:\u002F\u002Fcolab.research.google.com\u002Fassets\u002Fcolab-badge.svg)](https:\u002F\u002Fcolab.research.google.com\u002Fgithub\u002Fsaravananbcs\u002Ftango-demo-colab\u002Fblob\u002Fmaster\u002FTango_2_Google_Colab_demo.ipynb) | [Tango_2_Google_Colab_demo.ipynb](https:\u002F\u002Fgithub.com\u002Fdeclare-lab\u002Ftango\u002Fblob\u002Fmaster\u002FTango_Google_Colab_demo.ipynb)\n\n\n\n## Tango模型家族\n\n| 模型名称                 | 模型路径                                       |\n|----------------------------|-------------------------------------------------|\n| Tango                      | [https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango)                               |\n| Tango-Full-FT-Audiocaps    | [https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango-full-ft-audiocaps](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango-full-ft-audiocaps) |\nTango-Full-FT-Audio-Music-Caps | [https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango-full-ft-audio-music-caps](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango-full-ft-audio-music-caps) |\n| Mustango | [https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Fmustango](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Fmustango) |\n| Tango-Full | [https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango-full](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango-full) |\n| Tango-2    | [https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango2](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango2)|\n| Tango-2-full| [https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango2-full](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango2-full)|\n| Tango-AF-AC-FT-AC| [https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango-af-ac-ft-ac](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango-af-ac-ft-ac)|\n| TangoMusic-AF-FT-MC| [https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango-music-af-ft-mc](https:\u002F\u002Fhuggingface.co\u002Fdeclare-lab\u002Ftango-music-af-ft-mc)|\n\n## 描述\n\n**TANGO** 是一个用于文生音频（TTA）的潜在扩散模型（LDM）。**TANGO** 可以根据文本提示生成逼真的音频，包括人声、动物声音、自然和人造声音以及音效。我们使用冻结的指令微调LLM Flan-T5作为文本编码器，并训练了一个基于UNet的扩散模型来进行音频生成。尽管我们在一个规模小63倍的数据集上训练了LDM，但在客观和主观指标上，我们的表现与当前最先进的TTA模型相当。我们向研究社区开放了我们的模型、训练和推理代码以及预训练检查点。\n\n\u003Cp align=\"center\">\n  \u003Cimg src=img\u002Ftango.png \u002F>\n\u003C\u002Fp>\n\n🎵 🔥 我们发布了基于Tango构建的Tango 2，用于文生音频。Tango 2以Tango-full-ft检查点为初始状态，并在audio-alpaca这一成对文生音频偏好数据集上使用DPO进行了对齐训练。🎶\n\n\u003Cp align=\"center\">\n  \u003Cimg src=img\u002Ftango2-framework.png width=80%\u002F>\n\u003C\u002Fp>\n\n🎵 🔥 我们还发布了**Audio-alpaca**。**Audio-alpaca** 是一个成对偏好数据集，包含约1.5万个（提示,音频_w, 音频_l）三元组，其中给定一个文本提示，音频_w是更受欢迎的生成音频，而音频_l则是不理想的音频。[下载Audio-alpaca](https:\u002F\u002Fhuggingface.co\u002Fdatasets\u002Fdeclare-lab\u002Faudio-alpaca)。**Tango 2** 就是在**Audio-alpaca** 上进行训练的。\n\n## 快速入门指南\n\n下载**TANGO**模型，并根据文本提示生成音频：\n\n```python\nimport IPython\nimport soundfile as sf\nfrom tango import Tango\n\ntango = Tango(\"declare-lab\u002Ftango2\")\n\nprompt = \"观众欢呼鼓掌\"\naudio = tango.generate(prompt)\nsf.write(f\"{prompt}.wav\", audio, samplerate=16000)\nIPython.display.Audio(data=audio, rate=16000)\n```\n[CheerClap.webm](https:\u002F\u002Fuser-images.githubusercontent.com\u002F13917097\u002F233851915-e702524d-cd35-43f7-93e0-86ea579231a7.webm)\n\n模型会自动下载并保存在缓存中。后续运行将直接从缓存加载模型。\n\n`generate`函数默认使用100步来从潜在扩散模型中采样。我们建议使用200步以生成更高质量的音频。不过这会增加运行时间。\n\n```python\nprompt = \"雷鸣电闪\"\naudio = tango.generate(prompt, steps=200)\nIPython.display.Audio(data=audio, rate=16000)\n```\n[Thunder.webm](https:\u002F\u002Fuser-images.githubusercontent.com\u002F13917097\u002F233851929-90501e41-911d-453f-a00b-b215743365b4.webm)\n\n\u003C!-- [MachineClicking](https:\u002F\u002Fuser-images.githubusercontent.com\u002F25340239\u002F233857834-bfda52b4-4fcc-48de-b47a-6a6ddcb3671b.mp4 \"sample 1\") -->\n\n使用`generate_for_batch`函数可以为一批文本提示生成多个音频样本：\n\n```python\nprompts = [\n    \"汽车引擎轰鸣\",\n    \"狗吠声伴随着一些咔嗒声\",\n    \"水流潺潺\"\n]\naudios = tango.generate_for_batch(prompts, samples=2)\n```\n这将为三个文本提示中的每一个生成两个样本。\n\n更多生成的样本请见[这里](https:\u002F\u002Fgithub.com\u002Fdeclare-lab\u002Ftango\u002Fblob\u002Fmaster\u002Fsamples\u002FREADME.md)。\n\n## 先决条件\n\n我们的代码基于PyTorch 1.13.1+cu117版本。虽然我们在requirements文件中注明了`torch==1.13.1`，但根据你的GPU设备类型，你可能需要安装特定CUDA版本的PyTorch。\n\n安装`requirements.txt`。\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fdeclare-lab\u002Ftango\u002F\ncd tango\npip install -r requirements.txt\n```\n\n在Linux系统上，你可能还需要安装`libsndfile1`，以便soundfile能够正常工作：\n\n```bash\n(sudo) apt-get install libsndfile1\n```\n\n## 数据集\n\n请按照 [AudioCaps 仓库](https:\u002F\u002Fgithub.com\u002Fcdjkim\u002Faudiocaps) 中的说明下载数据。音频文件路径及对应的字幕描述已提供在我们的 `data` 目录中。`*.json` 文件用于训练和评估。下载完数据后，您应该能够通过文件 ID 将其映射到我们 `data\u002F*.json` 文件中提供的文件路径。\n\n请注意，由于版权问题，我们无法分发这些数据。\n\n🎵 🔥 我们还提供了 **Audio-alpaca** 数据集。**Audio-alpaca** 是一个成对偏好数据集，包含约 1.5 万个 (prompt, audio_w, audio_l) 三元组：给定一个文本提示，audio_w 是更优的生成音频，而 audio_l 则是较差的音频。[下载 Audio-alpaca](https:\u002F\u002Fhuggingface.co\u002Fdatasets\u002Fdeclare-lab\u002Faudio-alpaca)。**Tango 2** 就是在 **Audio-alpaca** 上训练得到的。\n\n## 如何训练？\n我们使用 Hugging Face 的 `accelerate` 包进行多 GPU 训练。在终端运行 `accelerate config`，并根据提示设置您的运行配置。\n\n现在您可以使用以下命令在 AudioCaps 数据集上训练 **TANGO**：\n\n```bash\naccelerate launch train.py \\\n--text_encoder_name=\"google\u002Fflan-t5-large\" \\\n--scheduler_name=\"stabilityai\u002Fstable-diffusion-2-1\" \\\n--unet_model_config=\"configs\u002Fdiffusion_model_config.json\" \\\n--freeze_text_encoder --augment --snr_gamma 5 \\\n```\n\n参数 `--augment` 使用了我们在论文中提到的增强数据进行训练。我们建议至少训练 40 个 epoch，这也是 `train.py` 中的默认设置。\n\n若要从我们发布的检查点开始训练，请使用 `--hf_model` 参数：\n\n```bash\naccelerate launch train.py \\\n--hf_model \"declare-lab\u002Ftango\" \\\n--unet_model_config=\"configs\u002Fdiffusion_model_config.json\" \\\n--freeze_text_encoder --augment --snr_gamma 5 \\\n```\n\n有关完整参数列表及其用法，请参阅 `train.py` 和 `train.sh`。\n\n训练脚本应会自动从 [这里](https:\u002F\u002Fzenodo.org\u002Frecord\u002F7600541\u002Ffiles\u002Faudioldm-s-full?download=1) 下载 AudioLDM 权重。但如果下载速度较慢或遇到其他问题，您可以：i) 从 [这里](https:\u002F\u002Fhuggingface.co\u002Fhaoheliu\u002FAudioLDM-S-Full\u002Ftree\u002Fmain) 下载 `audioldm-s-full` 文件，ii) 将其重命名为 `audioldm-s-full.ckpt`，iii) 存放在 `\u002Fhome\u002Fuser\u002F.cache\u002Faudioldm\u002F` 目录中。\n\n要在 **TANGO** 检查点的基础上，使用 **TANGO 2** 在 Audio-alpaca 数据集上进行训练：\n\n训练脚本将下载 audio_alpaca 的 WAV 文件，并将其保存在 {PATH_TO_DOWNLOAD_WAV_FILE}\u002Faudio_alpaca 目录下。默认位置为 ~\u002F.cache\u002Fhuggingface\u002Fdatasets。\n\n```bash\naccelerate launch tango2\u002Ftango2-train.py --hf_model \"declare-lab\u002Ftango-full-ft-audiocaps\" \\\n--unet_model_config=\"configs\u002Fdiffusion_model_config.json\" \\\n--freeze_text_encoder  \\\n--learning_rate=9.6e-7 \\\n--num_train_epochs=5  \\\n--num_warmup_steps=200 \\\n--per_device_train_batch_size=4 \\\n--per_device_eval_batch_size=4  \\\n--gradient_accumulation_steps=4 \\\n--beta_dpo=2000  \\\n--sft_first_epochs=1 \\\n--dataset_dir={PATH_TO_DOWNLOAD_WAV_FILE}\n```\n\n## 如何进行推理？\n\n### 从您自己训练的检查点\n\n训练得到的检查点将保存在 `saved\u002F*\u002F` 目录中。\n\n要从您训练好的检查点在 AudioCaps 测试集上进行音频生成和客观评估：\n\n```bash\nCUDA_VISIBLE_DEVICES=0 python inference.py \\\n--original_args=\"saved\u002F*\u002Fsummary.jsonl\" \\\n--model=\"saved\u002F*\u002Fbest\u002Fpytorch_model_2.bin\" \\\n```\n\n有关完整参数列表及其用法，请参阅 `inference.py` 和 `inference.sh`。\n\n要对 **TANGO 2** 进行音频生成和客观评估：\n\n```bash\nCUDA_VISIBLE_DEVICES=0 python tango2\u002Finference.py \\\n--original_args=\"saved\u002F*\u002Fsummary.jsonl\" \\\n--model=\"saved\u002F*\u002Fbest\u002Fpytorch_model_2.bin\" \\\n```\n\n请注意，**TANGO 2** 的推理脚本与 **TANGO** 的不同。\n\n### 从我们在 Hugging Face Hub 上发布的检查点\n\n要从我们的 Hugging Face 检查点在 AudioCaps 测试集上进行音频生成和客观评估：\n\n```bash\npython inference_hf.py --checkpoint=\"declare-lab\u002Ftango\"\n```\n\n### 注意事项\n\n我们在 `inference.py` 中使用了 `audioldm_eval` 提供的功能来进行客观评估。该功能要求黄金参考音频文件和生成音频文件具有相同的文件名。您需要创建目录 `data\u002Faudiocaps_test_references\u002Fsubset`，并将参考音频文件放在此处。文件名应如下所示：`output_0.wav`, `output_1.wav` 等等。文件编号应与 `data\u002Ftest_audiocaps_subset.json` 中对应行的索引一致。\n\n我们使用术语 _subset_，是因为 AudioCaps 原始数据集中的一些实例后来已被 YouTube 删除，不再可用。因此，我们仅对截至 2023 年 4 月 8 日仍可获取的数据实例进行了模型评估。\n\n我们使用 WandB 来记录训练和推理结果。\n\n## 实验结果\n\n### Tango\n\n|           **模型**            |  **数据集**  | **文本** | **参数量** |         FD ↓          |   KL ↓   |  FAD ↓   |         OVL ↑          |   REL ↑   |\n|:------------------------------:|:--------------:|:--------:|:-----------:|:---------------------:|:--------:|:--------:|:----------------------:|:---------:|\n|          真实数据          |       −        |    −     |      −      |           −           |    −     |    −     |         91.61          |   86.78   |\n|                                |                |          |             |                       |          |          |                        |           |\n|           DiffSound            |     AS+AC      |    ✓     |    400M     |         47.68         |   2.52   |   7.75   |           −            |     −     |\n|           AudioGen             | AS+AC+8 others |    ✗     |    285M     |           −           |   2.09   |   3.13   |           −            |     −     |\n|           AudioLDM-S           |       AC       |    ✗     |    181M     |         29.48         |   1.97   |   2.43   |           −            |     −     |\n|           AudioLDM-L           |       AC       |    ✗     |    739M     |         27.12         |   1.86   |   2.08   |           −            |     −     |\n|                                |                |          |             |                       |          |          |                        |           |\n| AudioLDM-M-Full-FT\u003Csup>‡\u003C\u002Fsup> | AS+AC+2 others |    ✗     |    416M     |         26.12         | **1.26** |   2.57   |         79.85          |   76.84   |\n|  AudioLDM-L-Full\u003Csup>‡\u003C\u002Fsup>   | AS+AC+2 others |    ✗     |    739M     |         32.46         |   1.76   |   4.18   |         78.63          |   62.69   |\n|       AudioLDM-L-Full-FT       | AS+AC+2 others |    ✗     |    739M     |       **23.31**       |   1.59   |   1.96   |           −            |     −     |\n|                                |                |          |             |                       |          |          |                        |           |\n|              TANGO             |       AC       |    ✓     |    866M     |         24.52         |   1.37   | **1.59** |       **85.94**        | **80.36** |\n\n### Tango 2\n\n| 模型                | 参数量 | FAD ↓     | KL ↓      | IS ↑      | CLAP ↑    | OVL ↑      | REL ↑      |\n|----------------------|------------|-----------|-----------|-----------|-----------|------------|------------|\n| AudioLDM-M-Full-FT   | 416M       | 2.57      | 1.26      | 8.34      | 0.43      | -          | -          |\n| AudioLDM-L-Full      | 739M       | 4.18      | 1.76      | 7.76      | 0.43      | -          | -          |\n| AudioLDM 2-Full      | 346M       | **2.18**  | 1.62      | 6.92      | 0.43      | -          | -          |\n| AudioLDM 2-Full-Large| 712M       | **2.11**  | 1.54      | 8.29      | 0.44      | 3.56       | 3.19       |\n| Tango-full-FT        | 866M       | 2.51      | 1.15      | 7.87      | 0.54      | 3.81       | 3.77       |\n| Tango 2              | 866M       | 2.69      | **1.12**  | **9.09**  | **0.57**  | **3.99**   | **4.07**   |\n\n\n## 引用\n如果您觉得我们的工作有所帮助，请考虑引用以下文章：\n\n```bibtex\n@misc{majumder2024tango,\n      title={Tango 2: 通过直接偏好优化对齐基于扩散的文本到音频生成}, \n      author={Navonil Majumder 和 Chia-Yu Hung、Deepanway Ghosal、Wei-Ning Hsu、Rada Mihalcea 和 Soujanya Poria},\n      year={2024},\n      eprint={2404.09956},\n      archivePrefix={arXiv},\n      primaryClass={cs.SD}\n}\n@article{ghosal2023tango,\n  title={使用指令微调的 LLM 和潜在扩散模型进行文本到音频生成},\n  author={Ghosal, Deepanway 和 Majumder, Navonil 以及 Mehrish, Ambuj 和 Poria, Soujanya},\n  journal={arXiv 预印本 arXiv:2304.13731},\n  year={2023}\n}\n```\n\n## 致谢\n我们借用了 `audioldm` 和 `audioldm_eval` 中的代码，这些代码来自 [AudioLDM](https:\u002F\u002Fgithub.com\u002Fhaoheliu\u002FAudioLDM) 的 [仓库](https:\u002F\u002Fgithub.com\u002Fhaoheliu\u002Faudioldm_eval)。我们感谢 AudioLDM 团队开源他们的代码。","# Tango 快速上手指南\n\nTango 是一个基于潜在扩散模型（LDM）的文本生成音频（Text-to-Audio）开源工具。它利用冻结的指令微调大语言模型（Flan-T5）作为文本编码器，能够根据文本提示生成逼真的人声、动物声、自然声及音效。最新版本的 **Tango 2** 引入了 DPO 对齐训练，进一步提升了生成质量。\n\n## 环境准备\n\n在开始之前，请确保您的开发环境满足以下要求：\n\n*   **操作系统**: Linux (推荐) 或 macOS。Windows 用户建议使用 WSL2。\n*   **Python 版本**: 建议 Python 3.8+。\n*   **PyTorch 版本**: 代码基于 `torch==1.13.1+cu117` 构建。请根据您的 GPU 驱动和 CUDA 版本安装对应的 PyTorch。\n*   **系统依赖**: Linux 用户需要安装 `libsndfile1` 以支持音频文件读写。\n\n```bash\n# Ubuntu\u002FDebian 系统安装音频依赖\nsudo apt-get install libsndfile1\n```\n\n## 安装步骤\n\n1.  **克隆项目仓库**\n\n    ```bash\n    git clone https:\u002F\u002Fgithub.com\u002Fdeclare-lab\u002Ftango\u002F\n    cd tango\n    ```\n\n2.  **安装 Python 依赖**\n\n    推荐使用国内镜像源（如清华源）加速安装过程：\n\n    ```bash\n    pip install -r requirements.txt -i https:\u002F\u002Fpypi.tuna.tsinghua.edu.cn\u002Fsimple\n    ```\n\n    > **注意**：如果 `requirements.txt` 中指定的 PyTorch 版本与您本地的 CUDA 环境不匹配，请先手动安装正确版本的 PyTorch，再安装其他依赖。\n\n## 基本使用\n\n安装完成后，您可以直接通过 Python 代码加载模型并生成音频。模型权重会自动从 Hugging Face 下载并缓存。\n\n### 1. 生成单个音频样本\n\n以下示例演示如何加载 `tango2` 模型，并根据提示词生成音频：\n\n```python\nimport IPython\nimport soundfile as sf\nfrom tango import Tango\n\n# 初始化模型，自动下载 declare-lab\u002Ftango2\ntango = Tango(\"declare-lab\u002Ftango2\")\n\nprompt = \"An audience cheering and clapping\"\n# 默认使用 100 步采样，建议设置为 200 步以获得更高音质（耗时稍长）\naudio = tango.generate(prompt, steps=200)\n\n# 保存为 WAV 文件\nsf.write(f\"{prompt}.wav\", audio, samplerate=16000)\n\n# 在 Jupyter Notebook 中直接播放\nIPython.display.Audio(data=audio, rate=16000)\n```\n\n### 2. 批量生成音频\n\n使用 `generate_for_batch` 函数可以一次性为多个提示词生成音频样本：\n\n```python\nprompts = [\n    \"A car engine revving\",\n    \"A dog barks and rustles with some clicking\",\n    \"Water flowing and trickling\"\n]\n\n# 为每个提示词生成 2 个不同的样本\naudios = tango.generate_for_batch(prompts, samples=2)\n```\n\n### 进阶提示\n*   **采样步数 (`steps`)**: `generate` 函数默认使用 100 步。若对音质有更高要求，可将 `steps` 参数设为 200，但这会增加推理时间。\n*   **模型选择**: 除了 `declare-lab\u002Ftango2`，您还可以尝试 `declare-lab\u002Ftango` 或其他变体（详见项目 README 中的模型列表）。","独立游戏开发者小林正在为一款复古像素风冒险游戏制作音效，需要大量匹配特定场景（如“雨夜中的脚步声”或“机械怪兽的低吼”）的独特音频素材。\n\n### 没有 tango 时\n- **素材库局限**：只能在免费音效网站反复搜索，很难找到完全契合“机械怪兽低吼”这种具体描述的现成文件，往往被迫使用勉强凑合的替代品。\n- **版权风险高**：部分高质量音效需付费购买或标注来源，增加了项目预算和法律合规的排查成本。\n- **定制成本昂贵**：若委托专业拟音师定制，单条音效报价高且沟通修改周期长，严重拖慢开发进度。\n- **风格不统一**：东拼西凑来的音效在音色质感上差异巨大，导致游戏整体听觉体验割裂，缺乏沉浸感。\n\n### 使用 tango 后\n- **精准生成**：直接输入“雨夜中踩在积水石板上的脚步声”等自然语言提示，tango 即可生成高度匹配且细节丰富的专属音效。\n- **零版权负担**：生成的音频由模型原创，开发者可放心将其用于商业项目，无需担心侵权纠纷。\n- **即时迭代**：对生成结果不满意时，只需微调提示词（如增加“更沉闷的回声”），几秒钟内即可获得新版本，极大提升了试错效率。\n- **风格一致性强**：通过控制提示词的语调和技术参数，能批量产出质感统一的音效系列，完美维持游戏的听觉美学。\n\ntango 将原本耗时数周的音效搜集与定制工作压缩至几小时，让小型团队也能以低成本拥有电影级的原创音频资产。","https:\u002F\u002Foss.gittoolsai.com\u002Fimages\u002Fdeclare-lab_tango_4a1ff385.png","declare-lab","Deep Cognition and Language Research (DeCLaRe) Lab","https:\u002F\u002Foss.gittoolsai.com\u002Favatars\u002Fdeclare-lab_27a2ce73.png","",null,"https:\u002F\u002Fdeclare-lab.github.io","https:\u002F\u002Fgithub.com\u002Fdeclare-lab",[80,84,88,92,96,100],{"name":81,"color":82,"percentage":83},"Python","#3572A5",81.7,{"name":85,"color":86,"percentage":87},"Jupyter Notebook","#DA5B0B",11.3,{"name":89,"color":90,"percentage":91},"MDX","#fcb32c",6.9,{"name":93,"color":94,"percentage":95},"Dockerfile","#384d54",0.1,{"name":97,"color":98,"percentage":99},"Makefile","#427819",0,{"name":101,"color":102,"percentage":99},"Shell","#89e051",1232,106,"2026-04-10T06:12:41","NOASSERTION","Linux","需要 NVIDIA GPU，需安装与设备匹配的 CUDA 版本（示例环境为 cu117），具体显存需求未说明","未说明",{"notes":111,"python":109,"dependencies":112},"在 Linux 系统上运行前，必须通过 apt-get 安装 'libsndfile1' 库以支持 soundfile 模块。训练多卡环境需配置 accelerate。模型权重会自动下载并缓存，首次运行需等待下载。推理默认使用 100 步采样，推荐 200 步以获得更好音质但会增加耗时。",[113,114,115,116,117,118,119],"torch==1.13.1","soundfile","accelerate","transformers","diffusers","audioldm_eval","wandb",[15,121,35],"音频",[123,124,125,126,127,128],"audio-generation","diffusion","diffusion-models","language-models","large-language-models","text-to-audio","2026-03-27T02:49:30.150509","2026-04-16T08:17:12.819950",[132,137,142,147,152,157,162],{"id":133,"question_zh":134,"answer_zh":135,"source_url":136},35556,"训练过程中出现 NaN loss（损失值为非数字）如何解决？","这通常是因为使用了不支持半精度（fp16）训练的文本编码器模型（如 `google\u002Fflan-t5-large`）。解决方法是将训练精度改为全精度（fp32）。在配置或训练脚本中禁用 fp16 混合精度训练即可解决该问题。","https:\u002F\u002Fgithub.com\u002Fdeclare-lab\u002Ftango\u002Fissues\u002F17",{"id":138,"question_zh":139,"answer_zh":140,"source_url":141},35555,"在 Windows 上安装时遇到 flash_attn 编译错误或依赖缺失怎么办？","该项目主要基于 PyTorch 1.13.1+cu117 版本开发。如果在 Windows 上安装 `requirements.txt` 失败（特别是 `flash_attn`），请确保使用正确的 PyTorch 版本。对于 CPU 环境或特定 CUDA 版本，可能需要手动指定安装命令，例如：`pip install torch==1.13.1+cu116 torchvision==0.14.1+cu116 torchaudio==0.13.1+cu116 --extra-index-url https:\u002F\u002Fdownload.pytorch.org\u002Fwhl\u002Fcu116`。此外，建议将 numpy 版本固定为 1.23.0 以避免兼容性问题。","https:\u002F\u002Fgithub.com\u002Fdeclare-lab\u002Ftango\u002Fissues\u002F1",{"id":143,"question_zh":144,"answer_zh":145,"source_url":146},35557,"如何在自定义数据集上微调 Tango 2 模型？","微调 Tango 2 不需要从头训练，也不需要运行 `tango2-train.py`（该脚本用于 DPO 训练）。你可以直接加载预训练的 Tango 2 检查点，并使用标准的 `train.py` 脚本在你的新数据集（格式化为 `train.json`）上进行微调。验证集和测试集的 JSON 文件可以替换为你自己的数据，但这不是必须的。注意：Tango 2 是基于 DPO 训练的，但常规微调只需使用监督微调流程。","https:\u002F\u002Fgithub.com\u002Fdeclare-lab\u002Ftango\u002Fissues\u002F50",{"id":148,"question_zh":149,"answer_zh":150,"source_url":151},35558,"运行训练脚本时遇到 'AudioDiffusion' object has no attribute 'device' 错误怎么办？","这是一个代码兼容性问题。解决方法是修改 `train.py` 源代码：将获取设备的代码从 `device = model.device` 更改为 `device = accelerator.device`。此外，请确保在运行训练前已正确执行 `accelerate config` 进行环境配置。","https:\u002F\u002Fgithub.com\u002Fdeclare-lab\u002Ftango\u002Fissues\u002F35",{"id":153,"question_zh":154,"answer_zh":155,"source_url":156},35559,"如何生成短时长（如 1 秒或更短）的音频？默认生成的音频太长。","音频生成长度由训练时的设置决定，无法在推理阶段直接通过参数随意缩短到任意值（如低于 2.5 秒）。若要生成短音频，你需要使用较短时长的音频样本重新训练模型。在 `train.py` 中修改 `duration` 变量（默认为 10 秒），将其设置为所需的秒数，并使用相应长度的数据集进行训练。","https:\u002F\u002Fgithub.com\u002Fdeclare-lab\u002Ftango\u002Fissues\u002F3",{"id":158,"question_zh":159,"answer_zh":160,"source_url":161},35560,"使用 Python 3.12 无法安装要求的 PyTorch 旧版本（如 1.13.1）怎么办？","PyTorch 1.13.1 不支持 Python 3.12。你需要创建一个使用 Python 3.10 的虚拟环境来安装该项目依赖。在 Ubuntu 系统上，可以通过 deadsnakes PPA 安装 Python 3.10，然后创建新的虚拟环境并重新安装所有依赖包。目前不建议尝试使用更新的 PyTorch 版本，除非你愿意自行解决潜在的兼容性代码修改。","https:\u002F\u002Fgithub.com\u002Fdeclare-lab\u002Ftango\u002Fissues\u002F56",{"id":163,"question_zh":164,"answer_zh":165,"source_url":141},35561,"在纯 CPU 环境下运行模型时遇到 CUDA 相关报错如何处理？","如果在没有 GPU 的机器上运行，初始化模型时需明确指定设备为 CPU，例如：`tango = Tango(\"declare-lab\u002Ftango\", \"cpu\")`。同时，由于 CPU 推理速度较慢，建议在调用 `tango.generate()` 时减少生成步数（steps），默认值为 100 步，适当降低可以显著缩短等待时间。此外，确保安装了与 CPU 兼容的 PyTorch 版本。",[]]