Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am coding this c++ program .I want to play audio clip, format dosen't matter , its just I wrote hello word the most basic program of any language but the thing is instead of showing hello world on terminal screen i want a pre recorded hello audio clip to be played but don't now hot to play audio clip via c++ . I m using Kubuntu, a sample program showing solution will be preferred. thank you

share|improve this question
Although it might seem to conceptually follow from hello world, playing audio is really a lot more complicated - you'll need to deal with external libraries to decode the input file and send it to the hardware, and there are lots of possible error conditions to consider. See, eg, the GStreamer multimedia hello world example - C rather than C++, and video rather than audio, but you should get the idea. – chronitis Dec 2 '13 at 15:03

You can use canberra-gtk-play -f path_to_audio_file to play .ogg, .wav files e.g.:

canberra-gtk-play -f audio.ogg

would play audio.ogg in the local directory.

The system() function can be used to call system shell commands from within a C/C++ program. e.g.:

int main()
  system("canberra-gtk-play -f audio.ogg");
  return 0;
share|improve this answer
I suspect canberra-gtk-play isn't installed by default in Kubuntu, and in any case using system() might be cheating a little... – chronitis Dec 2 '13 at 15:08
Yes it a little cheat... I agree... – precise Dec 2 '13 at 15:29
In fairness I should say that it does solve the problem as written though. – chronitis Dec 2 '13 at 15:54

Hope I'm helpful, because I'm not quite sure myself and haven't tried it yet; try ALSA, and read this seemingly helpful article on Introduction to Sound Programming with ALSA, I'm pretty sure you would get what you want.

share|improve this answer

I've made a MP3 player all in C for my Raspberry Pi. I followed instructions from here:

This will only play mp3 files atm, but I plan on adding OGG playback as well.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.