Skip to content
This repository was archived by the owner on Aug 22, 2023. It is now read-only.

Commit fa7fd50

Browse files
committed
Merge branch 'master' of github.com:horihiro/esp8266-google-home-notifier
2 parents e1ac85b + fb24939 commit fa7fd50

File tree

2 files changed

+34
-8
lines changed

2 files changed

+34
-8
lines changed

src/esp8266-google-home-notifier.cpp

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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);

src/esp8266-google-home-notifier.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,19 @@ typedef class GoogleHomeNotifier {
5252
static bool encode_string(pb_ostream_t *stream, const pb_field_t *field, void * const *arg);
5353
static bool decode_string(pb_istream_t *stream, const pb_field_t *field, void **arg);
5454
boolean connect();
55-
boolean play(const char* mp3url);
55+
boolean _play(const char* mp3url);
5656
void disconnect();
5757
void setLastError(const char* lastError);
5858
boolean sendMessage(const char* sourceId, const char* destinationId, const char* ns, const char* data);
59+
boolean cast(const char * phrase, const char * mp3Url);
5960

6061
public:
6162
boolean device(const char * name); // locale = 'en', timeout = 10000
6263
boolean device(const char * name, const char * locale); // timeout = 10000
6364
boolean device(const char * name, const char * locale, int timeout);
65+
boolean ip(IPAddress ip, const char *locale);
6466
boolean notify(const char * phrase);
67+
boolean play(const char * mp3Url);
6568
const IPAddress getIPAddress();
6669
const uint16_t getPort();
6770
const char * getLastError();

0 commit comments

Comments
 (0)