YoruTTS-1.5 / YoruTTS-0p5-Inference.py
aspmirlab's picture
Upload 3 files
6a8a991 verified
#Install relevant libraries if they are not yet available in your environment using the following commands from Terminal(MacOS) or Command Prompt(MS Windows)
#pip install torch
#pip install TTS
#pip install sounddevice
#pip install numpy
#Use the following commands if you are in Jupyter Notebook
#!pip install torch
#!pip install TTS
#!pip install sounddevice
#!pip install numpy
import torch
from TTS.api import TTS
import sounddevice as sd
import numpy as np
#ENSURE YoruTTS-0p5.pth and YoruTTS-0p5-Config.json are in thesame folder with this YoruTTS-0p5-Inference.py file
# Initialize the TTS model
tts = TTS(model_path="YoruTTS-0p5.pth", config_path="YoruTTS-0p5-Config.json" , progress_bar=True, gpu=False)
#Input text to synthesize
#text1 is a seen text during traning
#text2 is a unseen text during training
text1 = "Yàtọ̀ síyẹn, nǹkan bí ẹgbẹ̀rún kan àti ọgọ́rùn - ún mẹ́fà lára àwọn ọmọ tí wọ́n rán jáde ló ti pàdánù àǹfààní kan ṣoṣo."
text2 = "Ó jọ fún mi pé dípò tí wọn ì bá fi rọ́pò olùkọ́, ńṣe ni ẹgbẹ́ náà nílò àwọn òṣèré tuntun."
#Generate speech
wav = tts.tts(text=text2)
#Save the audio to a file
#For speech synthesis for text1: text=text1 AND file_path="WaveOutput-Text1"
#For speech synthesis for text2: text=text2 AND file_path="WaveOutput-Text2"
tts.tts_to_file(text=text1, file_path="WaveOutput-Text1.wav")