Search code examples
windowsaudiogstreamerwavgstreamer-1.0

How to play .wav audio file with gstreamer on Windows?


The wavparse documentation provides this example to play a .wav audio file through the speakers on Linux with Alsa audio.

gst-launch-1.0 filesrc location=sine.wav ! wavparse ! audioconvert ! alsasink

I have tried to adapt this for use on Windows with the wasapisink or the autoaudiosink:

gst-launch-1.0.exe -v filesrc location=1.wav ! wavparse ! audioconvert ! autoaudiosink
gst-launch-1.0.exe -v filesrc location=1.wav ! wavparse ! audioconvert ! wasapisink

Both attempts result in an error:

ERROR: from element /GstPipeline:pipeline0/GstWavParse:wavparse0: Internal data stream error.

The full logs look like this:

Setting pipeline to PAUSED ...
Pipeline is PREROLLING ...
/GstPipeline:pipeline0/GstWavParse:wavparse0.GstPad:src: caps = audio/x-raw, format=(string)S16LE, layout=(string)interleaved, channels=(int)2, channel-mask=(bitmask)0x0000000000000003, rate=(int)44100
ERROR: from element /GstPipeline:pipeline0/GstWavParse:wavparse0: Internal data stream error.
Additional debug info:
../gst/wavparse/gstwavparse.c(2308): gst_wavparse_loop (): /GstPipeline:pipeline0/GstWavParse:wavparse0:
streaming stopped, reason not-negotiated (-4)
ERROR: pipeline doesn't want to preroll.
Setting pipeline to NULL ...
ERROR: from element /GstPipeline:pipeline0/GstAutoAudioSink:autoaudiosink0/GstWasapiSink:autoaudiosink0-actual-sink-wasapi: The stream is in the wrong format.
Additional debug info:
../gst-libs/gst/audio/gstaudiobasesink.c(1117): gst_audio_base_sink_wait_event (): /GstPipeline:pipeline0/GstAutoAudioSink:autoaudiosink0/GstWasapiSink:autoaudiosink0-actual-sink-wasapi:
Sink not negotiated before eos event.
ERROR: pipeline doesn't want to preroll.
Freeing pipeline ...

I have tried with multiple .wav files from various sources. Always the same result.

I have confirmed that autoaudiosink works on my PC because both of these commands generated an audible tone:

gst-launch-1.0.exe -v audiotestsrc samplesperbuffer=160 ! audioconvert ! autoaudiosink
gst-launch-1.0.exe -v audiotestsrc samplesperbuffer=160 ! autoaudiosink

I have also confirmed that playbin can play the file through my speakers, but this doesn't work for me because ultimately I will need to split up the pipeline a bit more.

gst-launch-1.0.exe -v playbin uri=file:///C:/1.wav

I am using gstreamer 1.18.0 with Windows 10. How do I play the contents of a .wav file through my speakers using a filesrc and autoaudiosink?


Solution

  • Maybe try audioresample before or after audioconvert too. Not entirely sure about current windows audio subsystems - but nowadays hardware tend to require a sample rate of 48000 hz. If the audio subsystem does not take care of it you need to take of it yourself.