Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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 docs.gstreamer.com/pages/viewpage.action?pageId=327735 - C rather than C++, and video rather than audio, but you should get the idea. –  chronitis Dec 2 '13 at 15:03
add comment

2 Answers 2

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... –  rusty 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
add comment

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
add comment

Your Answer

 
discard

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.