I'm trying to learn how to stream audio from the A0 pin of an ESP8266 NodeMCU board via UDP socket connection over to another windows computer that uses pyaudio to play it. At the moment, all I get on the windows computer are a series of "popping" sounds each spaced about half a second apart.
I'm new to working with these types of break out boards, so I found an online project that I'm using as a starting point:
Streaming audio from ESP8266 to pyaudio working in Arduino IDE
I figure I start troubleshooting my popping sound issue by inspecting the UDP packets my ESP8266 code. Below is the source code I'm working from:
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
const char* ssid = "change this";
const char* password = "change this";
int contconexion = 0;
WiFiUDP Udp;
void setup()
{
Serial.begin(115200);
Serial.println();
pinMode(5, OUTPUT); //D1 Led de estado
digitalWrite(15, LOW);
WiFi.mode(WIFI_STA); //para que no inicie el SoftAP en el modo normal
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED and contconexion <50) { //Cuenta hasta 50 si no se puede conectar lo cancela
++contconexion;
delay(250);
Serial.print(".");
digitalWrite(5, HIGH);
delay(250);
digitalWrite(5, LOW);
}
if (contconexion <50) {
//para usar con ip fija
IPAddress Ip(192,168,1,180);
IPAddress Gateway(192,168,0,1);
IPAddress Subnet(255,255,255,0);
WiFi.config(Ip, Gateway, Subnet);
Serial.println("");
Serial.println("WiFi conectado");
Serial.println(WiFi.localIP());
//digitalWrite(5, HIGH);
}
else {
Serial.println("");
Serial.println("Error de conexion");
//digitalWrite(15, LOW);
}
}
void loop()
{
Udp.beginPacket("192.168.0.26", 1234);
for(int i=0; i<1024;i++){
int old=micros();
float analog = analogRead(A0);
if (analog > 255) {
analog = 255;
}
else if (analog < 0){
analog = 0;
}
Udp.write(int(analog));
Serial.print(int(analog));
Serial.print(",");
while(micros()-old<87); // 90uSec = 1Sec/11111Hz - 3uSec para los otros procesos
}
Serial.print(";;;;;");
Udp.endPacket();
delay(5);
}
Notice near the bottom of the file, I print out each analog value separated by a comma, and each data packet separated by five semicolons.
Can someone suggest a way for me to re-construct these series of integers into a sound file that I can inspect via listening with my own ears? Then I can tell if the sound data being sent is complete? Or let me know if there's a better way to test if all the data packets are being sent correctly.
UPDATE
I tried to create a wav file by doing this:
- Take the list of all integers from
Serial.print(int(analog))
and paste it into a file. I make sure all integers are space delimited (ie. no more commas or semicolons) - I copied the file over to a linux machine that had ffmpeg installed
- I ran the command
ffmpeg -f u8 -ar 11111 -ac 1 -i myfileofintegers -y test.wav
When I listen to the test.wav file, I just hear a series of rapid popping noises. Not sure if I created the wav file properly?
Serial.print(int(analog))
to a wav file. 3) A0 receives the output voltage of a pre-amplified electret microphone. The voltage amplitude seems to range between 0mv and 300mv.