Skip to content

Instantly share code, notes, and snippets.

@me-no-dev
Last active February 26, 2024 15:39
Show Gist options
  • Save me-no-dev/e8b5131f840822cdd14b to your computer and use it in GitHub Desktop.
Save me-no-dev/e8b5131f840822cdd14b to your computer and use it in GitHub Desktop.
/*
ffmpeg -i "$file" -f s32be -acodec pcm_s32be -ar 44100 -af "volume=0.5" tcp://espip:5522
*/
#include "i2s.h"
#include <ESP8266WiFi.h>
const char* ssid = "***********";
const char* password = "**********";
WiFiServer pcmServer(5522);
static WiFiClient pcmClient;
void setup() {
Serial.begin(115200);
Serial.print("\n");
Serial.setDebugOutput(true);
if (String(WiFi.SSID()) != String(ssid)) WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) delay(100);
pcmServer.begin();
pcmServer.setNoDelay(true);
i2s_begin();
i2s_set_rate(44100);
Serial.printf("Connected to: %s\n", ssid);
Serial.print("IP address: "); Serial.println(WiFi.localIP());
}
void loop() {
if (pcmServer.hasClient()){
if (!pcmClient || !pcmClient.connected()){
if(pcmClient) pcmClient.stop();
pcmClient = pcmServer.available();
} else {
pcmServer.available().stop();
}
}
if (pcmClient && pcmClient.connected()){
while(pcmClient.available() >= 8){
uint32_t data = 0;
//Right Channel
data |= (uint32_t)(pcmClient.read()) << 24;
data |= (uint32_t)(pcmClient.read()) << 16;
pcmClient.read();pcmClient.read();
//Left Channel
data |= (uint32_t)(pcmClient.read()) << 8;
data |= pcmClient.read();
pcmClient.read();pcmClient.read();
i2s_write_sample(data);
}
}
}
@miloit
Copy link

miloit commented Aug 6, 2021

Hello also possible the other way around send audio from Esp32 to PC??

@romakrau
Copy link

romakrau commented Jan 6, 2023

Hi, I try this code but unfortunatky it did'nt work. Can you give me a hi t. Thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment