\hypertarget{_time_to_text_8h_source}{}\doxysection{Time\+To\+Text.\+h}
\label{_time_to_text_8h_source}\index{src/TimeToText.h@{src/TimeToText.h}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{preprocessor}{\#pragma\ once}}
\DoxyCodeLine{00002\ \textcolor{preprocessor}{\#include\ "{}NumberToText.h"{}}}
\DoxyCodeLine{00003\ }
\DoxyCodeLine{00004\ \textcolor{keyword}{namespace\ }simple\_tts\ \{}
\DoxyCodeLine{00005\ }
\DoxyCodeLine{00012\ \textcolor{keyword}{class\ }\mbox{\hyperlink{classsimple__tts_1_1_time_to_text}{TimeToText}}\ :\ \textcolor{keyword}{public}\ \mbox{\hyperlink{classsimple__tts_1_1_simple_t_t_s_base}{SimpleTTSBase}}\ \{}
\DoxyCodeLine{00013\ \ \textcolor{keyword}{public}:}
\DoxyCodeLine{00015\ \ \ audio\_tools::Vector<const\ char\ *>\ \&\mbox{\hyperlink{classsimple__tts_1_1_time_to_text_a65c5d0ca832cda665a63697293f94fb7}{say}}(\textcolor{keywordtype}{int}\ hour,\ \textcolor{keywordtype}{int}\ minutes)\ \{}
\DoxyCodeLine{00016\ \ \ \ \ \mbox{\hyperlink{structsimple__tts_1_1_simple_time}{SimpleTime}}\ time(hour,minutes);}
\DoxyCodeLine{00017\ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{classsimple__tts_1_1_time_to_text_a65c5d0ca832cda665a63697293f94fb7}{say}}(time);}
\DoxyCodeLine{00018\ \ \ \}}
\DoxyCodeLine{00019\ }
\DoxyCodeLine{00021\ \ \ audio\_tools::Vector<const\ char\ *>\ \&\mbox{\hyperlink{classsimple__tts_1_1_time_to_text_a3fea7fbf6c9cc754049c144c8fdfffd5}{say}}(\mbox{\hyperlink{structsimple__tts_1_1_simple_time}{SimpleTime}}\ time)\ \{}
\DoxyCodeLine{00022\ \ \ \ \ result.clear();}
\DoxyCodeLine{00023\ \ \ \ \ LOGI(\textcolor{stringliteral}{"{}say:\ \%d:\%d"{}},time.hour,\ time.minute);}
\DoxyCodeLine{00024\ \ \ \ \ \textcolor{keywordflow}{if}\ (time.minute\ <\ 0\ ||\ time.minute\ >=\ 60)\ \{}
\DoxyCodeLine{00025\ \ \ \ \ \ \ LOGE(\textcolor{stringliteral}{"{}Invalid\ minute\ (range\ 0-\/59):\ \%d"{}},\ time.minute);}
\DoxyCodeLine{00026\ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ result;}
\DoxyCodeLine{00027\ \ \ \ \ \}}
\DoxyCodeLine{00028\ \ \ \ \ \textcolor{keywordflow}{if}\ (time.hour\ <\ 0\ ||\ time.hour\ >\ 24)\ \{}
\DoxyCodeLine{00029\ \ \ \ \ \ \ LOGE(\textcolor{stringliteral}{"{}Invalid\ hour\ (range\ 0-\/24):\ \%d"{}},\ time.hour);}
\DoxyCodeLine{00030\ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ result;}
\DoxyCodeLine{00031\ \ \ \ \ \}}
\DoxyCodeLine{00032\ }
\DoxyCodeLine{00033\ \ \ \ \ process(time);}
\DoxyCodeLine{00034\ }
\DoxyCodeLine{00035\ \ \ \ \ \textcolor{comment}{//\ provide\ result\ to\ callback}}
\DoxyCodeLine{00036\ \ \ \ \ \textcolor{keywordflow}{if}\ (callback)\{}
\DoxyCodeLine{00037\ \ \ \ \ \ \ \ \ callback(result,\ reference);}
\DoxyCodeLine{00038\ \ \ \ \ \}}
\DoxyCodeLine{00039\ }
\DoxyCodeLine{00040\ \ \ \ \ \textcolor{keywordflow}{return}\ result;}
\DoxyCodeLine{00041\ \ \ \}}
\DoxyCodeLine{00042\ }
\DoxyCodeLine{00044\ \ \ audio\_tools::Vector<const\ char\ *>\ \&\mbox{\hyperlink{classsimple__tts_1_1_time_to_text_a74b2534f6c65dc2f3a5403952ff80690}{allTexts}}()\ \{}
\DoxyCodeLine{00045\ \ \ \ \ result.clear();}
\DoxyCodeLine{00046\ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keywordtype}{int}\ j\ =\ 0;\ j\ <\ 10;\ j++)\ \{}
\DoxyCodeLine{00047\ \ \ \ \ \ \ add(j);}
\DoxyCodeLine{00048\ \ \ \ \ \}}
\DoxyCodeLine{00049\ \ \ \ \ \textcolor{keywordflow}{return}\ result;}
\DoxyCodeLine{00050\ \ \ \}}
\DoxyCodeLine{00051\ }
\DoxyCodeLine{00052\ \ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00053\ \ \ audio\_tools::Vector<const\ char\ *>\ result;}
\DoxyCodeLine{00054\ \ \ \mbox{\hyperlink{classsimple__tts_1_1_number_to_text}{NumberToText}}\ ntt;}
\DoxyCodeLine{00055\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ ITS\ =\ 0;}
\DoxyCodeLine{00056\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ NOON\ =\ 1;}
\DoxyCodeLine{00057\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ MIDNIGHT\ =\ 2;}
\DoxyCodeLine{00058\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ OCLOCK\ =\ 3;}
\DoxyCodeLine{00059\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ TO\ =\ 4;}
\DoxyCodeLine{00060\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ PAST\ =\ 5;}
\DoxyCodeLine{00061\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ AM\ =\ 6;}
\DoxyCodeLine{00062\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ PM\ =\ 7;}
\DoxyCodeLine{00063\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ HALF\ =\ 8;}
\DoxyCodeLine{00064\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ QUARTER\ =\ 9;}
\DoxyCodeLine{00065\ }
\DoxyCodeLine{00066\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *words[10]\ =\ \{\textcolor{stringliteral}{"{}ITS"{}},\ \textcolor{stringliteral}{"{}NOON"{}},\ \textcolor{stringliteral}{"{}MIDNIGHT"{}},\ \textcolor{stringliteral}{"{}OCLOCK"{}},\ \textcolor{stringliteral}{"{}TO"{}},}
\DoxyCodeLine{00067\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}PAST"{}},\ \textcolor{stringliteral}{"{}AM"{}},\ \ \ \textcolor{stringliteral}{"{}PM"{}},\ \ \ \ \ \ \ \textcolor{stringliteral}{"{}HALF"{}},\ \ \ \ \textcolor{stringliteral}{"{}QUARTER"{}}\};}
\DoxyCodeLine{00068\ }
\DoxyCodeLine{00069\ \ \ \textcolor{keywordtype}{void}\ add(\textcolor{keywordtype}{int}\ idx)\ \{\ add(words[idx]);\ \}}
\DoxyCodeLine{00070\ }
\DoxyCodeLine{00071\ \ \ \textcolor{keywordtype}{void}\ add(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *str)\ \{\ result.push\_back(str);\ \}}
\DoxyCodeLine{00072\ }
\DoxyCodeLine{00073\ \ \ \textcolor{keywordtype}{void}\ addAll(audio\_tools::Vector<const\ char\ *>\ \&words)\ \{}
\DoxyCodeLine{00074\ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{auto}\ word\ :\ words)\ \{}
\DoxyCodeLine{00075\ \ \ \ \ \ \ add(word);}
\DoxyCodeLine{00076\ \ \ \ \ \}}
\DoxyCodeLine{00077\ \ \ \}}
\DoxyCodeLine{00078\ }
\DoxyCodeLine{00079\ \ \ \textcolor{keywordtype}{void}\ process(SimpleTime\ time)\ \{}
\DoxyCodeLine{00080\ \ \ \ \ add(ITS);}
\DoxyCodeLine{00081\ \ \ \ \ \textcolor{comment}{//\ process\ exceptional\ times}}
\DoxyCodeLine{00082\ \ \ \ \ \textcolor{keywordflow}{if}\ (time.hour\ ==\ 12\ \&\&\ time.minute\ ==\ 00)\ \{}
\DoxyCodeLine{00083\ \ \ \ \ \ \ add(NOON);}
\DoxyCodeLine{00084\ \ \ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{00085\ \ \ \ \ \}}
\DoxyCodeLine{00086\ \ \ \ \ \textcolor{keywordflow}{if}\ (time.hour\ ==\ 0\ \&\&\ time.minute\ ==\ 00)\ \{}
\DoxyCodeLine{00087\ \ \ \ \ \ \ add(MIDNIGHT);}
\DoxyCodeLine{00088\ \ \ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{00089\ \ \ \ \ \}}
\DoxyCodeLine{00090\ }
\DoxyCodeLine{00091\ \ \ \ \ \textcolor{comment}{//\ add\ minutes}}
\DoxyCodeLine{00092\ \ \ \ \ processMinutes(time);}
\DoxyCodeLine{00093\ }
\DoxyCodeLine{00094\ \ \ \ \ \textcolor{comment}{//\ add\ hour}}
\DoxyCodeLine{00095\ \ \ \ \ \textcolor{keywordflow}{if}\ (time.hour\ <=\ 12)\ \{}
\DoxyCodeLine{00096\ \ \ \ \ \ \ processHourAM(time);}
\DoxyCodeLine{00097\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00098\ \ \ \ \ \ \ processHourPM(time);}
\DoxyCodeLine{00099\ \ \ \ \ \}}
\DoxyCodeLine{00100\ \ \ \ \ \textcolor{keywordflow}{return};}
\DoxyCodeLine{00101\ \ \ \}}
\DoxyCodeLine{00102\ }
\DoxyCodeLine{00103\ \ \ \textcolor{keywordtype}{void}\ processMinutes(SimpleTime\ \&time)\ \{}
\DoxyCodeLine{00104\ \ \ \ \ \textcolor{comment}{//\ process\ minutes}}
\DoxyCodeLine{00105\ \ \ \ \ \textcolor{keywordflow}{if}\ (time.minute\ ==\ 0)\ \{}
\DoxyCodeLine{00106\ \ \ \ \ \ \ \textcolor{comment}{//\ do\ nothing}}
\DoxyCodeLine{00107\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (time.minute\ ==\ 15)\ \{}
\DoxyCodeLine{00108\ \ \ \ \ \ \ add(QUARTER);}
\DoxyCodeLine{00109\ \ \ \ \ \ \ add(PAST);}
\DoxyCodeLine{00110\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (time.minute\ <\ 30)\ \{}
\DoxyCodeLine{00111\ \ \ \ \ \ \ addAll(ntt.\mbox{\hyperlink{classsimple__tts_1_1_number_to_text_aa5cb276b1a65ece56fcae76bb22b6e1d}{say}}(time.minute,0u));}
\DoxyCodeLine{00112\ \ \ \ \ \ \ add(PAST);}
\DoxyCodeLine{00113\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (time.minute\ ==\ 30)\ \{}
\DoxyCodeLine{00114\ \ \ \ \ \ \ add(HALF);}
\DoxyCodeLine{00115\ \ \ \ \ \ \ add(PAST);}
\DoxyCodeLine{00116\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (time.minute\ ==\ 45)\ \{}
\DoxyCodeLine{00117\ \ \ \ \ \ \ time.hour\ +=\ 1;}
\DoxyCodeLine{00118\ \ \ \ \ \ \ add(QUARTER);}
\DoxyCodeLine{00119\ \ \ \ \ \ \ add(TO);}
\DoxyCodeLine{00120\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (time.minute\ >\ 30)\ \{}
\DoxyCodeLine{00121\ \ \ \ \ \ \ time.hour\ +=\ 1;}
\DoxyCodeLine{00122\ \ \ \ \ \ \ time.minute\ =\ 60\ -\/\ time.minute;}
\DoxyCodeLine{00123\ \ \ \ \ \ \ addAll(ntt.\mbox{\hyperlink{classsimple__tts_1_1_number_to_text_aa5cb276b1a65ece56fcae76bb22b6e1d}{say}}(time.minute,0u));}
\DoxyCodeLine{00124\ \ \ \ \ \ \ add(TO);}
\DoxyCodeLine{00125\ \ \ \ \ \}}
\DoxyCodeLine{00126\ \ \ \}}
\DoxyCodeLine{00127\ }
\DoxyCodeLine{00128\ \ \ \textcolor{keywordtype}{void}\ processHourPM(SimpleTime\ time)\ \{}
\DoxyCodeLine{00129\ \ \ \ \ \textcolor{keywordtype}{int}\ hour\ =\ time.hour;}
\DoxyCodeLine{00130\ \ \ \ \ hour\ -\/=\ 12;}
\DoxyCodeLine{00131\ \ \ \ \ \textcolor{comment}{//\ we\ do\ not\ say\ 0pm\ -\/>\ 12pm}}
\DoxyCodeLine{00132\ \ \ \ \ \textcolor{keywordflow}{if}\ (hour\ ==\ 0)\ \{}
\DoxyCodeLine{00133\ \ \ \ \ \ \ hour\ =\ 12;}
\DoxyCodeLine{00134\ \ \ \ \ \}}
\DoxyCodeLine{00135\ \ \ \ \ addAll(ntt.\mbox{\hyperlink{classsimple__tts_1_1_number_to_text_aa5cb276b1a65ece56fcae76bb22b6e1d}{say}}(hour,0u));}
\DoxyCodeLine{00136\ }
\DoxyCodeLine{00137\ \ \ \ \ \textcolor{keywordflow}{if}\ (time.minute==0)\{}
\DoxyCodeLine{00138\ \ \ \ \ \ \ add(OCLOCK);}
\DoxyCodeLine{00139\ \ \ \ \ \}}
\DoxyCodeLine{00140\ }
\DoxyCodeLine{00141\ \ \ \ \ add(PM);}
\DoxyCodeLine{00142\ \ \ \}}
\DoxyCodeLine{00143\ }
\DoxyCodeLine{00144\ \ \ \textcolor{keywordtype}{void}\ processHourAM(SimpleTime\ time)\ \{}
\DoxyCodeLine{00145\ \ \ \ \ \textcolor{keywordtype}{int}\ hour\ =\ time.hour;}
\DoxyCodeLine{00146\ \ \ \ \ \textcolor{comment}{//\ we\ do\ not\ say\ 0am\ -\/>\ 12am}}
\DoxyCodeLine{00147\ \ \ \ \ \textcolor{keywordflow}{if}\ (hour\ ==\ 0)\ \{}
\DoxyCodeLine{00148\ \ \ \ \ \ \ hour\ =\ 12;}
\DoxyCodeLine{00149\ \ \ \ \ \}}
\DoxyCodeLine{00150\ \ \ \ \ addAll(ntt.\mbox{\hyperlink{classsimple__tts_1_1_number_to_text_aa5cb276b1a65ece56fcae76bb22b6e1d}{say}}(hour,0u));}
\DoxyCodeLine{00151\ }
\DoxyCodeLine{00152\ \ \ \ \ \textcolor{keywordflow}{if}\ (time.minute==0)\{}
\DoxyCodeLine{00153\ \ \ \ \ \ \ add(OCLOCK);}
\DoxyCodeLine{00154\ \ \ \ \ \}}
\DoxyCodeLine{00155\ }
\DoxyCodeLine{00156\ \ \ \ \ add(AM);}
\DoxyCodeLine{00157\ \ \ \}}
\DoxyCodeLine{00158\ \};}
\DoxyCodeLine{00159\ }
\DoxyCodeLine{00160\ \}\ \ \textcolor{comment}{//\ namespace\ simple\_tts}}

\end{DoxyCode}
