\label{index_md_README}%
\Hypertarget{index_md_README}%
 Microcontrollers do not have enough resources to provide a high quality \textquotesingle{}Text to Speech\textquotesingle{} functionality. However, often it might be good enough to provide a solution which is based on some pre-\/recorded audio.

I was wondering about the limitations of this approach and decided to implement a small prototype Arduino library that is based on the \href{https://github.com/pschatzmann/arduino-audio-tools}{\texttt{ Arduino Audio Tools}} for the audio output.

To keep things simple I started with a simple implementation that can process numbers and on top of that another one which reads out the time. So the starting point are some classes that translate numbers to text. The text is then used to identify the pre-\/recorded audio files.

This functionality can be used e.\+g. to build some


\begin{DoxyItemize}
\item talking clocks
\item talking scales
\end{DoxyItemize}\hypertarget{index_autotoc_md1}{}\doxysection{Conversion to Text Representation}\label{index_autotoc_md1}
\hypertarget{index_autotoc_md2}{}\doxysubsection{Numbers to Text}\label{index_autotoc_md2}
Number\+To\+Text translates the number input into a audio\+\_\+tools\+::\+Vector of words. In the following examples we just print them out\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{NumberToText\ ntt;}
\DoxyCodeLine{}
\DoxyCodeLine{auto\ result\ =\ ntt.say(700123.431);}
\DoxyCodeLine{}
\DoxyCodeLine{for\ (auto\ str\ :\ result)\{}
\DoxyCodeLine{\ \ \ \ Serial.print(str);}
\DoxyCodeLine{\ \ \ \ Serial.print("{}\ "{});}
\DoxyCodeLine{\}}

\end{DoxyCode}
 The result is\+: SEVEN HUNDRED THOUSAND ONE HUNDRED AND TWENTY THREE DOT FOUR THREE ONE ZERO ZERO ZERO\hypertarget{index_autotoc_md3}{}\doxysubsection{Time to Text}\label{index_autotoc_md3}
To process the time you need to provide the hours and minuts as input.


\begin{DoxyCode}{0}
\DoxyCodeLine{TimeToText\ ttt;}
\DoxyCodeLine{}
\DoxyCodeLine{auto\ result\ =\ ttt.say(12,\ 00);}
\DoxyCodeLine{}
\DoxyCodeLine{for\ (auto\ str\ :\ result)\{}
\DoxyCodeLine{\ \ \ \ Serial.print(str);}
\DoxyCodeLine{\ \ \ \ Serial.print("{}\ "{});}
\DoxyCodeLine{\}}

\end{DoxyCode}
 The result is\+: NOON\hypertarget{index_autotoc_md4}{}\doxysubsection{Numbers with Units}\label{index_autotoc_md4}
You can also process numbers with the corresponding units 
\begin{DoxyCode}{0}
\DoxyCodeLine{NumberUnitToText\ utt;}
\DoxyCodeLine{}
\DoxyCodeLine{auto\ result\ =\ utt.say(1.01,"{}usd"{});}
\DoxyCodeLine{}
\DoxyCodeLine{for\ (auto\ str\ :\ result)\{}
\DoxyCodeLine{\ \ \ \ Serial.print(str);}
\DoxyCodeLine{\ \ \ \ Serial.print("{}\ "{});}
\DoxyCodeLine{\}}

\end{DoxyCode}
 The result is\+: ONE u.\+s. dollar AND ONE cent\hypertarget{index_autotoc_md5}{}\doxysection{Text to Speech}\label{index_autotoc_md5}
If we record the words in mp3 we might even get away with the need for a separate SD drive because we can store the audio in program memory. The Example\+Audio\+Dictionary\+Values contains the prerecorded mp3 files which are stored in the PROGMEM.


\begin{DoxyCode}{0}
\DoxyCodeLine{\#include\ "{}SimpleTTS.h"{}}
\DoxyCodeLine{\#include\ "{}AudioCodecs/CodecMP3Helix.h"{}}
\DoxyCodeLine{}
\DoxyCodeLine{I2SStream\ i2s;\ \ //\ audio\ output\ via\ I2S}
\DoxyCodeLine{MP3DecoderHelix\ mp3;\ \ //\ mp3\ decoder}
\DoxyCodeLine{AudioDictionary\ dictionary(ExampleAudioDictionaryValues);}
\DoxyCodeLine{TextToSpeech\ tts(i2s,\ mp3,\ dictionary);}
\DoxyCodeLine{}
\DoxyCodeLine{void\ setup()\{}
\DoxyCodeLine{\ \ \ \ Serial.begin(115200);}
\DoxyCodeLine{\ \ \ \ //\ setup\ i2s}
\DoxyCodeLine{\ \ \ \ auto\ cfg\ =\ i2s.defaultConfig();\ }
\DoxyCodeLine{\ \ \ \ cfg.sample\_rate\ =\ 24000;}
\DoxyCodeLine{\ \ \ \ cfg.channels\ =\ 1;}
\DoxyCodeLine{\ \ \ \ i2s.begin(cfg);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ tts.say("{}BILLION"{});}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{void\ loop()\ \{}
\DoxyCodeLine{\}}

\end{DoxyCode}
 The word \char`\"{}\+Billion\char`\"{} is spoken out via I2S.

You can also use the text generation classes described above\+:


\begin{DoxyCode}{0}
\DoxyCodeLine{\#include\ "{}SimpleTTS.h"{}}
\DoxyCodeLine{\#include\ "{}AudioCodecs/CodecMP3Helix.h"{}}
\DoxyCodeLine{}
\DoxyCodeLine{TimeToText\ ttt;\ //\ Text\ source}
\DoxyCodeLine{I2SStream\ i2s;\ \ //\ audio\ output\ via\ I2S}
\DoxyCodeLine{MP3DecoderHelix\ mp3;\ \ //\ mp3\ decoder}
\DoxyCodeLine{AudioDictionary\ dictionary(ExampleAudioDictionaryValues);}
\DoxyCodeLine{TextToSpeech\ tts(ttt,\ i2s,\ mp3,\ dictionary);}
\DoxyCodeLine{}
\DoxyCodeLine{void\ setup()\{}
\DoxyCodeLine{\ \ \ \ Serial.begin(115200);}
\DoxyCodeLine{\ \ \ \ //\ setup\ i2s}
\DoxyCodeLine{\ \ \ \ auto\ cfg\ =\ i2s.defaultConfig();\ }
\DoxyCodeLine{\ \ \ \ cfg.sample\_rate\ =\ 24000;}
\DoxyCodeLine{\ \ \ \ cfg.channels\ =\ 1;}
\DoxyCodeLine{\ \ \ \ i2s.begin(cfg);}
\DoxyCodeLine{}
\DoxyCodeLine{\ \ \ \ ttt.say(14,40);}
\DoxyCodeLine{\}}
\DoxyCodeLine{}
\DoxyCodeLine{void\ loop()\ \{}
\DoxyCodeLine{\}}

\end{DoxyCode}
 This will output the audio result via I2S.\hypertarget{index_autotoc_md6}{}\doxysection{Memory Usage}\label{index_autotoc_md6}
Here is the info for a sketch that provides talking time and number support and stores all audio files as mp3 in PROGMEM on as ESP32\+: 
\begin{DoxyCode}{0}
\DoxyCodeLine{Sketch\ uses\ 740438\ bytes\ (23\%)\ of\ program\ storage\ space.\ Maximum\ is\ 3145728\ bytes.}
\DoxyCodeLine{Global\ variables\ use\ 23632\ bytes\ (7\%)\ of\ dynamic\ memory,\ leaving\ 304048\ bytes\ for\ }

\end{DoxyCode}


I think this leave plenty of headroom and you still have the option to store the {\bfseries{audio on an SD drive}}...\hypertarget{index_autotoc_md7}{}\doxysection{Documentation}\label{index_autotoc_md7}
Here is the \href{https://pschatzmann.github.io/arduino-simple-tts/docs/html/annotated.html}{\texttt{ link to the generated class documentation}}. Further information can be found in the \href{https://github.com/pschatzmann/arduino-simple-tts/wiki}{\texttt{ Wiki}} and in my \href{https://www.pschatzmann.ch/home/tag/tts/}{\texttt{ Blogs}}\hypertarget{index_autotoc_md8}{}\doxysection{Dependencies}\label{index_autotoc_md8}

\begin{DoxyItemize}
\item \href{https://github.com/pschatzmann/arduino-audio-tools}{\texttt{ Arduino Audio Tools}} -\/ mandatory
\item \href{https://github.com/pschatzmann/arduino-libhelix}{\texttt{ arduino-\/libhelix}} A {\bfseries{MP3 and AAC Decoder}} from Realnetworks -\/ mandatory if you use the mp3 of the examles
\item \href{https://github.com/greiman/SdFat}{\texttt{ Sd\+Fat Library}} -\/ optional for SD examples (or you can use the SD library instead\+: see Wiki)
\item \href{https://github.com/pschatzmann/arduino-audiokit}{\texttt{ Arduino Audio\+Kit}} -\/ optional if you use the Audio\+Kit (alternatively you can just replace the Audio\+Kit\+Stream in the examples with e.\+g. an I2\+SStream) 
\end{DoxyItemize}