\hypertarget{_simple_t_t_s_base_8h_source}{}\doxysection{Simple\+TTSBase.\+h}
\label{_simple_t_t_s_base_8h_source}\index{src/SimpleTTSBase.h@{src/SimpleTTSBase.h}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{preprocessor}{\#pragma\ once}}
\DoxyCodeLine{00002\ \textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{00003\ \textcolor{preprocessor}{\#include\ <string.h>}}
\DoxyCodeLine{00004\ \textcolor{preprocessor}{\#include\ <stdlib.h>}}
\DoxyCodeLine{00005\ }
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#include\ "{}AudioTools.h"{}}}
\DoxyCodeLine{00007\ }
\DoxyCodeLine{00008\ \textcolor{keyword}{namespace\ }simple\_tts\ \{}
\DoxyCodeLine{00009\ }
\DoxyCodeLine{00015\ \textcolor{keyword}{class\ }\mbox{\hyperlink{classsimple__tts_1_1_simple_t_t_s_base}{SimpleTTSBase}}\ \{}
\DoxyCodeLine{00016\ \ \textcolor{keyword}{public}:}
\DoxyCodeLine{00017\ \ \ \textcolor{keyword}{virtual}\ audio\_tools::Vector<const\ char*>\&\ allTexts()\ =\ 0;}
\DoxyCodeLine{00018\ \ \ \textcolor{keyword}{virtual}\ \textcolor{keywordtype}{void}\ registerCallback(}
\DoxyCodeLine{00019\ \ \ \ \ \ \ \textcolor{keywordtype}{void}\ (*ptr)(audio\_tools::Vector<const\ char*>\ words,\ \textcolor{keywordtype}{void}*\ refx),}
\DoxyCodeLine{00020\ \ \ \ \ \ \ \textcolor{keywordtype}{void}*\ ref)\ \{}
\DoxyCodeLine{00021\ \ \ \ \ callback\ =\ ptr;}
\DoxyCodeLine{00022\ \ \ \ \ reference\ =\ ref;}
\DoxyCodeLine{00023\ \ \ \}}
\DoxyCodeLine{00024\ }
\DoxyCodeLine{00025\ \ \ \textcolor{comment}{//\ Creates\ all\ missing\ audio\ recording\ files\ for\ the\ indicated\ source.\ We\ make\ sure}}
\DoxyCodeLine{00026\ \ \ \textcolor{comment}{//\ that\ the\ output\ is\ lowercase}}
\DoxyCodeLine{00027\ \ \ \textcolor{keywordtype}{void}\ printCSV(Print\ \&out)\ \{}
\DoxyCodeLine{00028\ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{auto}\ txt\ :\ allTexts())\ \{}
\DoxyCodeLine{00029\ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (txt!=\textcolor{keyword}{nullptr}\ \&\&\ strlen(txt)>0)\{}
\DoxyCodeLine{00030\ \ \ \ \ \ \ \ \ StrExt\ str\ =\ txt;\ }
\DoxyCodeLine{00031\ \ \ \ \ \ \ \ \ str.toLowerCase();\ \textcolor{comment}{//\ convert\ txt\ to\ lowercase}}
\DoxyCodeLine{00032\ \ \ \ \ \ \ \ \ out.print(str.c\_str());}
\DoxyCodeLine{00033\ \ \ \ \ \ \ \ \ out.print(\textcolor{stringliteral}{"{},"{}});}
\DoxyCodeLine{00034\ \ \ \ \ \ \ \ \ out.println(str.c\_str());}
\DoxyCodeLine{00035\ \ \ \ \ \ \ \}}
\DoxyCodeLine{00036\ \ \ \ \ \}}
\DoxyCodeLine{00037\ \ \ \}}
\DoxyCodeLine{00038\ }
\DoxyCodeLine{00039\ \ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00040\ \ \ void\ (*callback)(audio\_tools::Vector<const\ char*>\ word,\ \textcolor{keywordtype}{void}*\ ref)\ =\ \textcolor{keyword}{nullptr};}
\DoxyCodeLine{00041\ \ \ \textcolor{keywordtype}{void}*\ reference\ =\ \textcolor{keyword}{nullptr};}
\DoxyCodeLine{00042\ \};}
\DoxyCodeLine{00043\ }
\DoxyCodeLine{00049\ \textcolor{keyword}{class\ }\mbox{\hyperlink{classsimple__tts_1_1_audio_dictionary_base}{AudioDictionaryBase}}\ \{}
\DoxyCodeLine{00050\ \ \textcolor{keyword}{public}:}
\DoxyCodeLine{00051\ \ \ \textcolor{keyword}{virtual}\ AudioStream*\ get(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}*\ word)\ =\ 0;}
\DoxyCodeLine{00052\ \};}
\DoxyCodeLine{00053\ }
\DoxyCodeLine{00060\ \textcolor{keyword}{struct\ }\mbox{\hyperlink{structsimple__tts_1_1_audio_dictionary_entry}{AudioDictionaryEntry}}\ \{}
\DoxyCodeLine{00061\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}*\ name;}
\DoxyCodeLine{00062\ \ \ AudioStream*\ audio;}
\DoxyCodeLine{00063\ \};}
\DoxyCodeLine{00064\ }
\DoxyCodeLine{00072\ \textcolor{keyword}{struct\ }\mbox{\hyperlink{structsimple__tts_1_1_audio_s_d_entry}{AudioSDEntry}}\ \{}
\DoxyCodeLine{00073\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}*\ name;}
\DoxyCodeLine{00074\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}*\ text\ =\ \textcolor{keyword}{nullptr};\ \ \textcolor{comment}{//\ optional\ -\/\ when\ different\ from\ name}}
\DoxyCodeLine{00075\ \};}
\DoxyCodeLine{00076\ }
\DoxyCodeLine{00083\ \textcolor{keyword}{struct\ }\mbox{\hyperlink{structsimple__tts_1_1_simple_time}{SimpleTime}}\ \{}
\DoxyCodeLine{00084\ \ \ \textcolor{keywordtype}{int}\ hour\ =\ 0;}
\DoxyCodeLine{00085\ \ \ \textcolor{keywordtype}{int}\ minute\ =\ 0;}
\DoxyCodeLine{00086\ \ \ \mbox{\hyperlink{structsimple__tts_1_1_simple_time}{SimpleTime}}()\ =\ \textcolor{keywordflow}{default};}
\DoxyCodeLine{00087\ \ \ \mbox{\hyperlink{structsimple__tts_1_1_simple_time}{SimpleTime}}(\textcolor{keywordtype}{int}\ hour,\ \textcolor{keywordtype}{int}\ minutes)\ \{}
\DoxyCodeLine{00088\ \ \ \ \ this-\/>hour\ =\ hour;}
\DoxyCodeLine{00089\ \ \ \ \ this-\/>minute\ =\ minutes;}
\DoxyCodeLine{00090\ \ \ \}}
\DoxyCodeLine{00091\ \ \ \textcolor{keywordtype}{bool}\ operator==(\textcolor{keyword}{const}\ \mbox{\hyperlink{structsimple__tts_1_1_simple_time}{SimpleTime}}\&\ alt)\ \{}
\DoxyCodeLine{00092\ \ \ \ \ \textcolor{keywordflow}{return}\ alt.hour\ ==\ hour\ \&\&\ alt.minute\ ==\ minute;}
\DoxyCodeLine{00093\ \ \ \}}
\DoxyCodeLine{00094\ \ \ \textcolor{keywordtype}{bool}\ operator!=(\textcolor{keyword}{const}\ \mbox{\hyperlink{structsimple__tts_1_1_simple_time}{SimpleTime}}\&\ alt)\ \{}
\DoxyCodeLine{00095\ \ \ \ \ \textcolor{keywordflow}{return}\ alt.hour\ !=\ hour\ ||\ alt.minute\ !=\ minute;}
\DoxyCodeLine{00096\ \ \ \}}
\DoxyCodeLine{00097\ \};}
\DoxyCodeLine{00098\ }
\DoxyCodeLine{00106\ \textcolor{keyword}{class\ }\mbox{\hyperlink{classsimple__tts_1_1_number}{Number}}\ \{}
\DoxyCodeLine{00107\ \textcolor{keyword}{public}:}
\DoxyCodeLine{00108\ \ \ \textcolor{keywordtype}{void}\ set(\textcolor{keywordtype}{double}\ value,\ \textcolor{keywordtype}{int}\ digits=2)\ \{}
\DoxyCodeLine{00109\ \ \ \ \ \textcolor{keywordtype}{char}\ format[10];}
\DoxyCodeLine{00110\ \ \ \ \ \textcolor{comment}{//\ e.g.\ \%0.2f\ for\ 2\ digits.}}
\DoxyCodeLine{00111\ \ \ \ \ sprintf(format,\textcolor{stringliteral}{"{}\%\%0.\%df"{}},\ digits);}
\DoxyCodeLine{00112\ \ \ \ \ LOGD(\textcolor{stringliteral}{"{}format:\ \%s"{}},\ format);}
\DoxyCodeLine{00113\ \ \ \ \ memset(buffer,\ 0,\ buffer\_len);}
\DoxyCodeLine{00114\ \ \ \ \ \textcolor{comment}{//\ convert\ to\ string}}
\DoxyCodeLine{00115\ \ \ \ \ sprintf(buffer,\ format,\ value);}
\DoxyCodeLine{00116\ \ \ \ \ LOGD(\textcolor{stringliteral}{"{}number:\ \%s"{}},buffer);}
\DoxyCodeLine{00117\ \ \ \ \ dot\ =\ strchr(buffer,\ \textcolor{charliteral}{'.'});}
\DoxyCodeLine{00118\ \ \ \ \ \textcolor{keywordflow}{if}\ (dot!=\textcolor{keyword}{nullptr})\{}
\DoxyCodeLine{00119\ \ \ \ \ \ \ \textcolor{comment}{//\ split\ string}}
\DoxyCodeLine{00120\ \ \ \ \ \ \ *dot\ =\ 0;}
\DoxyCodeLine{00121\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00122\ \ \ \ \ \ \ \textcolor{comment}{//\ no\ decimal}}
\DoxyCodeLine{00123\ \ \ \ \ \ \ dot\ =\ buffer+strlen(buffer);}
\DoxyCodeLine{00124\ \ \ \ \ \}}
\DoxyCodeLine{00125\ }
\DoxyCodeLine{00126\ \ \ \ \ LOGD(\textcolor{stringliteral}{"{}int:\ \%s"{}},\ \mbox{\hyperlink{classsimple__tts_1_1_number_a0768e8ce47dff8521cec1e662587da32}{intValue}}());}
\DoxyCodeLine{00127\ \ \ \ \ LOGD(\textcolor{stringliteral}{"{}dec:\ \%s"{}},\ \mbox{\hyperlink{classsimple__tts_1_1_number_a33e8504471cb6f4ab31a43b178ec26e5}{decValues}}());}
\DoxyCodeLine{00128\ \ \ \}}
\DoxyCodeLine{00129\ }
\DoxyCodeLine{00130\ \ \ \textcolor{keywordtype}{void}\ set(int64\_t\ wholeNumber)\ \{}
\DoxyCodeLine{00131\ \ \ \ \ memset(buffer,0,buffer\_len);}
\DoxyCodeLine{00132\ \ \ \ \ \textcolor{comment}{//\ convert\ to\ string}}
\DoxyCodeLine{00133\ \ \ \ \ sprintf(buffer,\ \textcolor{stringliteral}{"{}\%lld"{}},\ wholeNumber);}
\DoxyCodeLine{00134\ \ \ \ \ \textcolor{comment}{//ltoa(wholeNumber,\ buffer,\ 10);}}
\DoxyCodeLine{00135\ \ \ \ \ dot\ =\ buffer+strlen(buffer);}
\DoxyCodeLine{00136\ \ \ \}}
\DoxyCodeLine{00137\ }
\DoxyCodeLine{00139\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}*\ \mbox{\hyperlink{classsimple__tts_1_1_number_a0768e8ce47dff8521cec1e662587da32}{intValue}}()\ \{}
\DoxyCodeLine{00140\ \ \ \ \ \textcolor{keywordflow}{return}\ buffer;}
\DoxyCodeLine{00141\ \ \ \}}
\DoxyCodeLine{00142\ }
\DoxyCodeLine{00144\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}*\ \mbox{\hyperlink{classsimple__tts_1_1_number_a33e8504471cb6f4ab31a43b178ec26e5}{decValues}}()\ \{}
\DoxyCodeLine{00145\ \ \ \ \ \textcolor{keywordflow}{return}\ dot+1;}
\DoxyCodeLine{00146\ \ \ \}}
\DoxyCodeLine{00147\ }
\DoxyCodeLine{00148\ \ \ \textcolor{comment}{//\ converts\ a\ decimal\ to\ a\ full\ number:\ 1\ gives\ 10,\ 01\ dives\ 1\ if\ digits\ are\ 2.\ This\ is\ used\ e.g.\ for\ USD\ 1.1\ which}}
\DoxyCodeLine{00149\ \ \ \textcolor{comment}{//\ will\ need\ to\ render\ 1\ dollar\ and\ 10\ cents;\ attn:\ 1.101\ should\ still\ give\ 10\ cents!}}
\DoxyCodeLine{00150\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}*\ decAsInt(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}*\ decimals,\ \textcolor{keywordtype}{int}\ digits)\{}
\DoxyCodeLine{00151\ \ \ \ \ memset(buffer,\ 0,\ buffer\_len);}
\DoxyCodeLine{00152\ \ \ \ \ memset(buffer,\textcolor{charliteral}{'0'},\ digits);}
\DoxyCodeLine{00153\ \ \ \ \ \textcolor{keywordtype}{int}\ len\ =\ min((\textcolor{keywordtype}{int})strlen(decimals),digits);}
\DoxyCodeLine{00154\ \ \ \ \ memcpy(buffer,\ decimals,\ len);}
\DoxyCodeLine{00155\ \ \ \ \ \textcolor{keywordflow}{return}\ buffer;}
\DoxyCodeLine{00156\ \ \ \}}
\DoxyCodeLine{00157\ }
\DoxyCodeLine{00158\ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00159\ \ \ \ \ \textcolor{comment}{//\ convert\ to\ string}}
\DoxyCodeLine{00160\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ buffer\_len\ =\ 100;}
\DoxyCodeLine{00161\ \ \ \ \ \textcolor{keywordtype}{char}\ buffer[buffer\_len];}
\DoxyCodeLine{00162\ \ \ \ \ \textcolor{keywordtype}{char}*\ dot=buffer;}
\DoxyCodeLine{00163\ }
\DoxyCodeLine{00164\ \};}
\DoxyCodeLine{00165\ }
\DoxyCodeLine{00166\ \}\ \ \textcolor{comment}{//\ namespace\ simple\_tts}}

\end{DoxyCode}
