Views
No views yet
from transformers import SpeechT5Processor, SpeechT5ForTextToSpeech
import numpy as np
tts_model = SpeechT5ForTextToSpeech.from_pretrained("ThuraAung1601/speecht5_for_thai_with_ipa_tts_v1")
ipa_processor = SpeechT5Processor.from_pretrained("ThuraAung1601/speecht5_for_thai_with_ipa_tts_v1")
ipa_tokenizer = ipa_processor.tokenizer
ipa_tokenizer.decode(ipa_tokenizer(text)["input_ids"])
loaded_np = np.load("speaker_embedding_304.npy")
speaker_embedding = torch.tensor(loaded_np)
text = "ที่ข้าพเจ้าได้เคยล่วงเกินท่านไว้"
from pythainlp.tokenize import word_tokenize
from pythainlp.transliterate import transliterate
def thai2ipa_dict(text):
result = []
for word in word_tokenize(text):
result.append(transliterate(word).replace(" ", ""))
return "".join(result)
ipa = thai2ipa_dict(text)
model_input = ipa_processor(text=ipa, return_tensors="pt")
spectrogram = tts_model.generate_speech(model_input["input_ids"], speaker_embedding)
from transformers import SpeechT5HifiGan
the_vocoder = SpeechT5HifiGan.from_pretrained("microsoft/speecht5_hifigan")
with torch.no_grad():
speech = the_vocoder(spectrogram)
import soundfile as sf
sf.write("output.wav", speech.numpy(), samplerate=16000)| Training Loss | Epoch | Step | Validation Loss |
|---|---|---|---|
| 0.5418 | 0.5601 | 1000 | 0.4969 |
| 0.5335 | 1.1199 | 2000 | 0.4889 |
| 0.5177 | 1.6799 | 3000 | 0.4818 |
| 0.5188 | 2.2397 | 4000 | 0.4800 |
| 0.5067 | 2.7998 | 5000 | 0.4738 |
| 0.5072 | 3.3596 | 6000 | 0.4730 |