sending wav to html

Gaston1980
Posts: 41
Joined: Sun Oct 06, 2024 10:26 am

sending wav to html

Postby Gaston1980 » Sun Jul 06, 2025 7:55 pm

Hi to all, I'm using esp32E to send wav sound to html page . I generated a tone and tested creating a C file then compiled an using VLC to listen the sound. So this tone works.
Now I'm trying to use the esp32E to send this tone to html using this code:

Code: Select all

    ESP_ERROR_CHECK(httpd_resp_set_status(req, HTTPD_200));
    ESP_ERROR_CHECK(httpd_resp_set_type(req,"audio/wav"));
    ESP_ERROR_CHECK(httpd_resp_send(req,(const char *)buff_wav,sizeof(buff_wav)));
    return ESP_OK;
inside buffer_wav i copied the header of wav file:

Code: Select all

struct wav_header
{
  char riff[4];            
  int32_t flength;        // file length in bytes                    
  char wave[4];           // "WAVE"                                  
  char fmt[4];            // "fmt "                                  
  int32_t chunk_size;     // size of FMT chunk in bytes (usually 16) 
  int16_t format_tag;     // 1=PCM, 257=Mu-Law, 258=A-Law, 259=ADPCM 
  int16_t num_chans;      // 1=mono, 2=stereo                        
  int32_t srate;          // Sampling rate in samples per second     
  int32_t bytes_per_sec;  // bytes per second = srate*bytes_per_samp 
  int16_t bytes_per_samp; // 2=16-bit mono, 4=16-bit stereo          
  int16_t bits_per_samp;  // Number of bits per sample               
  char data[4];           // "data"                                  
  int32_t dlength;        // data length in bytes (filelength - 44)  
};
the buffer_wav is dedfine as:

Code: Select all

static char buff_test[NUM_SAMPLES];
and the tone as:

Code: Select all

    for(unsigned i=0;i<BUFFER_LEN;i++)
    {
        buff_test[i]=(short int)(cos(step*i)*SCALE);
    }
debugging the code I got the buffer_wav with the correct header (see images attached). But in the html page I'm unable to listen the sound
but why? is the httpd Content-type correct? this is how i see the wav in the html (image below)
Attachments
html_wav.png
html_wav.png (3.25 KiB) Viewed 52 times
buffer_wav1.png
buffer_wav1.png (18.15 KiB) Viewed 52 times
buffer_wav2.png
buffer_wav2.png (17.62 KiB) Viewed 52 times

Who is online

Users browsing this forum: Google [Bot] and 6 guests