🚀 Nidum-Madurai-Tamil-TTS
🔊 这是由 Nidum 开发的一款高质量泰米尔语语音合成(TTS)模型。它能够根据输入文本生成清晰、自然的泰米尔语语音,适用于语音助手、屏幕阅读器、语言学习应用和内容朗读等场景。
🧪 在线演示:点击在Hugging Face Spaces上试用

🚀 快速开始
你可以通过以下步骤快速体验该模型:
- 访问 在线演示。
- 输入泰米尔语文本,选择语音角色。
- 点击“生成”按钮,即可立即收听生成的语音。
✨ 主要特性
- ✅ 能够将泰米尔语脚本转换为语音。
- ✅ 语音自然、富有表现力。
- ✅ 支持选择男性或女性语音。
- ✅ 可通过Hugging Face Spaces轻松试用。
🧑🎤 语音角色
语音角色ID |
语音类型 |
0 speaker |
男性 |
1 speaker |
女性 |
你可以在输入提示中使用相应的语音角色ID,示例如下:
0 speaker: வணக்கம்!
💻 使用示例
基础用法
import torch
import soundfile as sf
from transformers import AutoModelForCausalLM, AutoTokenizer
from snac import SNAC
fine_tuned_checkpoint = "<Model_ID>"
print("Loading model...")
model = AutoModelForCausalLM.from_pretrained(fine_tuned_checkpoint, torch_dtype=torch.bfloat16).cuda()
tokenizer = AutoTokenizer.from_pretrained(fine_tuned_checkpoint)
print("Loading SNAC model...")
snac_model = SNAC.from_pretrained("hubertsiuzdak/snac_24khz").to("cpu")
prompts = [
"0 speaker: வணக்கம்! இந்த பயன்பாட்டை பயன்படுத்தி உங்கள் உரையை குரலாக்கலாம்."
]
all_input_ids = [tokenizer(p, return_tensors="pt").input_ids for p in prompts]
start_token = torch.tensor([[128259]], dtype=torch.int64)
end_tokens = torch.tensor([[128009, 128260]], dtype=torch.int64)
all_modified_input_ids = [torch.cat([start_token, ids, end_tokens], dim=1) for ids in all_input_ids]
max_length = max([ids.shape[1] for ids in all_modified_input_ids])
all_padded_tensors, all_attention_masks = [], []
for modified_input_ids in all_modified_input_ids:
padding = max_length - modified_input_ids.shape[1]
padded_tensor = torch.cat([torch.full((1, padding), 128263, dtype=torch.int64), modified_input_ids], dim=1)
attention_mask = torch.cat([torch.zeros((1, padding), dtype=torch.int64), torch.ones((1, modified_input_ids.shape[1]), dtype=torch.int64)], dim=1)
all_padded_tensors.append(padded_tensor)
all_attention_masks.append(attention_mask)
input_ids = torch.cat(all_padded_tensors, dim=0).cuda()
attention_mask = torch.cat(all_attention_masks, dim=0).cuda()
print("Generating speech...")
with torch.no_grad():
generated_ids = model.generate(
input_ids=input_ids,
attention_mask=attention_mask,
max_new_tokens=4800,
do_sample=True,
temperature=1,
top_p=1,
repetition_penalty=1.1,
num_return_sequences=1,
eos_token_id=128258,
)
print("Parsing output...")
token_indices = (generated_ids == 128257).nonzero(as_tuple=True)
if len(token_indices[1]) > 0:
last_occurrence_idx = token_indices[1][-1].item()
cropped_tensor = generated_ids[:, last_occurrence_idx + 1:]
else:
cropped_tensor = generated_ids
processed_rows = [row[row != 128258] for row in cropped_tensor]
code_lists = []
for row in processed_rows:
row_length = row.size(0)
new_length = (row_length // 7) * 7
trimmed_row = row[:new_length] - 128266
code_lists.append(trimmed_row.tolist())
def redistribute_codes(code_list):
layer_1, layer_2, layer_3 = [], [], []
for i in range((len(code_list) + 1) // 7):
layer_1.append(code_list[7 * i])
layer_2.append(code_list[7 * i + 1] - 4096)
layer_3.append(code_list[7 * i + 2] - (2 * 4096))
layer_3.append(code_list[7 * i + 3] - (3 * 4096))
layer_2.append(code_list[7 * i + 4] - (4 * 4096))
layer_3.append(code_list[7 * i + 5] - (5 * 4096))
layer_3.append(code_list[7 * i + 6] - (6 * 4096))
codes = [
torch.tensor(layer_1).unsqueeze(0),
torch.tensor(layer_2).unsqueeze(0),
torch.tensor(layer_3).unsqueeze(0)
]
return snac_model.decode(codes)
print("Decoding speech...")
audio_samples = [redistribute_codes(codes) for codes in code_lists]
for i, samples in enumerate(audio_samples):
audio_data = samples.detach().squeeze().to("cpu").numpy()
sf.write(f"output_{i}.wav", audio_data, samplerate=24000)
print(f"Audio {i} saved as output_{i}.wav")
print("Done!")
📬 联系我们
如果您有任何问题、反馈或合作意向,请通过以下邮箱联系我们:
📧 info@nidum.ai
📄 许可证
本项目采用 Apache-2.0 许可证。