<p>It is not trivial and requires special architecture. You can read the description of it in a publications of <a href="https://deepmind.com/blog/wavenet-generative-model-raw-audio/" rel="nofollow noreferrer">DeepMind</a> and <a href="https://arxiv.org/abs/1702.07825" rel="nofollow noreferrer">Baidu</a>.</p>

<p>You might also want to study <a href="https://github.com/ibab/tensorflow-wavenet" rel="nofollow noreferrer">existing implementation of wavenet training</a>.</p>

<p>Overall, pure end-to-end speech synthesis is still not working. If you are serious about text-to-speech it is better to study conventional systems like <a href="https://github.com/CSTR-Edinburgh/merlin" rel="nofollow noreferrer">merlin</a>. </p>
How to create text-to-speech with neural network
<p>I am creating a Text to Speech system for a phonetic language called "Kannada" and I plan to train it with a Neural Network. The input is a word/phrase while the output is the corresponding audio.</p>

<p>While implementing the Network, I was thinking the input should be the segmented characters of the word/phrase as the output pronunciation only depends on the characters that make up the word, unlike English where we have slient words and Part of Speech to consider. However, I do not know how I should train the output. </p>

<p>Since my Dataset is a collection of words/phrases and the corrusponding MP3 files, I thought of converting these files to WAV using pydub for all audio files.</p>

<pre><code>from pydub import AudioSegment
sound = AudioSegment.from_mp3("audio/file1.mp3")
sound.export("wav/file1.wav", format="wav")
</code></pre>

<p>Next, I open the wav file and convert it to a normalized byte array with values between 0 and 1. </p>

<pre><code>import numpy as np
import wave

f = wave.open('wav/kn3.wav', 'rb')
frames = f.readframes(-1)

#Array of integers of range [0,255]
data = np.fromstring(frames, dtype='uint8')

#Normalized bytes of wav
arr  = np.array(data)/255
</code></pre>

<p><strong>How Should I train this?</strong></p>

<p>From here, I am not sure how to train this with the input text. From this, I would need a variable number of input and output neurons in the First and Last layers as the number of characters (1st layer) and the bytes of the corresponding wave (Last layer) change for every input. </p>

<p>Since RNNs deal with such variable data, I thought it would come in handy here. </p>

<p>Correct me if I am wrong, but the output of Neural Networks are actually probability values between 0 and 1. However, we are not dealing with a classification problem. The audio can be anything, right? In my case, the "output" should be a vector of bytes corrusponding to the WAV file. So there will be around 40,000 of these with values between 0 and 255 (without the normalization step) for every word. How do I train this speech data? Any suggestions are appreciated.</p>

<p><strong>EDIT 1</strong> : In response to <strong>Aaron's</strong> comment</p>

<p>From what I understand, Phonemes are the basic sounds of the language. So, why do I need a neural network to map phoneme labels with speech? Can't I just say, "whenever you see this alphabet, pronounce it like <em>this</em>". After all, this language, Kannada, is phonetic: There are no silent words. All words are pronounced the same way they are spelled. How would a Neural Network help here then?</p>

<p>On input of a new text, I just need to break it down to the corresponding alphabets (which are also the phonemes) and retrieve it's file (converted from WAV to raw byte data). Now, merge the bytes together and convert it to a wav file.</p>

<p>Is this this too simplistic? Am I missing something here? What would be the point of a Neural Network for this particular language (Kannada) ?</p>