Skip to content

Instantly share code, notes, and snippets.

@Gromina
Created April 3, 2021 17:19
Show Gist options
  • Save Gromina/d48ae481b503dffa8cdf2e734e7ffce4 to your computer and use it in GitHub Desktop.
Save Gromina/d48ae481b503dffa8cdf2e734e7ffce4 to your computer and use it in GitHub Desktop.
# ├── russian_g2p # https://github.com/nsu-ai/russian_g2p.git
# ├── russian_stt_text_normalization # https://github.com/snakers4/russian_stt_text_normalization.git
# ├── # silero
# └── TTS.py
#
#
import itertools
import torch
import torchaudio
from russian_stt_text_normalization.normalizer import Normalizer
#from russian_g2p.russian_g2p.Transcription import Transcription
from russian_g2p.russian_g2p.Accentor import Accentor
your_accentor = Accentor()
language = 'ru'
gg=["baya_16khz", "aidar_16khz"]
speaker = gg[0] #'kseniya_16khz'
device = torch.device('cpu')
model, symbols, sample_rate, example_text, apply_tts = torch.hub.load(repo_or_dir='snakers4/silero-models',
model='silero_tts',
language=language,
speaker=speaker)
model = model.to(device) # gpu or cpu
import itertools
import torch
import torchaudio
from russian_stt_text_normalization.normalizer import Normalizer
#from russian_g2p.russian_g2p.Transcription import Transcription
from russian_g2p.russian_g2p.Accentor import Accentor
your_accentor = Accentor()
language = 'ru'
gg=["baya_16khz", "aidar_16khz"]
speaker = gg[0] #'kseniya_16khz'
device = torch.device('cpu')
model, symbols, sample_rate, example_text, apply_tts = torch.hub.load(repo_or_dir='snakers4/silero-models',
model='silero_tts',
language=language,
speaker=speaker)
model = model.to(device) # gpu or cpu
text = 'Принцесса была прекрасной'
norm = Normalizer()
result = norm.norm_text(text)
words = [[w] for w in result.split() ]
accents = your_accentor.do_accents(words)
accents = " ".join(list(itertools.chain(*accents)))
print("1. ", text)
print("2. ", result)
print("3. ", accents)
audio = apply_tts(texts=[accents],
model=model,
sample_rate=sample_rate,
symbols=symbols,
device=device)
torchaudio.set_audio_backend("sox")
torchaudio.save('result.wav', audio[0], sample_rate)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment