File tree Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Expand file tree Collapse file tree 1 file changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < Wire.h>
2
+ #include < Adafruit_MS_PWM_Synth.h>
3
+ #include < ESP8266WiFi.h>
4
+ #include < ESP8266HTTPClient.h>
5
+
6
+ const char * ssid = " your_wifi_ssid" ;
7
+ const char * password = " your_wifi_password" ;
8
+ const char * serverIP = " http://your_server_ip:8000" ;
9
+
10
+ Adafruit_MS_PWM_Synth synth;
11
+
12
+ void setup () {
13
+ Serial.begin (115200 );
14
+ WiFi.begin (ssid, password);
15
+
16
+ while (WiFi.status () != WL_CONNECTED) {
17
+ delay (500 );
18
+ Serial.print (" ." );
19
+ }
20
+
21
+ Serial.println (" Connected to WiFi" );
22
+
23
+ synth.begin ();
24
+ }
25
+
26
+ void loop () {
27
+ HTTPClient http;
28
+
29
+ if (WiFi.status () == WL_CONNECTED) {
30
+ http.begin (serverIP + String (" /result" ));
31
+ int httpCode = http.GET ();
32
+
33
+ if (httpCode == HTTP_CODE_OK) {
34
+ String payload = http.getString ();
35
+ if (payload.startsWith (" {\" result\" :\" " )) {
36
+ String message = payload.substring (11 , payload.length () - 2 ); // Parsing result
37
+ playAudioMessage (message);
38
+ }
39
+ }
40
+ http.end ();
41
+ }
42
+ delay (10000 ); // Poll every 10 seconds
43
+ }
44
+
45
+ void playAudioMessage (String message) {
46
+ String audioFileName = " /static/audio/" + message + " .wav" ; // Construct file path
47
+
48
+ // Play audio file (Implement your audio file playing logic here)
49
+ Serial.println (" Playing: " + audioFileName);
50
+ }
You can’t perform that action at this time.
0 commit comments