您的位置:首页 > 科技 > IT业 > gm源码之家_推广链接软件_企业营销策划书范文_无锡网站制作无锡做网站

gm源码之家_推广链接软件_企业营销策划书范文_无锡网站制作无锡做网站

2024/12/26 23:01:55 来源:https://blog.csdn.net/weixin_42771529/article/details/144349958  浏览:    关键词:gm源码之家_推广链接软件_企业营销策划书范文_无锡网站制作无锡做网站
gm源码之家_推广链接软件_企业营销策划书范文_无锡网站制作无锡做网站

魔搭社区

该区提供了随机种子级音乐的试听与下载。

spk = torch.load(<PT-FILE-PATH>)
params_infer_code = {'spk_emb': spk,
}
略

测试过程:

1.先建一个文件夹:然后从上面的网站上下载了两个。放在里面测试

2

2.测试代码

import ChatTTS
import torch
import torchaudiochat = ChatTTS.Chat()
chat.load(compile=False) # Set to True for better performance
###################################
# Sample a speaker from Gaussian.# rand_spk = chat.sample_random_speaker()
# print(rand_spk) # save it for later timbre recovery
guding_spk=torch.load("speaker/seed_2279.pt")params_infer_code = ChatTTS.Chat.InferCodeParams(spk_emb = guding_spk, # add sampled speakertemperature = .3,   # using custom temperaturetop_P = 0.7,        # top P decodetop_K = 20,         # top K decode
)###################################
# For sentence level manual control.# use oral_(0-9), laugh_(0-2), break_(0-7)
# to generate special token in text to synthesize.
params_refine_text = ChatTTS.Chat.RefineTextParams(prompt='[oral_2][laugh_0][break_6]',
)
#
# wavs = chat.infer(
#     texts,
#     params_refine_text=params_refine_text,
#     params_infer_code=params_infer_code,
# )###################################
# For word level manual control.
text = '故事中国网是《故事会》杂志社主办的网站。网站内容丰富,与杂志期刊《故事会》同步更新'
# text = 'What is [uv_break]your favorite english food?[laugh][lbreak]'
wavs = chat.infer(text, skip_refine_text=True, params_refine_text=params_refine_text,  params_infer_code=params_infer_code)
"""
In some versions of torchaudio, the first line works but in other versions, so does the second line.
"""
try:torchaudio.save("word_level_output.wav", torch.from_numpy(wavs[0]).unsqueeze(0), 24000)
except:torchaudio.save("word_level_output.wav", torch.from_numpy(wavs[0]), 24000)

3.提示情况:

python guding.py
/home/duyicheng/gitee/ChatTTS/guding.py:12: FutureWarning: You are using `torch.load` with `weights_only=False` (the current default value), which uses the default pickle module implicitly. It is possible to construct malicious pickle data which will execute arbitrary code during unpickling (See https://github.com/pytorch/pytorch/blob/main/SECURITY.md#untrusted-models for more details). In a future release, the default value for `weights_only` will be flipped to `True`. This limits the functions that could be executed during unpickling. Arbitrary objects will no longer be allowed to be loaded via this mode unless they are explicitly allowlisted by the user via `torch.serialization.add_safe_globals`. We recommend you start setting `weights_only=True` for any use case where you don't have full control of the loaded file. Please open an issue on GitHub for any issues related to this experimental feature.
  guding_spk=torch.load("speaker/seed_2279.pt")
found invalid characters: {'《', '》'}
code:   0%|                                                                                                                                                                                     | 1/2048(max) [00:00,  2.80it/s]We detected that you are passing `past_key_values` as a tuple of tuples. This is deprecated and will be removed in v4.47. Please convert your cache or use an appropriate `Cache` class (https://huggingface.co/docs/transformers/kv_cache#legacy-cache-format)
code:  16%|█████████████████████████████▏                                                                                                                                                     | 334/2048(max) [00:10, 31.73it/s]
(chattts) duyicheng@duyicheng-computer:~/gitee/ChatTTS$

4.解决

根据你提供的信息,有几个问题需要注意:

1. **FutureWarning 关于 `torch.load`**:
   - 这个警告是因为你在使用 `torch.load` 加载模型权重时,默认情况下使用了 `pickle` 模块。未来版本的 PyTorch 将默认设置 `weights_only=True`,这意味着只有权重会被加载,而不是整个对象。
   - 建议你显式地设置 `weights_only=True` 来避免潜在的安全风险。
   - 修改代码如下:
     ```python
     guding_spk = torch.load("speaker/seed_2279.pt", weights_only=True)
     ```


2. **无效字符警告**:
   - 警告提示在文本中找到了无效字符 `{'《', '》'}`。这些字符可能不是模型支持的字符集的一部分。
   - 你可以尝试移除或替换这些字符,或者检查模型是否支持中文字符。
   - 修改文本如下:
     ```python
     text = '故事中国网是《故事会》杂志社主办的网站。网站内容丰富,与杂志期刊《故事会》同步更新'.replace('《', '').replace('》', '')
     ```


3. **关于 `past_key_values` 的弃用警告**:
   - 这个警告来自 Hugging Face 的 Transformers 库,提示你传递的 `past_key_values` 格式即将被弃用。
   - 你需要检查并更新你的代码以使用新的缓存格式。
   - 参考 Hugging Face 的文档进行相应的修改:[Legacy Cache Format](https://huggingface.co/docs/transformers/kv_cache#legacy-cache-format)

总结:
- 更新 `torch.load` 的调用以设置 `weights_only=True`。
- 移除或替换文本中的无效字符。
- 检查并更新 `past_key_values` 的使用方式以符合最新的库要求。

 5.修改后代码

import ChatTTS
import torch
import torchaudiochat = ChatTTS.Chat()
chat.load(compile=False) # Set to True for better performance
###################################
# Sample a speaker from Gaussian.# rand_spk = chat.sample_random_speaker()
# print(rand_spk) # save it for later timbre recovery
guding_spk=torch.load("speaker/seed_2279.pt",weights_only=True)params_infer_code = ChatTTS.Chat.InferCodeParams(spk_emb = guding_spk, # add sampled speakertemperature = .3,   # using custom temperaturetop_P = 0.7,        # top P decodetop_K = 20,         # top K decode
)###################################
# For sentence level manual control.# use oral_(0-9), laugh_(0-2), break_(0-7)
# to generate special token in text to synthesize.
params_refine_text = ChatTTS.Chat.RefineTextParams(prompt='[oral_2][laugh_0][break_6]',
)
#
# wavs = chat.infer(
#     texts,
#     params_refine_text=params_refine_text,
#     params_infer_code=params_infer_code,
# )###################################
# For word level manual control.
text = """
根据你提供的信息,有几个问题需要注意:
FutureWarning 关于 torch.load:
这个警告是因为你在使用 torch.load 加载模型权重时,默认情况下使用了 pickle 模块。未来版本的 PyTorch 将默认设置 weights_only=True,这意味着只有权重会被加载,而不是整个对象。
建议你显式地设置 weights_only=True 来避免潜在的安全风险。
修改代码如下:"""
# text = 'What is [uv_break]your favorite english food?[laugh][lbreak]'
wavs = chat.infer(text, skip_refine_text=True, params_refine_text=params_refine_text,  params_infer_code=params_infer_code)
"""
In some versions of torchaudio, the first line works but in other versions, so does the second line.
"""
try:torchaudio.save("word_level_output.wav", torch.from_numpy(wavs[0]).unsqueeze(0), 24000)
except:torchaudio.save("word_level_output.wav", torch.from_numpy(wavs[0]), 24000)

6.固定随机的内容并自行测试的方法


rand_spk = chat.sample_random_speaker()
torch.save(rand_spk, "speaker/XXXX.pt")
# print(rand_spk) # save it for later timbre recovery

以上测试通过。6G的卡,音质方面比4G  要好不少。原来我一台破机器上的破音很多。可能真得与硬件有关。

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com