TTS 零样本#

Riva 通过 P-Flow 引入了零样本 TTS 功能。Pflow 是一种快速高效的基于流的 TTS 模型,只需 3 秒的音频数据即可适应新的声音。Pflow 使用语音提示的文本编码器进行说话人适配,并使用流匹配生成解码器进行高质量和快速的语音合成。

注意

零样本 Riva TTS 模型目前处于有限的早期访问阶段。

OOTB 声音#

语言

模型

数据集

G2P

性别

声音

en-US

P-Flow HiFi-GAN

英语-美国

IPA

多说话人

English-US-Pflow.Female.neutral English-US-Pflow.Female.angry English-US-Pflow.Female.fearful English-US-Pflow.Female-1 English-US-Pflow.Female.disgusted English-US-Pflow.Female.calm English-US-Pflow.Female.happy English-US-Pflow.Female.sad English-US-Pflow.Male.calm English-US-Pflow.Male.happy English-US-Pflow.Male.sad English-US-Pflow.Male.disgusted English-US-Pflow.Male.neutral English-US-Pflow.Male.angry English-US-Pflow.Male.fearful English-US-Pflow.Male-1

设置 TTS Python API 参数#

sample_rate_hz = 44100
req = { 
        "language_code"  : "en-US",
        "encoding"       : riva.client.AudioEncoding.LINEAR_PCM ,        # LINEAR_PCM and OGGOPUS encodings are supported
        "sample_rate_hz" : sample_rate_hz,                               # Generate 44.1KHz audio
        "voice_name"     : "English-US-Pflow.Female.neutral",            # The name of the voice to generate
        "audio_prompt_encoding" : riva.client.AudioEncoding.LINEAR_PCM , # LINEAR_PCM and OGGOPUS encodings are supported
        "quality"  : 20                                                  # Number of times to iterate over while generating mels 
        "audio_prompt_file" : ""                                         # Path to the file containing the speech prompt
}

理解 TTS Python API 参数#

Riva TTS 在向 gRPC 端点发出文本到语音请求时支持多种选项,如上所示。让我们详细了解这些参数

  • language_code - 生成音频的语言代码

  • encoding - 要生成的音频编码类型。支持 LINEAR_PCM 和 OGGOPUS 编码。

  • sample_rate_hz - 生成音频的采样率。取决于输出音频设备,通常为 22khz 或 44khz。

  • voice_name - 用于合成音频的声音。目前,Riva 提供两种带有情感的 OOTB 默认声音

  • audio_prompt_encoding - 语音提示的音频编码类型。支持 LINEAR_PCM 和 OGGOPUS 编码。

  • quality - 用于 mel 生成的解码器迭代次数。范围为 1-40。

  • audio_prompt_file - 语音提示音频文件路径。如果同时传递了声音名称和语音提示,则将使用语音提示。

向 Riva 服务器发出 gRPC 请求#

对于批量推理模式,请使用 synthesize。当整个音频合成完成时,将返回结果。

req["text"] = "Is it recognize speech or wreck a nice beach?"
resp = riva_tts.synthesize(**req)
audio_samples = np.frombuffer(resp.audio, dtype=np.int16)
ipd.Audio(audio_samples, rate=sample_rate_hz)

对于在线推理,请使用 synthesize_online。结果以块的形式返回,因为它们是合成的。

req["text"] = "Is it recognize speech or wreck a nice beach?"
resp = riva_tts.synthesize_online(**req)
empty = np.array([])
for i, rep in enumerate(resp):
    audio_samples = np.frombuffer(rep.audio, dtype=np.int16) / (2**15)
    print("Chunk: ",i)
    ipd.display(ipd.Audio(audio_samples, rate=44100))
    empty = np.concatenate((empty, audio_samples))

print("Final synthesis:")
ipd.display(ipd.Audio(empty, rate=44100))

二进制客户端示例#

Docker 镜像中支持的二进制客户端也可以按如下方式使用

二进制 TTS 客户端示例#

riva_tts_client --text="I had a dream yesterday." --audio_file=/opt/riva/wav/output.wav --zero_shot_audio_prompt=<Path to the audio file> --zero_shot_quality=20

或者使用 voice_name 参数来使用任何 OOTB 声音。如果同时传递了声音名称和语音提示,则将使用语音提示。

riva_tts_client --text="I had a dream yesterday." --audio_file=/opt/riva/wav/output.wav --voice_name="English-US-Pflow.Female.neutral"

二进制 TTS 性能客户端示例#

二进制 TTS 客户端将相同的语音提示应用于 test_file 中的所有输入查询

riva_tts_perf_client --text_file=/work/test_files/tts/ljs_audio_text_test_filelist_small.txt --voice_name="English-US-Pflow.Female.neutral"