Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
E
ESP32-audioI2S
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
xpstem
ESP32-audioI2S
Commits
8d1a79b0
Unverified
Commit
8d1a79b0
authored
Jan 14, 2023
by
Wolle
Committed by
GitHub
Jan 14, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #465 from schreibfaul1/master
update from master
parents
fe1f37c9
0ef0ca35
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
3 deletions
+96
-3
examples/time_announcement/main.cpp
examples/time_announcement/main.cpp
+90
-0
src/Audio.cpp
src/Audio.cpp
+5
-2
src/Audio.h
src/Audio.h
+1
-1
No files found.
examples/time_announcement/main.cpp
0 → 100644
View file @
8d1a79b0
// This arduino sketch for ESP32 announces the time every hour.
// A connection to the Internet is required
// 1) to synchronize with the internal RTC on startup
// 2) so that GoogleTTS can be reached
#include <Arduino.h>
#include "WiFiMulti.h"
#include "Audio.h"
#include "time.h"
#include "esp_sntp.h"
//------------------------USER SETTINGS / GPIOs-------------------------------------------------------------------------
String
ssid
=
"xxxx"
;
String
password
=
"xxxx"
;
uint8_t
I2S_BCLK
=
27
;
uint8_t
I2S_LRC
=
26
;
uint8_t
I2S_DOUT
=
25
;
//------------------------OBJECTS /GLOBAL VARS--------------------------------------------------------------------------
Audio
audio
(
false
,
3
,
0
);
WiFiMulti
wifiMulti
;
uint32_t
sec1
=
millis
();
String
time_s
=
""
;
char
chbuf
[
200
];
int
timeIdx
=
0
;
//------------------------TIME / SNTP STUFF-----------------------------------------------------------------------------
#define TZName "CET-1CEST,M3.5.0,M10.5.0/3" // https://remotemonitoringsystems.ca/time-zone-abbreviations.php
char
strftime_buf
[
64
];
struct
tm
timeinfo
;
time_t
now
;
boolean
obtain_time
(){
time_t
now
=
0
;
int
retry
=
0
;
Serial
.
println
(
"Initializing SNTP"
);
sntp_setoperatingmode
(
SNTP_OPMODE_POLL
);
sntp_setservername
(
0
,
"pool.ntp.org"
);
sntp_init
();
const
int
retry_count
=
10
;
while
(
timeinfo
.
tm_year
<
(
2016
-
1900
)
&&
++
retry
<
retry_count
)
{
Serial
.
printf
(
"Waiting for system time to be set... (%d/%d)
\n
"
,
retry
,
retry_count
);
vTaskDelay
(
uint16_t
(
2000
/
portTICK_PERIOD_MS
));
time
(
&
now
);
localtime_r
(
&
now
,
&
timeinfo
);
}
setenv
(
"TZ"
,
TZName
,
1
);
tzset
();
localtime_r
(
&
now
,
&
timeinfo
);
strftime
(
strftime_buf
,
sizeof
(
strftime_buf
),
"%c"
,
&
timeinfo
);
if
(
retry
<
retry_count
)
return
true
;
else
return
false
;
}
const
char
*
gettime_s
(){
// hh:mm:ss
time
(
&
now
);
localtime_r
(
&
now
,
&
timeinfo
);
sprintf
(
strftime_buf
,
"%02d:%02d:%02d"
,
timeinfo
.
tm_hour
,
timeinfo
.
tm_min
,
timeinfo
.
tm_sec
);
return
strftime_buf
;
}
//-----------------------SETUP------------------------------------------------------------------------------------------
void
setup
()
{
Serial
.
begin
(
115200
);
wifiMulti
.
addAP
(
ssid
.
c_str
(),
password
.
c_str
());
wifiMulti
.
run
();
obtain_time
();
audio
.
setPinout
(
I2S_BCLK
,
I2S_LRC
,
I2S_DOUT
);
audio
.
setVolume
(
15
);
}
//-----------------------LOOP-------------------------------------------------------------------------------------------
void
loop
()
{
audio
.
loop
();
if
(
sec1
<
millis
()){
// every second
sec1
=
millis
()
+
1000
;
time_s
=
gettime_s
();
Serial
.
println
(
time_s
);
if
(
time_s
.
endsWith
(
"00:00"
)){
// time announcement every full hour
char
am_pm
[
5
]
=
"am."
;
int
h
=
time_s
.
substring
(
0
,
2
).
toInt
();
if
(
h
>
12
){
h
-=
12
;
strcpy
(
am_pm
,
"pm."
);}
sprintf
(
chbuf
,
"It is now %i%s and %i minutes"
,
h
,
am_pm
,
time_s
.
substring
(
3
,
5
).
toInt
());
Serial
.
println
(
chbuf
);
audio
.
connecttospeech
(
chbuf
,
"en"
);
}
}
}
//------------------EVENTS----------------------------------------------------------------------------------------------
void
audio_info
(
const
char
*
info
){
Serial
.
printf
(
"info: %s
\n
"
,
info
);
}
\ No newline at end of file
src/Audio.cpp
View file @
8d1a79b0
...
...
@@ -3,8 +3,8 @@
*
* Created on: Oct 26.2018
*
* Version 2.0.8
c
* Updated on: Jan 1
1
.2023
* Version 2.0.8
d
* Updated on: Jan 1
3
.2023
* Author: Wolle (schreibfaul1)
*
*/
...
...
@@ -2560,6 +2560,7 @@ const char* Audio::parsePlaylist_M3U8(){
strcpy
(
m_lastHost
,
tmp
);
if
(
tmp
){
free
(
tmp
);
tmp
=
NULL
;}
if
(
m_f_Log
)
log_i
(
"redirect %s"
,
m_playlistContent
[
i
]);
_client
->
stop
();
return
m_playlistContent
[
i
];
// it's a redirection, a new m3u8 playlist
}
...
...
@@ -4637,12 +4638,14 @@ bool Audio::ts_parsePacket(uint8_t* packet, uint8_t* packetStart, uint8_t* packe
if
(
m_f_Log
)
log_i
(
"Adaptation Field Length: %d"
,
AFL
);
}
int
PLS
=
PUSI
?
5
:
4
;
// PayLoadStart, Payload Unit Start Indicator
if
(
AFL
>
0
)
PLS
+=
AFL
+
1
;
// skip adaption field
if
(
PID
==
0
)
{
// Program Association Table (PAT) - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
if
(
m_f_Log
)
log_i
(
"PAT"
);
pidsOfPMT
.
number
=
0
;
pidOfAAC
=
0
;
int
startOfProgramNums
=
8
;
int
lengthOfPATValue
=
4
;
int
sectionLength
=
((
packet
[
PLS
+
1
]
&
0x0F
)
<<
8
)
|
(
packet
[
PLS
+
2
]
&
0xFF
);
...
...
src/Audio.h
View file @
8d1a79b0
...
...
@@ -4,7 +4,7 @@
* Created on: Oct 28,2018
*
* Version 2.0.8c
* Updated on: Jan 1
1
,2023
* Updated on: Jan 1
3
,2023
* Author: Wolle (schreibfaul1)
*/
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment