@@ -57,15 +57,38 @@ boolean GoogleHomeNotifier::device(const char * name, const char * locale, int t
5757 return true ;
5858}
5959
60- boolean GoogleHomeNotifier::notify (const char * phrase)
60+ boolean GoogleHomeNotifier::ip (IPAddress ip, const char *locale)
61+ {
62+ this ->m_ipaddress = ip;
63+ this ->m_port = 8009 ;
64+ sprintf (this ->m_locale , " %s" , locale);
65+ return true ;
66+ }
67+
68+ boolean GoogleHomeNotifier::notify (const char * phrase) {
69+ return this ->cast (phrase, NULL );
70+ }
71+
72+ boolean GoogleHomeNotifier::play (const char * mp3Url) {
73+ return this ->cast (NULL , mp3Url);
74+ }
75+
76+ boolean GoogleHomeNotifier::cast (const char * phrase, const char * mp3Url)
6177{
6278 char error[128 ];
6379 String speechUrl;
64- speechUrl = tts.getSpeechUrl (phrase, m_locale);
65- delay (1 );
80+ if (phrase != NULL ) {
81+ speechUrl = tts.getSpeechUrl (phrase, m_locale);
82+ delay (1 );
6683
67- if (speechUrl.indexOf (" https://" ) != 0 ) {
68- this ->setLastError (" Failed to get TTS url." );
84+ if (speechUrl.indexOf (" https://" ) != 0 ) {
85+ this ->setLastError (" Failed to get TTS url." );
86+ return false ;
87+ }
88+ } else if (mp3Url != NULL ) {
89+ speechUrl = mp3Url;
90+ } else {
91+ this ->setLastError (" Both TTS phrase and mp3 url are NULL." );
6992 return false ;
7093 }
7194
@@ -87,7 +110,7 @@ boolean GoogleHomeNotifier::notify(const char * phrase)
87110 }
88111
89112 delay (1 );
90- if ( this ->play (speechUrl.c_str ()) != true ) {
113+ if ( this ->_play (speechUrl.c_str ()) != true ) {
91114 sprintf (error, " Failed to play mp3 file. (%s)" , this ->getLastError ());
92115 this ->setLastError (error);
93116 disconnect ();
@@ -244,7 +267,7 @@ boolean GoogleHomeNotifier::connect()
244267 return true ;
245268}
246269
247- boolean GoogleHomeNotifier::play (const char * mp3url)
270+ boolean GoogleHomeNotifier::_play (const char * mp3url)
248271{
249272 // send 'CONNECT' again
250273 sprintf (data, CASTV2_DATA_CONNECT);
0 commit comments