how to play an audio file through c++ ?


OS:-Windows 7
Audacity version:-2.0.3

I want to play an audio file(.mp3) in audacity,
through c++ command.

Actually I want to write a c++ code which will open audacity and play the audio file.
So,how to write a command to open that file and play?

Thank you,


You could build Audacity from the source code and enable mod-script-pipe (, but it would probably be easier to use a command line player such as SoX ( rather than Audacity.

Thank you steve,

In audacity link, it’s about perl scripting,
but is it possible to implement through c++?

I mean, is it possible to play an audio file in audacity,
by sending c++ command and it will open audacity and play the audio file,
which we want?

Thank you

I’m not a C++ programmer. It’s been a few years since I’ve played with this but I’ve had mod-script-pipe working with Python and with BASH. I’d imagine that C++ also supports pipes.

ok…that’s fine.
Thank you steve.


In audacity, is there any api for play command?

Thank you,

It’s rather complex because Audacity is not a “file player”.
Audacity projects are made up of “blocks” of data that are managed by an XML structure. For cross-platform support Audacity uses PortAudio to handle audio I/O
“Play” commands are handled through src/toolbars/ControlToolBar.cpp (see ControlToolBar::OnPlay)