[Libwebsockets] Receive and save audio stream as a file

Lucian Georgescu lucgeo92 at gmail.com
Thu May 12 01:01:06 CEST 2016


Hello,

I'm new to libwebsockets, I installed version 2.0 and I have a problem with my first application. 
I want to create a simple server to be able to receive audio chunks and then to write them on a file on disk. Here is my code: https://drive.google.com/file/d/0B7umVbxKsF0GUEZGX1lhUlJpRGc/view?usp=sharing

I got the message "client connected" and also the wav file is created (the file size is bigger than zero), but the content isn't ok, I cannot play it. 

The client is based on Web Audio API. It captures live audio from microphone and it sends audio chunks already encoded as wav, 16Khz, mono. I used code from this project: http://kaljurand.github.io/dictate.js/. The client is working well, I used it in the past for exactly the same task with a Java server.

I observed an interesting thing about the resulted wav file. Using the following command: "hexdump -C file.wav | head", I got the hex content. It contains only the information regarding the encoding type, the rest of the data being zero. Here are some rows in hex:

00000000  52 49 46 46 f4 22 00 00  57 41 56 45 66 6d 74 20  |RIFF."..WAVEfmt |
00000010  10 00 00 00 01 00 02 00  44 ac 00 00 10 b1 02 00  |........D.......|
00000020  04 00 10 00 64 61 74 61  d4 22 00 00 00 00 00 00  |....data."......|
00000030  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00  |................|

 I would really appreciate if someone could indicate me how to save these audio chunks in a valid file.

 Thanks,

 Lucian




More information about the Libwebsockets mailing list