Dia-1.6B TTS:最佳文本转对话生成模型

Dia-1.6B TTS:最佳文本转对话生成模型

正在寻找合适的文本到语音模型?拥有 16 亿个参数的模型 Dia 可能就是您的最佳选择。如果您知道这个模型是由两名本科生在零资金的情况下创建的,您一定会大吃一惊!在本文中,您将了解到该模型的相关信息、如何访问和使用该模型,还将看到结果,从而真正了解该模型的能力。在使用该模型之前,最好先熟悉一下它。

什么是Dia-1.6B?

以文本作为输入、自然语音作为输出为目标而训练的模型称为文本到语音模型。由 Nari Labs 开发的 Dia-1.6B 参数模型属于文本到语音模型系列。这是一个有趣的模型,它能够从文本生成逼真的对话。值得注意的是,该模型还能产生非语言交流,如大笑、打喷嚏、吹口哨等。是不是很令人兴奋?

如何访问Dia-1.6B?

我们可以通过两种方式访问 Dia-1.6B 模型:

  1. 通过 Google Colab 使用 Hugging Face API
  2. 使用 Hugging Face spaces

第一种方法需要获取 API 密钥,然后用代码将其集成到 Google Colab 中。后者无需代码,我们可以交互式地使用 Dia-1.6B。

1. 使用Hugging Face和Colab

该模型可在 Hugging Face 上使用,并可借助谷歌 Colab notebook 中 T4 GPU 提供的 10 GB VRAM 运行。我们将通过一个小型对话来演示。

在开始之前,让我们先获取 Hugging Face 访问令牌,这是运行代码所必需的。如果还没有密钥,请访问 https://huggingface.co/settings/tokens 生成一个密钥。

确保启用以下权限:

 Colab notebook 权限

在 Google Colab 中打开一个新 notebook,并在秘密中添加此密钥(名称应为 HF_Token):

新 notebook

注:运行此 notebook 需要切换到 T4 GPU。只有这样,您才能使用运行该机型所需的 10GB VRAM。

现在,让我们开始动手制作模型:

  1. 首先克隆 Dia 的 Git 仓库:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
!git clone https://github.com/nari-labs/dia.git
!git clone https://github.com/nari-labs/dia.git
!git clone https://github.com/nari-labs/dia.git
  1. 安装本地软件包:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
!pip install ./dia
!pip install ./dia
!pip install ./dia
  1. 安装 soundfile 音频库:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
!pip install soundfile
!pip install soundfile
!pip install soundfile

运行前面的命令后,请重启会话再继续。

  1. 安装完成后,让我们进行必要的导入并初始化模型:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
import soundfile as sf
from dia.model import Dia
import IPython.display as ipd
model = Dia.from_pretrained("nari-labs/Dia-1.6B")
import soundfile as sf from dia.model import Dia import IPython.display as ipd model = Dia.from_pretrained("nari-labs/Dia-1.6B")
import soundfile as sf
from dia.model import Dia
import IPython.display as ipd
model = Dia.from_pretrained("nari-labs/Dia-1.6B")
  1. 初始化文本,用于文本到语音的转换:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
text = "[S1] This is how Dia sounds. (laugh) [S2] Don't laugh too much. [S1] (clears throat) Do share your thoughts on the model."
text = "[S1] This is how Dia sounds. (laugh) [S2] Don't laugh too much. [S1] (clears throat) Do share your thoughts on the model."
text = "[S1] This is how Dia sounds. (laugh) [S2] Don't laugh too much. [S1] (clears throat) Do share your thoughts on the model."
  1. 对模型进行推理:
Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
output = model.generate(text)
sampling_rate = 44100 # Dia uses 44.1Khz sampling rate.
output_file="dia_sample.mp3"
sf.write(output_file, output, sampling_rate) # Saving the audio
ipd.Audio(output_file) # Displaying the audio
output = model.generate(text) sampling_rate = 44100 # Dia uses 44.1Khz sampling rate. output_file="dia_sample.mp3" sf.write(output_file, output, sampling_rate) # Saving the audio ipd.Audio(output_file) # Displaying the audio
output = model.generate(text)
sampling_rate = 44100 # Dia uses 44.1Khz sampling rate.
output_file="dia_sample.mp3"
sf.write(output_file, output, sampling_rate) # Saving the audio
ipd.Audio(output_file) # Displaying the audio

输出:

语音非常像人类,模型在非语言交流方面表现出色。值得注意的是,由于没有语音模板,结果无法重现。

注:您可以尝试修复模型的种子,以重现结果。

2. 使用Hugging Face spaces

让我们尝试通过“Hugging Face spaces”使用模型克隆声音。在这里,我们可以选择在在线界面 https://huggingface.co/spaces/nari-labs/Dia-1.6B 上直接使用模型。

在这里,你可以传递输入文本,还可以使用“音频提示”来复制声音。我传递了上一节中生成的音频。

输入文本如下

[S1] Dia is an open weights text to dialogue model. [S2] You get full control over scripts and voices. [S1] Wow. Amazing. (laughs) [S2] Try it now on Git hub or Hugging Face.

通过“Hugging Face spaces”使用模型克隆声音

来源:Hugging Face Labs

我让你来评判一下,你觉得这个模型成功捕捉并复制了之前的声音吗?

:在使用 Hugging Face spaces 生成语音时,我遇到了多个错误,请尝试更改输入文本或音频提示,以使模型正常工作。

使用Dia-1.6B时应注意的事项

使用 Dia-1.6B 时应注意以下几点:

  • 该模型没有针对特定语音进行微调。因此,每次运行都会得到不同的声音。您可以尝试固定模型的种子来重现结果。
  • Dia 使用 44.1 KHz 采样率。
  • 安装完库后,请确保重启 Colab notebook。
  • 我在使用“Colab notebook”生成语音时多次出错,请尝试更改输入文本或音频提示,以确保模型正常工作。

小结

该模型的结果很有希望,尤其是当我们看到它与竞争对手相比所能做的事情时。该模型最大的优势是支持各种非语言交流。该模型的语调清晰,语音感觉自然,但另一方面,由于它没有对特定的声音进行微调,要再现特定的声音可能并不容易。与其他任何生成式人工智能工具一样,使用该模型时应负责任。

评论留言