\hypertarget{_number_to_text_8h_source}{}\doxysection{Number\+To\+Text.\+h}
\label{_number_to_text_8h_source}\index{src/NumberToText.h@{src/NumberToText.h}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{preprocessor}{\#pragma\ once}}
\DoxyCodeLine{00002\ \textcolor{preprocessor}{\#include\ "{}SimpleTTSBase.h"{}}}
\DoxyCodeLine{00003\ \textcolor{preprocessor}{\#include\ "{}AudioBasic/Collections/Vector.h"{}}}
\DoxyCodeLine{00004\ \textcolor{preprocessor}{\#include\ <stdio.h>}}
\DoxyCodeLine{00005\ \textcolor{preprocessor}{\#include\ <string.h>}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#include\ <stdlib.h>}}
\DoxyCodeLine{00007\ }
\DoxyCodeLine{00008\ \textcolor{keyword}{namespace\ }simple\_tts\ \{}
\DoxyCodeLine{00009\ }
\DoxyCodeLine{00015\ \textcolor{keyword}{class\ }\mbox{\hyperlink{classsimple__tts_1_1_number_to_text}{NumberToText}}\ :\ \textcolor{keyword}{public}\ \mbox{\hyperlink{classsimple__tts_1_1_simple_t_t_s_base}{SimpleTTSBase}}\ \{}
\DoxyCodeLine{00016\ \ \textcolor{keyword}{public}:}
\DoxyCodeLine{00017\ }
\DoxyCodeLine{00019\ \ \ audio\_tools::Vector<const\ char*>\ \&\mbox{\hyperlink{classsimple__tts_1_1_number_to_text_aa5cb276b1a65ece56fcae76bb22b6e1d}{say}}(\textcolor{keywordtype}{double}\ value,\ \textcolor{keywordtype}{int}\ decimals=2)\ \{}
\DoxyCodeLine{00020\ \ \ \ \ \mbox{\hyperlink{classsimple__tts_1_1_number}{Number}}\ number;}
\DoxyCodeLine{00021\ \ \ \ \ number.set(value,\ decimals);}
\DoxyCodeLine{00022\ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{classsimple__tts_1_1_number_to_text_aa5cb276b1a65ece56fcae76bb22b6e1d}{say}}(number.\mbox{\hyperlink{classsimple__tts_1_1_number_a0768e8ce47dff8521cec1e662587da32}{intValue}}(),\ number.\mbox{\hyperlink{classsimple__tts_1_1_number_a33e8504471cb6f4ab31a43b178ec26e5}{decValues}}());}
\DoxyCodeLine{00023\ \ \ \}}
\DoxyCodeLine{00024\ }
\DoxyCodeLine{00025\ \ \ audio\_tools::Vector<const\ char*>\ \&\mbox{\hyperlink{classsimple__tts_1_1_number_to_text_aa5cb276b1a65ece56fcae76bb22b6e1d}{say}}(int64\_t\ wholeNumber)\ \{}
\DoxyCodeLine{00026\ \ \ \ \ \mbox{\hyperlink{classsimple__tts_1_1_number}{Number}}\ number;}
\DoxyCodeLine{00027\ \ \ \ \ number.set(wholeNumber);}
\DoxyCodeLine{00028\ \ \ \ \ \textcolor{keywordflow}{return}\ \mbox{\hyperlink{classsimple__tts_1_1_number_to_text_aa5cb276b1a65ece56fcae76bb22b6e1d}{say}}(number.\mbox{\hyperlink{classsimple__tts_1_1_number_a0768e8ce47dff8521cec1e662587da32}{intValue}}(),\ number.\mbox{\hyperlink{classsimple__tts_1_1_number_a33e8504471cb6f4ab31a43b178ec26e5}{decValues}}());}
\DoxyCodeLine{00029\ \ \ \}}
\DoxyCodeLine{00030\ }
\DoxyCodeLine{00032\ \ \ audio\_tools::Vector<const\ char*>\ \&\mbox{\hyperlink{classsimple__tts_1_1_number_to_text_a6ad6f5daf5caf6fbc9665947ee3cdc5d}{say}}(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}*\ wholeNumber,\ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}*\ decimals=\textcolor{stringliteral}{"{}"{}})\ \{}
\DoxyCodeLine{00033\ \ \ \ \ result.clear();}
\DoxyCodeLine{00034\ }
\DoxyCodeLine{00035\ \ \ \ \ LOGI(\textcolor{stringliteral}{"{}say(number='\%s',\ decimal='\%s')"{}},wholeNumber,\ decimals);}
\DoxyCodeLine{00036\ \ \ \ \ Str\ wn(wholeNumber);}
\DoxyCodeLine{00037\ \ \ \ \ wn.trim();}
\DoxyCodeLine{00038\ \ \ \ \ \textcolor{keywordflow}{if}\ (wn.startsWith(\textcolor{stringliteral}{"{}-\/"{}}))\{}
\DoxyCodeLine{00039\ \ \ \ \ \ \ add(third[MINUS]);}
\DoxyCodeLine{00040\ \ \ \ \ \}}
\DoxyCodeLine{00041\ }
\DoxyCodeLine{00042\ \ \ \ \ \textcolor{comment}{//\ number\ before\ decimals}}
\DoxyCodeLine{00043\ \ \ \ \ convert(wholeNumber);}
\DoxyCodeLine{00044\ \ }
\DoxyCodeLine{00045\ \ \ \ \ \textcolor{comment}{//\ add\ decimals}}
\DoxyCodeLine{00046\ \ \ \ \ \textcolor{keywordflow}{if}\ (Str(decimals).toLong()>0l)\{}
\DoxyCodeLine{00047\ \ \ \ \ \ \ convertDecimals(decimals);}
\DoxyCodeLine{00048\ \ \ \ \ \}}
\DoxyCodeLine{00049\ }
\DoxyCodeLine{00050\ \ \ \ \ \textcolor{comment}{//\ provide\ result\ to\ callback}}
\DoxyCodeLine{00051\ \ \ \ \ \textcolor{keywordflow}{if}\ (callback)\{}
\DoxyCodeLine{00052\ \ \ \ \ \ \ \ \ callback(result,\ reference);}
\DoxyCodeLine{00053\ \ \ \ \ \}}
\DoxyCodeLine{00054\ \ \ \ \ \textcolor{keywordflow}{return}\ result;}
\DoxyCodeLine{00055\ \ \ \}}
\DoxyCodeLine{00056\ }
\DoxyCodeLine{00058\ \ \ audio\_tools::Vector<const\ char*>\ \&\mbox{\hyperlink{classsimple__tts_1_1_number_to_text_ae7cdf641730a749293956193b785a772}{allTexts}}()\ \{}
\DoxyCodeLine{00059\ \ \ \ \ result.clear();}
\DoxyCodeLine{00060\ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keywordtype}{int}\ j=0;j<20;j++)\{}
\DoxyCodeLine{00061\ \ \ \ \ \ \ add(first[j]);}
\DoxyCodeLine{00062\ \ \ \ \ \}}
\DoxyCodeLine{00063\ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keywordtype}{int}\ j=0;j<10;j++)\{}
\DoxyCodeLine{00064\ \ \ \ \ \ \ add(second[j]);}
\DoxyCodeLine{00065\ \ \ \ \ \}}
\DoxyCodeLine{00066\ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keywordtype}{int}\ j=0;j<7;j++)\{}
\DoxyCodeLine{00067\ \ \ \ \ \ \ add(third[j]);}
\DoxyCodeLine{00068\ \ \ \ \ \}}
\DoxyCodeLine{00069\ \ \ \ \ \textcolor{keywordflow}{return}\ result;}
\DoxyCodeLine{00070\ \ \ \}}
\DoxyCodeLine{00071\ }
\DoxyCodeLine{00072\ \ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00073\ \ \ audio\_tools::Vector<const\ char*>\ result;}
\DoxyCodeLine{00074\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}*\ first[20]\ =\ \{\textcolor{stringliteral}{"{}ZERO"{}},\ \ \ \ \textcolor{stringliteral}{"{}ONE"{}},\ \ \ \ \ \ \ \textcolor{stringliteral}{"{}TWO"{}},\ \ \ \ \ \ \ \textcolor{stringliteral}{"{}THREE"{}},}
\DoxyCodeLine{00075\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}FOUR"{}},\ \ \ \ \textcolor{stringliteral}{"{}FIVE"{}},\ \ \ \ \ \ \textcolor{stringliteral}{"{}SIX"{}},\ \ \ \ \ \ \ \textcolor{stringliteral}{"{}SEVEN"{}},}
\DoxyCodeLine{00076\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}EIGHT"{}},\ \ \ \textcolor{stringliteral}{"{}NINE"{}},\ \ \ \ \ \ \textcolor{stringliteral}{"{}TEN"{}},\ \ \ \ \ \ \ \textcolor{stringliteral}{"{}ELEVEN"{}},}
\DoxyCodeLine{00077\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}TWELVE"{}},\ \ \textcolor{stringliteral}{"{}THIRTEEN"{}},\ \ \textcolor{stringliteral}{"{}FOURTEEN"{}},\ \ \textcolor{stringliteral}{"{}FIFTEEN"{}},}
\DoxyCodeLine{00078\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}SIXTEEN"{}},\ \textcolor{stringliteral}{"{}SEVENTEEN"{}},\ \textcolor{stringliteral}{"{}EIGHTEEN"{}},\ \ \textcolor{stringliteral}{"{}NINETEEN"{}}\};}
\DoxyCodeLine{00079\ }
\DoxyCodeLine{00080\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}*\ second[10]\ =\ \{\textcolor{stringliteral}{"{}"{}},\ \ \ \ \ \ \textcolor{stringliteral}{"{}TEN"{}},\ \ \ \textcolor{stringliteral}{"{}TWENTY"{}},\ \ \textcolor{stringliteral}{"{}THIRTY"{}},\ \textcolor{stringliteral}{"{}FORTY"{}},}
\DoxyCodeLine{00081\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{stringliteral}{"{}FIFTY"{}},\ \textcolor{stringliteral}{"{}SIXTY"{}},\ \textcolor{stringliteral}{"{}SEVENTY"{}},\ \textcolor{stringliteral}{"{}EIGHTY"{}},\ \textcolor{stringliteral}{"{}NINETY"{}}\};}
\DoxyCodeLine{00082\ }
\DoxyCodeLine{00083\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}*\ third[7]\ =\ \{\textcolor{stringliteral}{"{}AND"{}},\textcolor{stringliteral}{"{}DOT"{}},\textcolor{stringliteral}{"{}MINUS"{}},\ \textcolor{stringliteral}{"{}HUNDRED"{}},\ \textcolor{stringliteral}{"{}THOUSAND"{}},\ \textcolor{stringliteral}{"{}MILLION"{}},\textcolor{stringliteral}{"{}BILLION"{}}\};}
\DoxyCodeLine{00084\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ AND\ =\ 0;}
\DoxyCodeLine{00085\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ DOT\ =\ 1;}
\DoxyCodeLine{00086\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ MINUS\ =\ 2;}
\DoxyCodeLine{00087\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ HUNDRED\ =\ 3;}
\DoxyCodeLine{00088\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ THOUSAND\ =\ 4;}
\DoxyCodeLine{00089\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ MILLION\ =\ 5;}
\DoxyCodeLine{00090\ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{int}\ BILLION\ =\ 6;}
\DoxyCodeLine{00091\ }
\DoxyCodeLine{00092\ \ \ \textcolor{keywordtype}{void}\ add(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}*\ str)\{}
\DoxyCodeLine{00093\ \ \ \ \ result.push\_back(str);}
\DoxyCodeLine{00094\ \ \ \}}
\DoxyCodeLine{00095\ }
\DoxyCodeLine{00096\ \ \ \textcolor{keywordtype}{void}\ convertDecimals(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}*\ decimals)\ \{}
\DoxyCodeLine{00097\ \ \ \ \ Str\ dec(decimals);}
\DoxyCodeLine{00098\ \ \ \ \ \textcolor{keywordflow}{if}\ (dec.toInt()!=0.0)\{}
\DoxyCodeLine{00099\ \ \ \ \ \ \ \textcolor{keyword}{const}\ \textcolor{keywordtype}{char}*\ ch=decimals;}
\DoxyCodeLine{00100\ \ \ \ \ \ \ add(third[DOT]);}
\DoxyCodeLine{00101\ \ \ \ \ \ \ \textcolor{keywordflow}{while}\ (*ch)\{}
\DoxyCodeLine{00102\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{int}\ idx\ =\ (*ch)-\/48;\ \textcolor{comment}{//\ convert\ to\ index}}
\DoxyCodeLine{00103\ \ \ \ \ \ \ \ \ add(first[idx]);}
\DoxyCodeLine{00104\ \ \ \ \ \ \ \ \ ch++;}
\DoxyCodeLine{00105\ \ \ \ \ \ \ \}}
\DoxyCodeLine{00106\ \ \ \ \ \}}
\DoxyCodeLine{00107\ \ \ \}}
\DoxyCodeLine{00108\ \ \ \textcolor{keywordtype}{void}\ convert(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}*\ strValue)\{}
\DoxyCodeLine{00109\ \ \ \ \ convert(Str(strValue).toLong());}
\DoxyCodeLine{00110\ \ \ \}}
\DoxyCodeLine{00111\ }
\DoxyCodeLine{00112\ \ \ \textcolor{comment}{//\ TODO:\ convert\ to\ string\ operations}}
\DoxyCodeLine{00113\ \ \ \textcolor{keywordtype}{void}\ convert(int64\_t\ value)\{}
\DoxyCodeLine{00114\ \ \ \ \ \textcolor{keywordflow}{if}\ (value\ <\ 0)\ \{}
\DoxyCodeLine{00115\ \ \ \ \ \ \ convert(-\/value);}
\DoxyCodeLine{00116\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (value\ >=\ 1000000000)\ \{}
\DoxyCodeLine{00117\ \ \ \ \ \ \ convert(value\ /\ 1000000000);}
\DoxyCodeLine{00118\ \ \ \ \ \ \ add(third[BILLION]);}
\DoxyCodeLine{00119\ \ \ \ \ \ \ int64\_t\ remainder\ =\ value\%1000000000;}
\DoxyCodeLine{00120\ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (remainder)\ convert(remainder);}
\DoxyCodeLine{00121\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (value\ >=\ 1000000)\ \{}
\DoxyCodeLine{00122\ \ \ \ \ \ \ convert(value\ /\ 1000000);}
\DoxyCodeLine{00123\ \ \ \ \ \ \ add(third[MILLION]);}
\DoxyCodeLine{00124\ \ \ \ \ \ \ int64\_t\ remainder\ =\ value\%1000000;}
\DoxyCodeLine{00125\ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (remainder)\ convert(remainder);}
\DoxyCodeLine{00126\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (value\ >=\ 1000)\ \{}
\DoxyCodeLine{00127\ \ \ \ \ \ \ convert(value\ /\ 1000);}
\DoxyCodeLine{00128\ \ \ \ \ \ \ add(third[THOUSAND]);}
\DoxyCodeLine{00129\ \ \ \ \ \ \ int64\_t\ remainder\ =\ value\%1000;}
\DoxyCodeLine{00130\ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (remainder)\ convert(remainder);}
\DoxyCodeLine{00131\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (value\ >=\ 100)\ \{}
\DoxyCodeLine{00132\ \ \ \ \ \ \ convert(value\ /\ 100);}
\DoxyCodeLine{00133\ \ \ \ \ \ \ add(third[HUNDRED]);}
\DoxyCodeLine{00134\ \ \ \ \ \ \ int64\_t\ remainder\ =\ value\%100;}
\DoxyCodeLine{00135\ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (remainder)\ convert(remainder);}
\DoxyCodeLine{00136\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \textcolor{keywordflow}{if}\ (value\ >=\ 20)\ \{}
\DoxyCodeLine{00137\ \ \ \ \ \ \ add(second[value\ /\ 10]);}
\DoxyCodeLine{00138\ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (value\ \%\ 10)\ \{}
\DoxyCodeLine{00139\ \ \ \ \ \ \ \ \ convert(value\ \%\ 10);}
\DoxyCodeLine{00140\ \ \ \ \ \ \ \}}
\DoxyCodeLine{00141\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00142\ \ \ \ \ \ \ add(first[value]);}
\DoxyCodeLine{00143\ \ \ \ \ \}}
\DoxyCodeLine{00144\ \ \ \}}
\DoxyCodeLine{00145\ \};}
\DoxyCodeLine{00146\ }
\DoxyCodeLine{00147\ \}\ \ \textcolor{comment}{//\ namespace\ simple\_tts}}

\end{DoxyCode}
