\hypertarget{_text_to_speech_8h_source}{}\doxysection{Text\+To\+Speech.\+h}
\label{_text_to_speech_8h_source}\index{src/TextToSpeech.h@{src/TextToSpeech.h}}

\begin{DoxyCode}{0}
\DoxyCodeLine{00001\ \textcolor{preprocessor}{\#pragma\ once}}
\DoxyCodeLine{00002\ \textcolor{preprocessor}{\#ifndef\ NO\_SPEECH}}
\DoxyCodeLine{00003\ \textcolor{preprocessor}{\#include\ "{}AudioCodecs/CodecMP3Helix.h"{}}}
\DoxyCodeLine{00004\ \textcolor{preprocessor}{\#include\ "{}AudioTools/AudioOutput.h"{}}}
\DoxyCodeLine{00005\ \textcolor{preprocessor}{\#include\ "{}AudioTools/AudioStreams.h"{}}}
\DoxyCodeLine{00006\ \textcolor{preprocessor}{\#include\ "{}AudioTools/AudioTypes.h"{}}}
\DoxyCodeLine{00007\ \textcolor{preprocessor}{\#include\ "{}NumberToText.h"{}}}
\DoxyCodeLine{00008\ \textcolor{preprocessor}{\#include\ "{}AudioDictionary.h"{}}}
\DoxyCodeLine{00009\ }
\DoxyCodeLine{00010\ \textcolor{keyword}{namespace\ }simple\_tts\ \{}
\DoxyCodeLine{00011\ }
\DoxyCodeLine{00018\ \textcolor{keyword}{class\ }\mbox{\hyperlink{classsimple__tts_1_1_text_to_speech}{TextToSpeech}}\ \{}
\DoxyCodeLine{00019\ \ \textcolor{keyword}{public}:}
\DoxyCodeLine{00021\ \ \ \mbox{\hyperlink{classsimple__tts_1_1_text_to_speech_a7ab9d174704592d9fdc5e5b7c97d4cf3}{TextToSpeech}}(\mbox{\hyperlink{classsimple__tts_1_1_simple_t_t_s_base}{SimpleTTSBase}}\ \&tts,\ AudioStream\ \&sink,\ AudioDecoder\ \&decoder,}
\DoxyCodeLine{00022\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classsimple__tts_1_1_audio_dictionary_base}{AudioDictionaryBase}}\ \&dict)\ \{}
\DoxyCodeLine{00023\ \ \ \ \ tts.registerCallback(\mbox{\hyperlink{classsimple__tts_1_1_text_to_speech_aef5be846d3540b0591952d4b50467bca}{callback}},\ \textcolor{keyword}{this});}
\DoxyCodeLine{00024\ \ \ \ \ p\_tts\ =\ \&tts;}
\DoxyCodeLine{00025\ \ \ \ \ p\_dictionary\ =\ \&dict;}
\DoxyCodeLine{00026\ \ \ \ \ p\_decoder\ =\ \&decoder;}
\DoxyCodeLine{00027\ \ \ \ \ p\_sink\ =\ \&sink;}
\DoxyCodeLine{00028\ \ \ \ \ decodedStream\ =\ \textcolor{keyword}{new}\ audio\_tools::EncodedAudioStream(\&sink,\ \&decoder);}
\DoxyCodeLine{00029\ \ \ \ \ begin();}
\DoxyCodeLine{00030\ \ \ \}}
\DoxyCodeLine{00031\ }
\DoxyCodeLine{00032\ \ \ \mbox{\hyperlink{classsimple__tts_1_1_text_to_speech}{TextToSpeech}}(\mbox{\hyperlink{classsimple__tts_1_1_simple_t_t_s_base}{SimpleTTSBase}}\ \&tts,\ AudioOutput\ \&sink,\ AudioDecoder\ \&decoder,}
\DoxyCodeLine{00033\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classsimple__tts_1_1_audio_dictionary_base}{AudioDictionaryBase}}\ \&dict)\ \{}
\DoxyCodeLine{00034\ \ \ \ \ tts.registerCallback(\mbox{\hyperlink{classsimple__tts_1_1_text_to_speech_aef5be846d3540b0591952d4b50467bca}{callback}},\ \textcolor{keyword}{this});}
\DoxyCodeLine{00035\ \ \ \ \ p\_tts\ =\ \&tts;}
\DoxyCodeLine{00036\ \ \ \ \ p\_dictionary\ =\ \&dict;}
\DoxyCodeLine{00037\ \ \ \ \ p\_decoder\ =\ \&decoder;}
\DoxyCodeLine{00038\ \ \ \ \ p\_sink\ =\ \&sink;}
\DoxyCodeLine{00039\ \ \ \ \ decodedStream\ =\ \textcolor{keyword}{new}\ audio\_tools::EncodedAudioStream(\&sink,\ \&decoder);}
\DoxyCodeLine{00040\ \ \ \ \ begin();}
\DoxyCodeLine{00041\ \ \ \}}
\DoxyCodeLine{00042\ }
\DoxyCodeLine{00044\ \ \ \mbox{\hyperlink{classsimple__tts_1_1_text_to_speech_a316f6162063dc215f5e37b6326b109e1}{TextToSpeech}}(AudioStream\ \&sink,\ AudioDecoder\ \&decoder,}
\DoxyCodeLine{00045\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \mbox{\hyperlink{classsimple__tts_1_1_audio_dictionary_base}{AudioDictionaryBase}}\ \&dict)\ \{}
\DoxyCodeLine{00046\ \ \ \ \ p\_dictionary\ =\ \&dict;}
\DoxyCodeLine{00047\ \ \ \ \ p\_decoder\ =\ \&decoder;}
\DoxyCodeLine{00048\ \ \ \ \ p\_sink\ =\ \&sink;}
\DoxyCodeLine{00049\ \ \ \ \ decodedStream\ =\ \textcolor{keyword}{new}\ audio\_tools::EncodedAudioStream(\&sink,\ \&decoder);}
\DoxyCodeLine{00050\ \ \ \ \ begin();}
\DoxyCodeLine{00051\ \ \ \}}
\DoxyCodeLine{00052\ }
\DoxyCodeLine{00053\ }
\DoxyCodeLine{00054\ \ \ \mbox{\hyperlink{classsimple__tts_1_1_text_to_speech}{\string~TextToSpeech}}()\ \{\ \textcolor{keyword}{delete}\ decodedStream;\ \}}
\DoxyCodeLine{00055\ }
\DoxyCodeLine{00057\ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classsimple__tts_1_1_text_to_speech_ac832e8ee5f5631cc8a75d0afd2ab824d}{say}}(\textcolor{keyword}{const}\ \textcolor{keywordtype}{char}\ *word)\ \{}
\DoxyCodeLine{00058\ \ \ \ \ LOGI(\textcolor{stringliteral}{"{}say:\ \%s"{}},word);}
\DoxyCodeLine{00059\ \ \ \ \ AudioStream\ *mp3Stream\ =\ p\_dictionary-\/>get(word);}
\DoxyCodeLine{00060\ \ \ \ \ \textcolor{keywordflow}{if}\ (mp3Stream\ !=\ \textcolor{keyword}{nullptr})\ \{}
\DoxyCodeLine{00061\ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (!active)\ begin();}
\DoxyCodeLine{00062\ \ \ \ \ \ \ mp3Stream-\/>begin();}
\DoxyCodeLine{00063\ \ \ \ \ \ \ copier.begin(*decodedStream,\ *mp3Stream);}
\DoxyCodeLine{00064\ \ \ \ \ \ \ copier.copyAll(0,\ 0);}
\DoxyCodeLine{00065\ \ \ \ \ \ \ copier.end();}
\DoxyCodeLine{00066\ \ \ \ \ \ \ mp3Stream-\/>end();}
\DoxyCodeLine{00067\ \ \ \ \ \}\ \textcolor{keywordflow}{else}\ \{}
\DoxyCodeLine{00068\ \ \ \ \ \ \ LOGE(\textcolor{stringliteral}{"{}Word\ not\ available\ in\ dictionary:\ \%s"{}},\ word);}
\DoxyCodeLine{00069\ \ \ \ \ \}}
\DoxyCodeLine{00070\ \ \ \}}
\DoxyCodeLine{00071\ }
\DoxyCodeLine{00072\ \ \ \textcolor{keywordtype}{void}\ begin()\ \{}
\DoxyCodeLine{00073\ \ \ \ \ p\_decoder-\/>begin();}
\DoxyCodeLine{00074\ \ \ \ \ active\ =\ \textcolor{keyword}{true};}
\DoxyCodeLine{00075\ \ \ \}}
\DoxyCodeLine{00076\ }
\DoxyCodeLine{00077\ \ \ \textcolor{keywordtype}{void}\ end()\ \{}
\DoxyCodeLine{00078\ \ \ \ \ p\_decoder-\/>end();}
\DoxyCodeLine{00079\ \ \ \ \ active\ =\ \textcolor{keyword}{false};}
\DoxyCodeLine{00080\ \ \ \}}
\DoxyCodeLine{00081\ }
\DoxyCodeLine{00083\ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classsimple__tts_1_1_text_to_speech_a3e32159205a745f4d3a59b40ce57c57b}{say}}(audio\_tools::Vector<const\ char\ *>\ words)\ \{}
\DoxyCodeLine{00084\ \ \ \ \ begin();}
\DoxyCodeLine{00085\ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keyword}{auto}\ word\ :\ words)\ \{\ \ \ \ \ \ }
\DoxyCodeLine{00086\ \ \ \ \ \ \ \mbox{\hyperlink{classsimple__tts_1_1_text_to_speech_ac832e8ee5f5631cc8a75d0afd2ab824d}{say}}(word);}
\DoxyCodeLine{00087\ \ \ \ \ \}}
\DoxyCodeLine{00088\ \ \ \ \ end();}
\DoxyCodeLine{00089\ \ \ \}}
\DoxyCodeLine{00090\ }
\DoxyCodeLine{00092\ \ \ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classsimple__tts_1_1_text_to_speech_aa7ebf5afbc70655c9a0116de496ae58e}{delay}}(uint32\_t\ delay\_ms)\{}
\DoxyCodeLine{00093\ \ \ \ \ \ \ uint8\_t\ buffer[1024]\ =\ \{0\};}
\DoxyCodeLine{00094\ \ \ \ \ \ \ \textcolor{keywordtype}{unsigned}\ \textcolor{keywordtype}{long}\ timeout\ =\ millis()+delay\_ms;}
\DoxyCodeLine{00095\ \ \ \ \ \ \ \textcolor{keywordflow}{while}(timeout>millis())\{}
\DoxyCodeLine{00096\ \ \ \ \ \ \ \ \ \ p\_sink-\/>write((\textcolor{keyword}{const}\ uint8\_t*)buffer,1024);}
\DoxyCodeLine{00097\ \ \ \ \ \ \ \}}
\DoxyCodeLine{00098\ \ \ \}}
\DoxyCodeLine{00099\ }
\DoxyCodeLine{00100\ \ \textcolor{keyword}{protected}:}
\DoxyCodeLine{00101\ \ \ \textcolor{keywordtype}{bool}\ active\ =\ \textcolor{keyword}{false};}
\DoxyCodeLine{00102\ \ \ \mbox{\hyperlink{classsimple__tts_1_1_number_to_text}{NumberToText}}\ ntt;}
\DoxyCodeLine{00103\ \ \ audio\_tools::AudioDecoder\ *p\_decoder\ =\ \textcolor{keyword}{nullptr};}
\DoxyCodeLine{00104\ \ \ audio\_tools::EncodedAudioStream\ *decodedStream\ =\ \textcolor{keyword}{nullptr};\ \ \textcolor{comment}{//\ Decoding\ stream}}
\DoxyCodeLine{00105\ \ \ \mbox{\hyperlink{classsimple__tts_1_1_simple_t_t_s_base}{SimpleTTSBase}}\ *p\_tts\ =\ \textcolor{keyword}{nullptr};\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ Text\ source}}
\DoxyCodeLine{00106\ \ \ \mbox{\hyperlink{classsimple__tts_1_1_audio_dictionary_base}{AudioDictionaryBase}}\ *p\_dictionary\ =\ \textcolor{keyword}{nullptr};\ \ \textcolor{comment}{//\ Dictionary\ to\ access\ audio\ data}}
\DoxyCodeLine{00107\ \ \ audio\_tools::StreamCopy\ copier;\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ copy\ in\ to\ out}}
\DoxyCodeLine{00108\ \ \ Print\ *p\_sink=\textcolor{keyword}{nullptr};}
\DoxyCodeLine{00109\ }
\DoxyCodeLine{00111\ \ \ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ \mbox{\hyperlink{classsimple__tts_1_1_text_to_speech_aef5be846d3540b0591952d4b50467bca}{callback}}(audio\_tools::Vector<const\ char\ *>\ words,\ \textcolor{keywordtype}{void}*\ ref)\ \{\ }
\DoxyCodeLine{00112\ \ \ \ \ \mbox{\hyperlink{classsimple__tts_1_1_text_to_speech}{TextToSpeech}}*\ self\ =\ (\mbox{\hyperlink{classsimple__tts_1_1_text_to_speech}{TextToSpeech}}*)ref;}
\DoxyCodeLine{00113\ \ \ \ \ self-\/>\mbox{\hyperlink{classsimple__tts_1_1_text_to_speech_ac832e8ee5f5631cc8a75d0afd2ab824d}{say}}(words);\ \}}
\DoxyCodeLine{00114\ \};}
\DoxyCodeLine{00115\ }
\DoxyCodeLine{00116\ \}\ \ \textcolor{comment}{//\ namespace\ simple\_tts}}
\DoxyCodeLine{00117\ }
\DoxyCodeLine{00118\ \textcolor{preprocessor}{\#endif}}

\end{DoxyCode}
