@paulabartabajo_:给AI工程师的建议 如果你正在构建语音智能体,别再连接3个独立模型了,用于音频转文本、文本转音频,或文本转文本……

X AI KOLs Timeline 模型

摘要

宣布推出 liquid-audio,这是 Liquid AI 端到端语音转语音 LFM 模型(LFM2-Audio-1.5B 和 LFM2.5-Audio-1.5B)的开源仓库,支持交错和顺序生成模式以及微调功能。

给AI工程师的建议 如果你正在构建语音智能体,别再连接3个独立模型了,用于音频转文本、文本转音频或文本转文本。𝗹𝗶𝗾𝘂𝗶𝗱-𝗮𝘂𝗱𝗶𝗼 是业界领先语音转语音 LFM 模型的开源仓库。端到端架构。现在还支持微调功能。更多示例即将推出。收藏这个 ↓ https://github.com/Liquid4All/liquid-audio…
查看原文
查看缓存全文

缓存时间: 2026/05/08 23:39

给 AI 工程师的建议

如果你正在构建语音助手,别再连接 3 个独立的模型了——分别用于语音转文本、文本转语音或文本转文本。liquid-audio 是一个开源仓库,提供了 SOTA 级别的语音到语音 LFM 模型。端到端。现在还支持微调。更多示例即将推出。收藏这个 ↓https://github.com/Liquid4All/liquid-audio…


Liquid4All/liquid-audio

源码: https://github.com/Liquid4All/liquid-audio

Liquid Audio - 语音到语音模型

我们推出 LFM2-Audio-1.5B,这是 Liquid AI (https://www.liquid.ai/) 的首个端到端音频基础模型。以低延迟为设计目标,轻量级的 LFM2 (https://huggingface.co/LiquidAI/LFM2-1.2B) 骨干网络支持实时语音到语音对话,同时不牺牲质量。LFM2-Audio 支持两种生成模式:交错生成顺序生成,可在不同任务中最大化性能和质量。

交错生成以固定的交错模式输出文本和音频 token。这种方法最小化了首个音频输出的延迟时间和生成的 token 数量,使其成为资源受限设备上自然流畅的实时语音到语音交互的理想选择。

顺序生成模式由模型通过特殊 token 决定何时切换模态,适用于非对话任务,如语音识别 (ASR) 或文本转语音 (TTS)。

更新

  • LFM2.5-Audio-1.5B (https://huggingface.co/LiquidAI/LFM2.5-Audio-1.5B) 已发布!该模型基于更强的 LFM2.5-1.2B 基础模型,并配备了一个基于 LFM2 的极速音频解tokenizer、更强的 ASR 和更好的 TTS 语音。要使用新的解tokenizer,只需使用 processor.decode,详见下方示例。改进的 TTS 语音见 TTS 部分。

安装

可以通过 pip 安装该包

pip install liquid-audio
pip install "liquid-audio [demo]" # 可选,安装演示依赖
pip install flash-attn --no-build-isolation # 可选,使用 flash attention 2
# 如果未安装将回退到 torch SDPA

使用方法

生成由两种生成模式处理:交错生成顺序生成,分别通过方法 LFM2AudioModel.generate_interleavedLFM2AudioModel.generate_sequential 访问。两者都是生成器,会 yield torch.Tensor。文本 token 用 1 个元素的 tensor 表示,音频 token 用 8 个元素的 tensor 表示,对应 8 个 Mimi (https://huggingface.co/docs/transformers/en/model_doc/mimi) 码本。

LFM2AudioModel 类只操作 token。LFM2AudioProcessor 类用于在 token 和数据之间转换。对于文本,这意味着字符串和 token 之间的相互转换。对于音频输入,这处理波形到 log-mel 特征的转换;对于音频输出,这处理音频 token 到波形的解tokenize。为了方便为生成方法创建输入并应用正确的聊天模板,请使用 ChatState 辅助类。详见下方示例。

Gradio 演示

要使用演示界面,请确保安装 [demo] 组的额外依赖,例如

pip install "liquid-audio [demo]"

要启动演示,请在终端使用命令 liquid-audio-demo。演示界面可通过 http://localhost:7860 访问。

多轮多模态聊天

对于多轮文本和音频输出聊天,我们使用交错生成。系统提示词应设置为 Respond with interleaved text and audio.。这里我们用音频作为第一个用户轮次,文本作为第二个轮次。

对话记录

用户

https://github.com/user-attachments/assets/e2ffb8c3-c84c-4460-9cb8-f95a13b6eec6

助手

当然!比如“手工木工,精准为您打造“怎么样?另一个选项可以是“优质木工,优质成果“。如果你想要更个性化的,可以试试“您的木工需求,我们的专业“。

https://github.com/user-attachments/assets/019664b5-3480-4801-b05a-bd62ddcb8d3e

用户

我的业务主要做椅子,你能给我一些相关的吗?

助手

当然可以!“舒适的椅子,精心制作“或者“优雅的座椅,纯手工为您打造“怎么样?如果需要更多选项请告诉我。

https://github.com/user-attachments/assets/d0d054b2-6d1d-49fb-94df-4aa0b6641990

import torch
import torchaudio

from liquid_audio import LFM2AudioModel, LFM2AudioProcessor, ChatState, LFMModality

# 加载模型
HF_REPO = "LiquidAI/LFM2.5-Audio-1.5B"
processor = LFM2AudioProcessor.from_pretrained(HF_REPO).eval()
model = LFM2AudioModel.from_pretrained(HF_REPO).eval()

# 为模型设置输入
chat = ChatState(processor)
chat.new_turn("system")
chat.add_text("Respond with interleaved text and audio.")
chat.end_turn()

chat.new_turn("user")
wav, sampling_rate = torchaudio.load("assets/question.wav")
chat.add_audio(wav, sampling_rate)
chat.end_turn()

chat.new_turn("assistant")

# 生成文本和音频 token
text_out: list[torch.Tensor] = []
audio_out: list[torch.Tensor] = []
modality_out: list[LFMModality] = []

for t in model.generate_interleaved(**chat, max_new_tokens=512, audio_temperature=1.0, audio_top_k=4):
    if t.numel() == 1:
        print(processor.text.decode(t), end="", flush=True)
        text_out.append(t)
        modality_out.append(LFMModality.TEXT)
    else:
        audio_out.append(t)
        modality_out.append(LFMModality.AUDIO_OUT)

# 输出: Sure! How about "Handcrafted Woodworking, Precision Made for You"? Another option could be "Quality Woodworking, Quality Results." If you want something more personal, you might try "Your Woodworking Needs, Our Expertise."

# 解tokenize 音频,移除最后的"音频结束"码
# Mimi 返回 24kHz 的音频
audio_codes = torch.stack(audio_out[:-1], 1).unsqueeze(0)
waveform = processor.decode(audio_codes)
torchaudio.save("answer1.wav", waveform.cpu(), 24_000)

# 将新生成的 token 追加到聊天历史
chat.append(
    text = torch.stack(text_out, 1),
    audio_out = torch.stack(audio_out, 1),
    modality_flag = torch.tensor(modality_out),
)
chat.end_turn()

# 开始新轮次
chat.new_turn("user")
chat.add_text("My business specialized in chairs, can you give me something related to that?")
chat.end_turn()

chat.new_turn("assistant")

# 生成第二轮文本和音频 token
audio_out: list[torch.Tensor] = []

for t in model.generate_interleaved(**chat, max_new_tokens=512, audio_temperature=1.0, audio_top_k=4):
    if t.numel() == 1:
        print(processor.text.decode(t), end="", flush=True)
    else:
        audio_out.append(t)

# 输出: Sure thing! How about "Comfortable Chairs, Crafted with Care" or "Elegant Seats, Handcrafted for You"? Let me know if you'd like a few more options.

# 解tokenize 第二轮的音频,移除最后的"音频结束"码
audio_codes = torch.stack(audio_out[:-1], 1).unsqueeze(0)
waveform = processor.decode(audio_codes)
torchaudio.save("answer2.wav", waveform.cpu(), 24_000)

ASR

对于 ASR,我们使用顺序生成,系统提示词固定为 Perform ASR.。输出带有大写和标点。

输入音频片段

https://github.com/user-attachments/assets/b3cc017f-363d-49f3-8e7d-f6db9556900e

模型输出: The stale smell of old beer lingers. It takes heat to bring out the odor. A cold dip restores health and zest. A salt pickle tastes fine with ham. Tacos al pastor are my favorite. A zestful food is the hot cross bun.

import torch
import torchaudio

from liquid_audio import LFM2AudioModel, LFM2AudioProcessor, ChatState, LFMModality

# 加载模型
HF_REPO = "LiquidAI/LFM2.5-Audio-1.5B"
processor = LFM2AudioProcessor.from_pretrained(HF_REPO).eval()
model = LFM2AudioModel.from_pretrained(HF_REPO).eval()

# 为模型设置输入
chat = ChatState(processor)
chat.new_turn("system")
chat.add_text("Perform ASR.")
chat.end_turn()

chat.new_turn("user")
wav, sampling_rate = torchaudio.load("assets/asr.wav")
chat.add_audio(wav, sampling_rate)
chat.end_turn()

chat.new_turn("assistant")

# 生成文本
for t in model.generate_sequential(**chat, max_new_tokens=512):
    if t.numel() == 1:
        print(processor.text.decode(t), end="", flush=True)

# 输出: The stale smell of old beer lingers. It takes heat to bring out the odor. A cold dip restores health and zest. A salt pickle tastes fine with ham. Tacos al pastor are my favorite. A zestful food is the hot cross bun.

TTS

对于 TTS,我们也使用顺序生成。我们支持四个预定义语音,可以通过选择以下四个系统提示词之一来选择

Perform TTS. Use the US male voice.
Perform TTS. Use the US female voice.
Perform TTS. Use the UK male voice.
Perform TTS. Use the UK female voice.

TTS 示例

系统提示词: Perform TTS. Use the UK male voice.

输入句子: What is this obsession people have with books? They put them in their houses—like they’re trophies. What do you need it for after you read it?

输出音频

https://github.com/user-attachments/assets/8d57c184-b92e-4e1a-983b-d1f9d16d0d92

import torch
import torchaudio

from liquid_audio import LFM2AudioModel, LFM2AudioProcessor, ChatState, LFMModality

# 加载模型
HF_REPO = "LiquidAI/LFM2.5-Audio-1.5B"
processor = LFM2AudioProcessor.from_pretrained(HF_REPO).eval()
model = LFM2AudioModel.from_pretrained(HF_REPO).eval()

# 为模型设置输入
chat = ChatState(processor)
chat.new_turn("system")
chat.add_text("Perform TTS. Use the UK male voice.")
chat.end_turn()

chat.new_turn("user")
chat.add_text("What is this obsession people have with books? They put them in their houses—like they're trophies. What do you need it for after you read it?")
chat.end_turn()

chat.new_turn("assistant")

# 生成文本音频
audio_out: list[torch.Tensor] = []

for t in model.generate_sequential(**chat, max_new_tokens=512, audio_temperature = 0.8, audio_top_k=64):
    if t.numel() > 1:
        audio_out.append(t)

# 解tokenize 音频
audio_codes = torch.stack(audio_out[:-1], 1).unsqueeze(0)
waveform = processor.decode(audio_codes)
torchaudio.save("tts.wav", waveform.cpu(), 24_000)

微调

要微调你自己的数据,请使用 ChatMessage 接口。这需要你:

  1. 将你的原始数据集行映射为 list[ChatMessage]
  2. 使用 LFM2AudioChatMapper 创建预处理数据集
  3. 使用 LFM2DataLoader 从预处理数据集训练模型

首先,安装项目依赖:

uv sync

预处理

在训练前,将数据集转换为我们的预处理训练格式。为此,定义一个迭代器,为数据集中的每个样本生成一个 list[ChatMessage]LFM2AudioChatMapper 负责将这些消息转换为模型可用的特征。

ChatMessage 支持:

  • TextSegment(text=...)
  • AudioSegment(audio=...)
  • InterleavedSegment(text=..., audio=...)

详见 examples/preprocess_jenny_tts.py 中如何预处理 Jenny TTS 数据集 (https://huggingface.co/datasets/reach-vb/jenny_tts_dataset) 用于 TTS 模型微调的示例。

运行预处理:

python -m examples.preprocess_jenny_tts

这会将预处理数据集写入 data/jenny_tts/train

训练

训练读取预处理数据集。例如,要使用之前从预处理数据集微调 Jenny TTS 数据集 (https://huggingface.co/datasets/reach-vb/jenny_tts_dataset) 上的模型,运行:

python -m examples.train

许可证

本仓库中的代码及相关权重采用 LFM Open License v1.0 许可。音频编码器代码基于 Nvidia NeMo (https://github.com/NVIDIA-NeMo/NeMo/tree/main),采用 Apache 2.0 许可 (https://github.com/NVIDIA-NeMo/NeMo/blob/294ddff187f68c055d87ffe9400e65975b38693d/LICENSE),以及 canary-180m-flash (https://huggingface.co/nvidia/canary-180m-flash) 检查点,采用 CC-BY 4.0 许可 (https://huggingface.co/datasets/choosealicense/licenses/blob/main/markdown/cc-by-4.0.md)。为简化依赖解析,我们还附带了 Kyutai Mimi (https://github.com/kyutai-labs/moshi) 的 Python 代码,采用 MIT 许可 (https://github.com/kyutai-labs/moshi/blob/aee53fc0fc0119e4d7343e5ea4dd6ddafd7f09c4/LICENSE-MIT)。

相似文章

在API中引入下一代音频模型

OpenAI Blog

OpenAI 为 API 引入了下一代音频模型,包括改进的语音转文本(gpt-4o-transcribe、gpt-4o-mini-transcribe)和可自定义的文本转语音模型,使开发者能够构建更智能、更具表现力的语音代理,在具有挑战性的场景中提升准确性。

OpenAI的新语音模型不止于回话

Reddit r/ArtificialInteligence

OpenAI推出了三个新的实时音频模型,支持连续、多任务的语音交互,优先考虑长上下文推理、实时翻译和无缝工具使用。

LiquidAI/LFM2.5-ColBERT-350M

Hugging Face Models Trending

LiquidAI 发布 LFM2.5-ColBERT-350M,这是一种后期交互多语言检索模型,同时还有一个密集双编码器变体,两者均基于 LFM2.5-350M-Base,支持 11 种语言,并设计为 RAG 管道的即插即用替代品。