A Mutable Log

A blog by Devendra Tewari


Project maintained by tewarid Hosted on GitHub Pages — Theme by mattgraham

Read and write raw PCM using GStreamer

Embedded developers have a frequent need to encode or decode PCM audio. In this post I show some GStreamer pipelines that can help with that task.

Convert WAV to PCM

gst-launch-1.0 filesrc location=file.wav ! wavparse ! audioresample ! audioconvert ! audio/x-raw,format=S16BE,channels=1,rate=8000 ! filesink location=file.pcm

For additional raw formats, see Raw Audio Media Types.

For bulk conversion, try

find *.wav -exec gst-launch-1.0 filesrc location={} ! wavparse ! audioresample ! audioconvert ! audio/x-raw,format=S16BE,channels=1,rate=8000 ! filesink location={}.pcm \;

This should also work fine from Git Bash shell on Windows.

Convert PCM to WAV

gst-launch-1.0 filesrc location=file.pcm ! audio/x-raw,format=S16BE,channels=1,rate=8000 ! audioconvert ! audio/x-raw,format=S16LE,channels=1,rate=8000 ! wavenc ! filesink location=file.wav

Play PCM

gst-launch-1.0 filesrc location=file.pcm ! audio/x-raw,format=S16BE,channels=1,rate=8000 !
audioconvert ! audioresample ! autoaudiosink

Use xxd to create C array of PCM data

xxd -i file.pcm > voice.c