0
votes

I am making a ASR server uisng open source. client side send the voice data through websocket in webm file format. in server side, first receive the 8bit msg. it is done by libwebsocket.

then I want to get a raw pcm data using opus codec. I heard that webm's audio codec is opus.

How can I do it? please tell me the the way conceptually and in detail.

this is the code. (from internet)

// libopus audio decoder init
{
    int err = 0;
    my_opus_decoder = opus_decoder_create(16000, 1, &err);
    if (err<0)
    {
        fprintf(stderr, "failed to set bitrate: %s\n", opus_strerror(err));
        return EXIT_FAILURE;
    }       
}

.................................. this is the call back funtion of libwebsocket.

    //* If receive a data from client*/
    case LWS_CALLBACK_RECEIVE:
        printf(KCYN_L"[Main Service] Server recvived: size %d %s\n"RESET, strlen((char *)in), (char *)in);
        frame_size = opus_decode(my_opus_decoder, (const unsigned char *)in, nbBytes, out , MAX_FRAME_SIZE, 0);

here char *in is the stream, I sent it to opus decoder. but invalid packet error happened in opus decoder (return value is -4)

nbbytes : length of input, 4096.

out : decoded output, array, int16 out[2*960].

MAX_FRAME_SIZE : I confused what this is.

(I set this to 960*2, for 16khz sampling rate).

frame_size : return, Number of decoded samples or error code.

1

1 Answers

1
votes

You can use FFMPEG library (https://ffmpeg.org/) to convert webm to raw pcm.

Webm is a file format or a container. it can have Audio or/and Video encoded data in it. ( OPUS , VP8/9 etc)

Media pipeline : Webm file format -> Opus decoder -> raw PCM data

I found this git repo useful for ffmpeg tutorial:

https://github.com/leandromoreira/ffmpeg-libav-tutorial

other links :

Decoding opus using libavcodec from FFmpeg

For more details please google ffmpeg libavcodec webm