Skip to content

Commit 999de92

Browse files
Add files via upload
1 parent fcc703c commit 999de92

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
}

0 commit comments

Comments
 (0)